Wednesday, July 31, 2019

What is the function of the push / pop instructions used on registers in x86 assembly?



When reading about assembler I often come across people writing that they push a certain register of the processor and pop it again later to restore it's previous state.




  • How can you push a register? Where is it pushed on? Why is this needed?

  • Does this boil down to a single processor instruction or is it more complex?


Answer



pushing a value (not necessarily stored in a register) means writing it to the stack.



popping means restoring whatever is on top of the stack into a register. Those are basic instructions:



push 0xdeadbeef      ; push a value to the stack
pop eax ; eax is now 0xdeadbeef

; swap contents of registers
push eax
mov eax, ebx
pop ebx

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...