xv6: what does `popl 0(%eax)` mean? (OSTEP)

19 Views Asked by At

In Operating Systems, Three Easy Pieces Chapter 6, there is a code snippet from xv6's context switch:

...
void swtch(struct context **old, struct context *new);
#
# Save current register context in old
# and then load register context from new.
.globl swtch
swtch:
# Save old registers
movl 4(%esp), %eax # put old ptr into eax
popl 0(%eax) # save the old IP
movl %esp, 4(%eax) # and stack
movl %ebx, 8(%eax) # and other registers
...

I understand that movl 4(%esp), %eax moves the content inside the address 4(%esp) (first parameter of the method, or the old context address) to register eax.

However, the next line popl 0(%eax) seems to also pop from the stack (which points to the instruction pointer of the caller) and load it into eax. However, my understanding is contradicting because that would mean we're loading two values into eax.

Which part am I not following correctly here?

I assume that 0(%eax) is not loading into eax but perhaps loading into the address pointed by eax? That would make sense since eax pointing at the old context address.

0

There are 0 best solutions below