Say I have 3 numbers I want to keep so I do this
mov eax,num1
push eax
mov eax,num2
push eax
mov eax,num3
push eax

Now I want to get the first number I put in the stack, so I pop eax 3 times, but after I want the rest of the numbers back in the stack, how do I do that?

pop eax ; num3
pop eax ; num2
pop eax ; num1

How do I return num2 and num1 to the stack as they were?
Posted on 2003-04-14 08:51:48 by CyberGuy
Are you doing Forth mimics ?

well man the stack is just another memory area

push num1
push num2
push num3

mov ebp,esp

now you can deal with them like this:

num1 at
num2 at
num3 at

the only probelem is with really big number sequences, they could go beyond a stack page frame (4K)
but 3 numbers put no problems
Posted on 2003-04-14 09:01:52 by BogdanOntanu

the only probelem is with really big number sequences, they could go beyond a stack page frame (4K)
but 3 numbers put no problems

What is a "stack page frame" ? =)
There's no problem using more than 4k stack - you can use a LOT of stack. Just access it linearly from top to bottom (or bottom to top, depending on how you think - that is, from esp+00 to esp+nn) and you wont have problems. If you need random access, pretouch the stack. Read up on Guard Pages if you wonder why.
Posted on 2003-04-14 09:04:20 by f0dder
Thanks, it works perfectly.
Posted on 2003-04-14 09:09:38 by CyberGuy
CyberGuy,

Here is a quick example:




.386
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\user32.lib

.data
.data?
buffer db 12 dup(?)
.code
start:
push 10000
push 20000
push 30000
mov eax,[esp+8] ;0:30000 +4:20000 +8:10000
invoke dw2a,eax,addr buffer
invoke StdOut,addr buffer
add esp,12;release the stack 3*4=12
invoke ExitProcess,0
end start

Posted on 2003-04-14 09:09:59 by Vortex
It will be better to use my quick example because
it is shorter (1024 bytes only) and hasn't
additional garbage in it...


.386
.model flat, stdcall
option casemap:none

include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
include \masm32\include\masm32.inc
includelib \masm32\lib\masm32.lib

.code ;
start: ;
push 0 ; 0 zero->string
push 30303033h ; ASCII code -> 3000
push 30303032h ; ASCII code -> 2000
push 30303031h ; ASCII code -> 1000
push esp ; addr buffer -> 0:1000 +4:2000 +8:3000
push ExitProcess ; return address
jmp StdOut ; call proc
end start ;

Regards,
Lingo
Posted on 2003-04-14 18:24:16 by lingo12
as if that really mattered.
But fun nevertheless.
Posted on 2003-04-15 01:47:54 by f0dder
Mea culpa fodder ,

What i meant was a "stack guard page" -- as in paging and virtual memory management tricks used by modern OS (aka Windows) to extend the Stack selector size for specific process...

It was dumb for me to bring it up on ...
Posted on 2003-04-15 02:02:02 by BogdanOntanu
Now,look at here lingo kid,

Instead of studying C run-time DLLs,you are wasting your time by doing stupid
things.Your genius application contains only one section.This is your main trick.
Now,little kid,prove that you are a REAL MAN:tell us what is your problem with me?

You made again mistakes:your app. displays all the three numbers instead of the first.

Where are you from?
Posted on 2003-04-15 02:10:55 by Vortex