News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Question about PUSH POP in 32 bit assembler.

Started by kaiserimpact, July 21, 2011, 03:53:32 PM

Previous topic - Next topic

kaiserimpact

The original user deleted the question after he got an answer, the following answers will give you the context of his question.

bomz


bomz

.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



Coma

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)
Coma Homepage 20:00-23:00 GMT+2 --- http://ge2001.dyndns.org:44792

hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

bomz

http://www.emu8086.com/  may be it's better try 16 bit assembler first? this program allow see how computer work



kaiserimpact

wow thanks ppl. really appreciate it very much! thread closed

dedndave

 :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

hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php