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
Assembly sp and bp registers
Pregunta
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.
Solución
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow