Question

I need some help understanding how the stack registers work in x86 Assembly. The code snippets below are from a bootloader that I am studying.

The print function takes three "arguments". Since I push all three to the stack, I expect sp to be at 0xfff9. bp takes the same address in once in the print function.

How come I have to do [bp+4] instead of [bp+2]? Since aren't the variables I pushed at locations 0xfffd , 0xfffb , and 0xfff9? Then when I return from the print function I add add sp, 6 to restore sp to same location before printing.

; stack initialization
mov ax, 0x0000
mov ss, ax
mov sp, 0xffff
mov bp, 0xffff

EDIT Forgot about the function return address.

Était-ce utile?

La solution

BP points to where the previous BP value was pushed
BP + 2 points to the return address pushed by `call PRINTMESSAGE`
BP + 4 points to the last argument pushed
and so on
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top