The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: john113 on April 28, 2008, 11:01:11 PM

Title: stack and proc
Post by: john113 on April 28, 2008, 11:01:11 PM
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         


Title: Re: stack and proc
Post by: NightWare on April 28, 2008, 11:23:05 PM
maybe too much PUSH...  :wink jump after...
Title: Re: stack and proc
Post by: raymond on April 29, 2008, 02:34:52 AM
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.
Title: Re: stack and proc
Post by: evlncrn8 on April 29, 2008, 05:55:37 AM
;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?
Title: Re: stack and proc
Post by: Darrel on April 29, 2008, 05:59:52 AM
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
Title: Re: stack and proc
Post by: raymond on April 30, 2008, 02:23:00 AM
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.
Title: Re: stack and proc
Post by: Darrel on April 30, 2008, 03:48:22 AM
You are correct Raymond.