The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: kaiserimpact on July 21, 2011, 03:53:32 PM

Title: Question about PUSH POP in 32 bit assembler.
Post by: kaiserimpact on July 21, 2011, 03:53:32 PM
The original user deleted the question after he got an answer, the following answers will give you the context of his question.
Title: Re: Help needed with MOV, PUSH and POP
Post by: bomz on July 21, 2011, 04:04:52 PM
ax=3000h bx=1000h cx=2000h
Title: Re: Help needed with MOV, PUSH and POP
Post by: bomz on July 21, 2011, 04:08:21 PM
.386

.model flat, stdcall
option casemap :none

include \MASM32\INCLUDE\windows.inc
include \MASM32\INCLUDE\masm32.inc
include \MASM32\INCLUDE\user32.inc
include \MASM32\INCLUDE\kernel32.inc
includelib \MASM32\LIB\masm32.lib
includelib \MASM32\LIB\user32.lib
includelib \MASM32\LIB\kernel32.lib

.data
form db "AX: %x BX: %x CX %x", 0


.data?
buffer db 512 dup(?)

.code
start:
xor eax, eax
xor ebx, ebx
xor ecx, ecx

MOV AX ,1000H
MOV BX ,2000H
MOV CX ,3000H

PUSH AX
PUSH BX
PUSH CX

POP AX
POP CX
POP BX

invoke wsprintf,ADDR buffer,ADDR form,eax, ebx, ecx
invoke MessageBox,0,ADDR buffer,NULL,MB_ICONASTERISK
invoke ExitProcess,0
end start


(http://i005.radikal.ru/1107/19/cb173263e21b.png)
Title: Re: Help needed with MOV, PUSH and POP
Post by: Coma on July 21, 2011, 04:12:56 PM
After loading AX, BX or CX with a value the higher word of EAX, EBX or ECX remains untouched. So, i.e. EAX could be ABCD3000h if the higher word of EAX was ABCDh.

Final values:
AX=3000h
CX=2000h
BX=1000h

Simple rule:
Last IN (Push)
First OUT (Pop)
Title: Re: Help needed with MOV, PUSH and POP
Post by: hutch-- on July 21, 2011, 04:14:32 PM
The order that you POP the 3 registers is the reverse order of the 3 that you pushed. The stack is a last on, first off system with PUSH / POP.
Title: Re: Help needed with MOV, PUSH and POP
Post by: bomz on July 21, 2011, 04:15:33 PM
http://www.emu8086.com/  may be it's better try 16 bit assembler first? this program allow see how computer work


(http://i058.radikal.ru/1102/64/eea23a98dc88.gif)
Title: Re: Help needed with MOV, PUSH and POP
Post by: kaiserimpact on July 22, 2011, 12:46:25 AM
wow thanks ppl. really appreciate it very much! thread closed
Title: Re: thread closed
Post by: dedndave on July 22, 2011, 03:01:53 AM
 :bg
we don't "close threads" unless there is something malicious in them
that way, the topic title, etc may be searched for future reference
not to worry
most everyone in here knows how the stack works
i am surprised that bogdan hasn't noticed this thread   :lol
Title: Re: thread closed
Post by: hutch-- on July 22, 2011, 07:40:02 AM
I have, make a point of not doing this again, this is a forum of members, not a paid help desk.  :tdown

The thread is now locked.