NASM - The Netwide Assembler
NASM Forum => Using NASM => Topic started by: nobody on January 15, 2008, 03:10:00 AM
-
I'm experimenting with Nasm and I started with demo11 from your 2.0 distribution.
Im having problems using the latest proc macros. I'm used to Masm syntax and like the stile but have a hard time to make it work.
The example may illustrate:
entry consol
[section .bss]
fname: resb 260
lname: resb 260
age: resd 1
[section .text]
CHAR Title, "My first console program"
proc consol
LOCALS
LOCAL pTitle, dword ;local variable
ENDLOCALS
invoke printf, "Nasm Version %s%c%c", __NASM_VER__,13,10
invoke printf,"-----------------%c%c",13,10
invoke printf,"%s%c%c%c%c", Title,13,10,13,10
invoke printf, "First Name: "
invoke scanf, "%260s", fname
invoke printf, "Last Name: "
invoke scanf, "%260s", lname
invoke printf, "Age: "
invoke scanf, "%01d", age
mov eax, [age]
if eax, >=, 21
invoke printf, "Hello, %s %s! What are you having today?", fname, lname
else
invoke printf, "Sorry kid, you're only %d !%c%c", [age],13,10
endif
invoke printf, "The Address of Title: %x%c%c", Title,13,10
;This is what I try to do:
mov dword[ebp-4],fname
invoke printf,"The string pointed at: %s%c%c",[ebp-4],13,10
;This is what I thought it should be but dont work!
mov dword[pTitle],Title ;attemtet to store addr of Title in local var
invoke printf,"The string pointed at: %s%c%c",[pTitle],13,10
invoke printf, "%c%c%c%cPress any key to exit.",13,10,13,10
invoke _getch
xor eax, eax
ret
endproc
The question I have is this:
How do I address the local var by its name?
Masm syntax, lea eax pTitle don't work either
any help would be appreciated
tx Klod
-
Doesn't look like anything you found at this site. Nasmx?
In what manner does it not work?
The "-e" switch or the "-l" switch may be helpful to see what this "hidden cruft" actually emits - if it'll assemble at all...
Good Luck,
Frank
-
Hi Klod
In this code :
mov dword[pTitle],Title
you are trying to re-write something in .text which is the code
area. I think Windows forbids this.
You can make this work by moving the variable "pTitle" out of
the .text section and into an initialized data section :
[section.data]
pTitle dd 0
I think the LOCAL statement is for initializing variables in a code
area *but I'm not sure*. If so, then the variables would be read-only. I eliminated the LOCAL directives altogether.
What surprised me most was that
mov dword[pTitle],Title
actually worked. I would have thought a register would be required:
mov eax,pTitle
mov dword [pTitle],eax
Live and learn!
Hope this helps.
mcamember
-
Of course that last code line *should* have read:
mov eax,Title <------
mov dword [pTitle],eax
;mcamember