The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: ThatLlamaGirl on April 25, 2011, 08:05:04 PM

Title: Pass By Reference
Post by: ThatLlamaGirl on April 25, 2011, 08:05:04 PM
Hello-

New to the forum, sort of new to MASM.  I've had experience with MASM before, but it's been YEARS.  So I'm having annoying (simple) problems left and right.  I've managed to bang out most of them, but I'm having a hard time wrapping my brain around the pass by reference for a procedure. Here's a code chunk:

over proc i:ptr byte

mov esi, i
mov eax, [esi]
...
; print the value of eax (the value of i stored in eax) here, works
...
mov i, 0 ; the problem is here?
mov esi, i
mov eax, [esi] ; program hangs here.

I think I'm trying to set the value of i wrong, but I don't know how to do it right.  How do I set the value of a parameter that is passed by reference?  I know the answer is probably something really easy, but it's been forever since I've touched any assembly-like code.
Title: Re: Pass By Reference
Post by: jj2007 on April 25, 2011, 08:11:16 PM
mov i, 0 ; the problem is here?
mov esi, i
mov eax, [esi] ; program hangs here.

esi points to memory location zero - that won't work. Do it like this:

.data
MyDword dd 123
.code
mov esi, offset MyDword
mov eax, [esi]  ; OK
mov dword ptr [esi], 456  ; OK - the dword ptr tells the assembler what size we are using
mov eax, 789
mov [esi], eax  ; OK - no dword ptr needed because eax is dword anyway
Title: Re: Pass By Reference
Post by: ThatLlamaGirl on April 25, 2011, 08:13:54 PM
Thanks, that worked!  I knew it was something simple, just didn't know what!