Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

ASM Question

Name: Anonymous 2011-03-09 1:33

A section from the ASM guide I'm reading:
"MOV  AX,51h
MOV  BX,4Fh
XCHG AX,BX
PUSH AX
MOV  AX,34h
POP  BX
PUSH BX
POP  AX
First AX is equal to 51h and BX to 4Fh, than the 2 get exchanged.  Now we got
AX = 4Fh and BX = 51h.  AX gets pushed on the stack, then set to 34h:
AX = 34h and BX = 51h.  BX gets poped, than pushed:
AX = 34h and BX = 4Fh.  Finally AX gets poped.  So the final result is:
AX = 4Fh and BX = 4Fh"


Can someone please explain why AX= 4Fh and not 34h?? That's the last value that was copied to it.

Name: Anonymous 2011-03-09 1:38

*[code]

Name: Anonymous 2011-03-09 1:40

>>2

Sorry I haven't posted on /prog/ much and wasn't sure if [code] was supported. Hopefully the text is still readable/good enough for your eyes, your highness.

Name: Anonymous 2011-03-09 1:46

>>3
No.

Name: Anonymous 2011-03-09 1:46

>>3
Don't listen to >>2.
>>2
Here's the [code]ified version:

MOV  AX,51h
MOV  BX,4Fh
XCHG AX,BX
PUSH AX
MOV  AX,34h
POP  BX
PUSH BX
POP  AX

First AX is equal to 51h and BX to 4Fh, than the 2 get exchanged.  Now we got
AX = 4Fh and BX = 51hAX gets pushed on the stack, then set to 34h:
AX = 34h and BX = 51hBX gets poped, than pushed:
AX = 34h and BX = 4Fh.  Finally AX gets poped.  So the final result is:
AX = 4Fh and BX = 4Fh

Name: Anonymous 2011-03-09 1:55

The PUSH instruction stores its operand on the stack.

The POP instruction retrieves the most recent pushed value.

Read this OP http://www.c-jump.com/CIS77/ASM/Stack/lecture.html

Name: Anonymous 2011-03-09 2:09

>>6
The POP instruction retrieves the most recent pushed value.
It's documentation like this that's killing programming.

Name: Anonymous 2011-03-09 4:18

POP stuff is just:
mov stuff,[(e)sp]
add (e)sp,{size of popped object}

Or just take whatever is at the top of the stack and place it in the argument passed to pop then add the stack pointer by the size of popped object (usually 2-4 bytes depending on CPU mode, see Intel CPU documentation for details).

Name: Anonymous 2011-03-09 6:57

AUTISM

Name: Anonymous 2011-03-09 7:04

>>8
or sub

Name: Anonymous 2011-03-09 7:06

>>10
Depends on the direction the stack grows in. On x86, it grows down.

Name: Anonymous 2011-03-09 7:24

>>11
This depends on how you define ``down''.

Name: Anonymous 2011-03-09 7:28

>>12
down - to lower addresses
up - to higher addresses

Name: Anonymous 2011-03-09 7:45

I, personally, hate it when I get poped.

Name: Anonymous 2011-03-09 9:18

>>14
Well that's why no one invites you to our Discordian parties no more.

Name: Anonymous 2011-03-09 17:46

>>15
Discord? I prefer diminished FORTH

Don't change these.
Name: Email:
Entire Thread Thread List