I first save PUSH EAX , then PUSH EAX , that is, the values of the two registers. Perhaps there is a special instruction that allows you to take the lowest value of the stack? The top of the stack is the EAX value, the bottom of the stack is the ECX value. How to take the value from the "bottom", change it and put it back on the bottom? Thank you for the answers!
- oneThat's why he and the stack to work with him as with the stack. If you need the lowest, save everything before it and then back form the stack. - Daniel Protopopov
1 answer
The machine stack is just a memory location, you can work with it as you would with any other memory location, for example, using the mov command, you can access any address above the current vertex (the address lying in esp ).
Actions from the question can be performed as follows:
push eax push ecx mov edx, [esp+4] ; берем значение, которое было добавлено в стек предпоследним ... ; как-то меняем mov [esp+4], edx ; кладем обратно For the procedure, the value of the stack pointer that it has at the moment of entering the procedure can be conditionally considered the bottom of the stack. There is a standard method when this value is saved to the ebp register, then memory is allocated on the stack for local variables (the stack pointer is simply reduced by the size of local variables), and then in the process of running the procedure from ebp up ( [ebp+N] ) addresses of the procedure arguments, and down ( [ebp-N] ) - addresses of local variables. At the same time, the value of esp in the process of the procedure may change, and the value of ebp remains the same. The procedure code will look something like this:
; Стандартный пролог для создания стекового фрейма push ebp mov ebp, esp sub esp, M ; M - размер локальных переменных ... ; основной код процедуры ; Стандартный эпилог mov esp, ebp pop ebp ret