NASM - The Netwide Assembler
NASM Forum => Using NASM => Topic started by: nobody on October 05, 2009, 04:30:04 AM
-
> BlockquoteHi Frank
I have been mucking around with preprocessor directives again. I have tried to make use of Synfires ASSUME macro, but could not make it work under Windows.
So I decided to start with the Doc:
4.1.3 Concatenating Single Line Macro Tokens: %+
Individual tokens in single line macros can be concatenated, to produce longer tokens for later processing. This can be useful if there are several similar macros that perform similar functions.
Please note that a space is required after %+, in order to disambiguate it from the syntax %+1 used in multiline macros.
I took the Ideas and modified Synfire's code snippet to work on Windows XP, taking the assume macro out and try the technique discribed obove:
> Blockquote
%define ddBlah(x) ddBlah+HighLow %+x
EXTERN wsprintfA
EXTERN ExitProcess
EXTERN MsgBox
STRUC HighLow
.High RESW 1
.Low RESW 1
ENDSTRUC
SECTION .data
ddBlah DD 123456789
strFmt DB `High Word: %d\nLow Word: %d\n`, 0
buffer TIMES 1024 db 0
caption db 'Testing',0
SECTION .text
Global Start
Start:
movzx eax,WORD[ddBlah+HighLow.High] ;access the structure with Nasm notation
movzx ebx,WORD[ddBlah+HighLow.Low] ; to prove out the program
Mov Ax, ddBlah(Low) ;assembled -e option Mov Ax, ddBlah+HighLowLow
Mov Bx, ddBlah(.High) ;assembled -e option Mov Bx, ddBlah+HighLow.High This is what I wanted
Push Eax
Push Ebx
Push DWORD strFmt
push dword buffer
Call wsprintfA
push caption
push buffer
call MsgBox
push 0
call ExitProcess
;Radasm IDE 3,O,$B\NASM -Ox -fwin32 ,2 ;latest version from download
;$.exe,O,$B\GoLink.EXE @$B\GFL.txt /debug coff /entry Start ,3`
> These are the two errors I get for obove code sample
MacroTest.asm:24: error: symbol `HighLowLow' undefined
MacroTest.asm:25: error: COFF format does not support non-32-bit relocations
As can be seen from the -e assembly Mov Bx, ddBlah(.High) assembled to Mov Bx, ddBlah+HighLow.High, what I wanted but I get MacroTest.asm:25: error: COFF format does not support non-32-bit relocations
Do you have any suggestions or known workarounds?
Regards Klod
`
-
> %define ddBlah(x) ddBlah+HighLow %+x
EXTERN wsprintfA
EXTERN ExitProcess
EXTERN MsgBox
STRUC HighLow
.High RESW 1
.Low RESW 1
ENDSTRUC
SECTION .data
ddBlah DD 123456789
strFmt DB `High Word: %d\nLow Word: %d\n`, 0
buffer TIMES 1024 db 0
caption db 'Testing',0
SECTION .text
Global Start
Start:
movzx eax,WORD[ddBlah+HighLow.High] ;access the structure with Nasm notation
movzx ebx,WORD[ddBlah+HighLow.Low] ; to prove out the program
Mov Ax, ddBlah(Low) ;assembled -e option Mov Ax, ddBlah+HighLowLow
Mov Bx, ddBlah(.High) ;assembled -e option Mov Bx, ddBlah+HighLow.High This is what I wanted
Push Eax
Push Ebx
Push DWORD strFmt
push dword buffer
Call wsprintfA
push caption
push buffer
call MsgBox
push 0
call ExitProcess
;Radasm IDE 3,O,$B\NASM -Ox -fwin32 ,2
;$.exe,O,$B\GoLink.EXE @$B\GFL.txt /debug coff /entry Start ,3
> The formating really killed that one. resubmit the code sample, hoping for the best
Klod
-
Hi Klod,
This forum is just about completely useless for posting code! Fortunately, I get email notification that is a little better...
I think the "undefined symbol" is because you left out the "." in "Mov Ax, ddBlah(Low)". The "non-32-bit relocation" error is from trying to stuff a 32-bit address into a 16-bit register. Did you intend "[contents]"?
I'm afraid that's all I can come up with...
Best,
Frank