Does data remain in stack after pop operation?

Viewed 110

I know the pop instruction does this :

Loads the value from the top of the stack to the location specified with the destination operand (or explicit opcode) and then increments the stack pointer

but I can't access the data when I pop it !

I have this code :

mov ah , 0x0e
mov bp, 0x8000
mov sp , bp
push 'A'

mov al , [0x7ffe]
int 0x10    ; print A

pop bx
mov al ,bl
int 0x10    ; print A

mov al , [0x7ffe]
int 0x10    ; **print random chare !**


jmp $
times 510-($-$$) db 0
dw 0xaa55

Why does the third int 0x10 not print 'A' ?

1 Answers

At the first mov al, [0x7ffe] you have access to the memory at address 0x7FFE because you just reserved it for your stack with push, but after you used pop the stackpointer got increased and gave free that address. You no longer have ownership of it and so other processes can use that address and will overwrite your stored value. That's why you get an apparently random number at that address.

Related