flat assembler
Message board for the users of flat assembler.

Index > Main > Passing reference to procedures.

Author
Thread Post new topic Reply to topic
system error



Joined: 01 Sep 2013
Posts: 671
system error
Code:
push x ;pass address of val
call change_by_ref
invoke exit,0
val dd 0

proc change_by_ref
     push ebp
     mov ebp,esp
     mov dword[ebp+8],34 ;supposed to change val in main? Nope?
     pop ebp
ret
endp    


This code doesn't work. It keeps displaying 0 for val. Is this the correct way to pass reference argument to a procedure?
Post 05 Mar 2014, 18:19
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
Code:
push x ;pass address of val
call change_by_ref
invoke exit,0
val dd 0

proc change_by_ref, SomePointer
        mov   eax, [SomePointer]
        mov   dword [eax], 34
        ret
endp    


The macro proc will define for you the procedure stack frame management code. If you really want to do everything by hands, don't use "proc":

Code:
push x ;pass address of val
call change_by_ref
invoke exit,0
val dd 0

change_by_ref:
        mov   eax, [esp+8]
        mov   dword[eax], 34 ;supposed to change val in main? Nope?
        retn    

_________________
Tox ID: 48C0321ADDB2FE5F644BB5E3D58B0D58C35E5BCBC81D7CD333633FEDF1047914A534256478D9
Post 05 Mar 2014, 18:32
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
system error



Joined: 01 Sep 2013
Posts: 671
system error
JohnFound wrote:
Code:
push x ;pass address of val
call change_by_ref
invoke exit,0
val dd 0

proc change_by_ref, SomePointer
        mov   eax, [SomePointer]
        mov   dword [eax], 34
        ret
endp    


The macro proc will define for you the procedure stack frame management code. If you really want to do everything by hands, don't use "proc":

Code:
push x ;pass address of val
call change_by_ref
invoke exit,0
val dd 0

change_by_ref:
        mov   eax, [esp+8]
        mov   dword[eax], 34 ;supposed to change val in main? Nope?
        retn    


thanks john found.
Post 05 Mar 2014, 22:00
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.