News:

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

Quite confused.

Started by Kookiies, March 01, 2010, 02:25:55 PM

Previous topic - Next topic

Kookiies

Hello guys, I am really new to the Assembly Language and I'd like to ask something:

I plan to become a programmer because it is one of my hobbies.
The problem is that I am trying to learn asm but I cannot even try and make test programs because I am having great difficulty with stacks, popping and pushing, even if I go through tutorials - but I can understand the other things though.

I would greatly appreciate it if someone could break it down for me in detail (stacks, popping and pushing).

PS. I have been on a number of forums and the pages on this forum (and also posting and etc) load really fast  :U.

dedndave

welcome to ASM and the forum   :U

the ESP register always points to the last dword pushed onto the stack

when you PUSH a dword value, whether it is a number, a memory value, or a register, the
processor subtracts 4 from the ESP register, then places the pushed value at that address

when you POP a value into memory or a register, the processor
retrieves the value at [ESP], then adds 4 to the ESP register

when you CALL a routine, the processor PUSHes the return address value
when you RET from the routine, the processor POPs the value into the EIP register

Kookiies

Ah ok, I get that.
Thanks, dedndave.
And also, what tutorials would you recommend for a complete beginner dedndave?

dedndave

well - in the upper right hand corner of the forum, you will find links
one of them is to Iczelion's tutorials
also - you can find links to d/l the intel programmers reference manuals
in the masm32 folder, help, examples, and tutorials subfolders have a lot of good material
Randy Hyde's AOA is available online also
http://www.arl.wustl.edu/~lockwood/class/cs306/books/artofasm/toc.html

one more source is the forum search tool   :P
i find much of what i need has already been discussed

Sergiu FUNIERU

Quote from: Harun on March 01, 2010, 02:25:55 PMI would greatly appreciate it if someone could break it down for me in detail (stacks, popping and pushing).
For me, it was easier to understand how stack works by creating a simple program that saves something to the stack (that is push-ing) then restoring from the stack (that is pop-ing).

I use OllyDbg to debug it and to see what happens on the stack.
http://www.ollydbg.de/download.htm

This is the program I used (I also attach it as a asm inside a zip file)
.686
include c:\masm32\include\masm32rt.inc

.code
start:
push edx
pop ecx

inkey "Press any key to exit..."

exit
end start


Before running "push edx"
ECX = 75CD3811
EDX = 00401000
current value of the stack = 75CD3823


After running "push edx"
ECX = 75CD3811
EDX = 00401000
current value of the stack = 00401000


After running "pop ecx"
ECX = 00401000
EDX = 00401000
current value of the stack = 75CD3823
(the value which was before pushing).
That value was pushed down from the upper position in the stack then got back to the top after the new value was popped.






jj2007

QuoteBefore running "push edx"
ECX = 75CD3811
EDX = 00401000
current value of the stack = 75CD3823

"Value of stack" would generally be interpreted as "value of esp". What you mean is
Quotevalue of the dword in memory at the current stack pointer position
which can be obtained with a simple
mov eax,  [esp]  ; get value of dword at current stack position without changing stack pointer
or
pop eax ; get value of dword at current stack position, add 4 to esp