News:

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

stack and proc

Started by john113, April 28, 2008, 11:01:11 PM

Previous topic - Next topic

john113

please help...cannot get this code to work!


.const
    para1 equ 0
    para2 equ 0

       
    .code                       
    start:                         
    print "Running.....",13,10
    invoke poo para1,para2                 
    print "Ended.",13,10
    invoke ExitProcess,0

;procedure code
poo proc para1:DWORD,para2:DWORD       
    push ebp
    mov ebp,esp
    push esi
    push edi
    mov eax,[ebp+8]
    mov ecx,[ebp+12]
    dec eax                     
    jnz poo                 
    pop edi
    pop esi
    pop ebp
    ret 8
   
poo endp                   

end start         



NightWare

maybe too much PUSH...  :wink jump after...

raymond

Use a debugger and step through your code. Watch what is happening in your registers and on the stack. You will then certainly understand why it doesn't work.

You're also missing a coma between your proc name and the first parameter when you invoke the proc.
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

evlncrn8

;procedure code
poo proc para1:DWORD,para2:DWORD       
    push ebp
    mov ebp,esp
    push esi
    push edi

    mov eax,[ebp+8]
    mov ecx,[ebp+12]

loopie:

    dec eax                     
    jnz loopie

    pop edi
    pop esi
    pop ebp
    ret 8
   
poo endp                   

something like that maybe, but your code will deadlock, u sure u know where you're wanting to loop...
can't actually see the point of the proc though, can you explain a little more?

Darrel

Each loop you mov 0 into eax then decrement eax (eax=-1), which makes it a never ending loop. From your procedure it looks like you want to setup the following loop:
loop00000:

       dec     eax
       jnz     loop00000

raymond

QuoteEach loop you mov 0 into eax

I would think he's moving the old value of EBP into EAX, which is a value of ESP prior to pushing all those registers!!! The stack eventually runs out of space and the program crashes.
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

Darrel

You are correct Raymond.