<<< Popping Values from Stack | Index | Saving Flags on the Stack >>> |
To reference operands on the stack, remember that the values pointed to by the EBP (Base Pointer) and ESP registers are relative to the SS (Stack Segment) register.
The EBP register is often used to point to the base of a frame of reference (a stack frame) within the stack.
This example shows how you can access values on the stack using indirect memory operands with 16-bit BP as the base register.
push bp ; Save current value of BP mov bp, sp ; Set stack frame push ax ; Push first; SP = BP - 2 push bx ; Push second; SP = BP - 4 push cx ; Push third; SP = BP - 6 . . . mov ax, [bp-6] ; Put third word in AX mov bx, [bp-4] ; Put second word in BX mov cx, [bp-2] ; Put first word in CX . . . add sp, 6 ; Restore stack pointer ; (two bytes per push) pop bp ; Restore BP
<<< Popping Values from Stack | Index | Saving Flags on the Stack >>> |