What is the behavior of the POP instruction? After testing some stuff last night, I get the impression that on x86, POP reads the data at SS:SP, writes back junk, and increments SP by 2.
The code I used:
trace:
I did it with slightly different orders a few times, and BX seems to come back with different numbers pretty much every time. I can't find any information on what happens to the memory location where AX was popped from after a pop (probably because you're not supposed to do things like this
).
What would other architectures do in a situation like this? (If it matters, I tested this on an pre-tbird Athlon)
The code I used:
MOV AX, ABCD
MOV BX, 1234
PUSH AX
NOP
POP AX
NOP
DEC SP
NOP
DEC SP
NOP
POP BX
NOP
NOP
trace:
AX=ABCD BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=0B1D ES=0B1D SS=0B1D CS=0B1D IP=0103 NV UP EI PL NZ NA PO NC
0B1D:0103 BB3412 MOV BX,1234
-T
AX=ABCD BX=1234 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=0B1D ES=0B1D SS=0B1D CS=0B1D IP=0106 NV UP EI PL NZ NA PO NC
0B1D:0106 50 PUSH AX
-T
AX=ABCD BX=1234 CX=0000 DX=0000 SP=FFEC BP=0000 SI=0000 DI=0000
DS=0B1D ES=0B1D SS=0B1D CS=0B1D IP=0107 NV UP EI PL NZ NA PO NC
0B1D:0107 90 NOP
-T
AX=ABCD BX=1234 CX=0000 DX=0000 SP=FFEC BP=0000 SI=0000 DI=0000
DS=0B1D ES=0B1D SS=0B1D CS=0B1D IP=0108 NV UP EI PL NZ NA PO NC
0B1D:0108 58 POP AX
-T
AX=ABCD BX=1234 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=0B1D ES=0B1D SS=0B1D CS=0B1D IP=0109 NV UP EI PL NZ NA PO NC
0B1D:0109 90 NOP
-T
AX=ABCD BX=1234 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=0B1D ES=0B1D SS=0B1D CS=0B1D IP=010A NV UP EI PL NZ NA PO NC
0B1D:010A 4C DEC SP
-T
AX=ABCD BX=1234 CX=0000 DX=0000 SP=FFED BP=0000 SI=0000 DI=0000
DS=0B1D ES=0B1D SS=0B1D CS=0B1D IP=010B NV UP EI NG NZ NA PE NC
0B1D:010B 90 NOP
-T
AX=ABCD BX=1234 CX=0000 DX=0000 SP=FFED BP=0000 SI=0000 DI=0000
DS=0B1D ES=0B1D SS=0B1D CS=0B1D IP=010C NV UP EI NG NZ NA PE NC
0B1D:010C 4C DEC SP
-T
AX=ABCD BX=1234 CX=0000 DX=0000 SP=FFEC BP=0000 SI=0000 DI=0000
DS=0B1D ES=0B1D SS=0B1D CS=0B1D IP=010D NV UP EI NG NZ NA PO NC
0B1D:010D 90 NOP
-T
AX=ABCD BX=1234 CX=0000 DX=0000 SP=FFEC BP=0000 SI=0000 DI=0000
DS=0B1D ES=0B1D SS=0B1D CS=0B1D IP=010E NV UP EI NG NZ NA PO NC
0B1D:010E 5B POP BX
-T
AX=ABCD BX=3333 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=0B1D ES=0B1D SS=0B1D CS=0B1D IP=010F NV UP EI NG NZ NA PO NC
0B1D:010F 90 NOP
-T
AX=ABCD BX=3333 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=0B1D ES=0B1D SS=0B1D CS=0B1D IP=0110 NV UP EI NG NZ NA PO NC
0B1D:0110 90 NOP
-
I did it with slightly different orders a few times, and BX seems to come back with different numbers pretty much every time. I can't find any information on what happens to the memory location where AX was popped from after a pop (probably because you're not supposed to do things like this
What would other architectures do in a situation like this? (If it matters, I tested this on an pre-tbird Athlon)
