The pushl
Y86 instruction both decrements the stack pointer by 4 and writes a register value to memory. So it's not clear what the processor should do when it executes the instruction pushl %esp
, since the register being pushed is being changed by the same instruction. Two possible events can occur:
(1) push the original value of %esp
, or (2) push the decremented value of %esp
.
In light of this, how could we modify this code-equivalent of pushl REG
to account for, and accomdate, these ambiguities (being that REG can be %esp as well as any other register)?:
subl $4,%esp Decrement stack pointer
movl REG,(%esp) Store REG on stack
Similarly, the instruction popl %esp
could either set %esp
to the value read from memory or to the incremented stack pointer. How could this code be changed to accommodate for these ambiguities?:
movl (%esp),REG Read REG from stack
addl $4,%esp Increment stack pointer