News:

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

Pass By Reference

Started by ThatLlamaGirl, April 25, 2011, 08:05:04 PM

Previous topic - Next topic

ThatLlamaGirl

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.

jj2007

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

ThatLlamaGirl

Thanks, that worked!  I knew it was something simple, just didn't know what!