
este es mi primer code hecho en C++ :3
me base en una pregunta que se hizo hace poco en el foro y me dio ganas de hacer el codigo, mi humilde codigo
es una simulacion de como trabaja la pila en asm :3 mi codigo soporta desplazamientos de punteros, en asm seria
de los registros ESP, EBP, para que apunten a diferentes lugares de la pila tambien tiene el registro EBP.
tambien pido a los grandes en c++ consejos, recomendaciones, todo lo que sea para poder mejorar

Código
// .MODEL 386,486,586 xD
// .STACK 100h // Size Segment STACK
class ClsSTACK
{
public:
ClsSTACK():ClsESP(&SegSTACK[0]),ClsEBP(0) {} // Inicialize Value
void ClsPUSH(int Reg); // Instruction PUSH Operator
int ClsPOP(); // Instruction POP Operator
int SegSTACK[0x100]; // Segment STACK
int* ClsESP; // STACK POINTER
int* ClsEBP; // BASE POINTER
};
void ClsSTACK::ClsPUSH(int Reg)
{
*ClsESP = Reg;
ClsESP++;
}
int ClsSTACK::ClsPOP()
{
return *ClsESP--;
}
// .DATA
// ValS DWORD 0
// .CODE
// inicio:
// MOV EDX,@DATA
// MOV DS,EDX
int main()
{
ClsSTACK MSTACK; //Make STACK
int ValS = 0;
MSTACK.ClsPUSH(0x10);
MSTACK.ClsPUSH(0x0);
MSTACK.ClsPUSH(0x0);
MSTACK.ClsPUSH(0x10);
MSTACK.ClsPUSH(0x100);
MSTACK.ClsPUSH(0x200);
MSTACK.ClsESP--; // ADD ESP,04h
ValS = MSTACK.ClsPOP(); // POP EAX
// MOV DS:ValS,EAX ; ValS = 100h
// Test BASE POINTER
MSTACK.ClsEBP = MSTACK.ClsESP; // MOV EBP,ESP
MSTACK.ClsEBP = MSTACK.ClsEBP-4; // ADD EBP,8h
ValS = *MSTACK.ClsEBP; // MOV EAX,EBP
ValS = MSTACK.ClsPOP(); // POP EAX ; Not Change
return 0;
// end inicio
}











Autor



En línea





gracias 

