|
Assembly A little text to describe your forum
|
Important Notice:
We regret to inform you that our free phpBB forum hosting service will be discontinued by the end of June 30, 2024.
If you wish to migrate to our paid hosting service, please contact billing@hostonnet.com.
View previous topic :: View next topic |
Author |
Message |
fbkotler
Joined: 05 Oct 2009 Posts: 5 Location: New Hampshire, USA
|
Posted: Mon Oct 05, 2009 5:48 am Post subject: Nasm preprocessor |
|
|
Klod and I are trying to discuss this on the SourceForge Nasm beginner's questions forum. It has become impossible. I think what he's trying to do is...
;-------------------
%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?
--------------------------------
Well, you're not going to be able to mov a 32-bit address into a 16-bit register. Use a 32-bit register, or perhaps "Mov Bx, [ddBlah(.High)]".
I should note that you've got ".High" and ".Low" reversed from their usual usage...
If this works out better than the SF forum, talk to ya soon!
Best,
Frank |
|
Back to top |
|
|
Klod
Joined: 05 Oct 2009 Posts: 5
|
Posted: Thu Oct 08, 2009 2:34 am Post subject: |
|
|
Hi Frank, I finally activated my account and it looks like I on board
Klod |
|
Back to top |
|
|
fbkotler
Joined: 05 Oct 2009 Posts: 5 Location: New Hampshire, USA
|
Posted: Fri Oct 09, 2009 2:21 am Post subject: |
|
|
So, is it working for you? I don't see what you're trying to do with "mov reg16, 32-bit address"...
Best,
Frank |
|
Back to top |
|
|
Klod
Joined: 05 Oct 2009 Posts: 5
|
Posted: Fri Oct 09, 2009 2:57 pm Post subject: |
|
|
This was a test program Synfire had worked out and works on Linux.
For some reason I cannot make it work on win32 XP pro
I would have liked to attach it as a zip file, but this forum does not support it. Here is the code:
Code: | BITS 32
%imacro ASSUME 2
%ifidni %2, NOTHING
%undef %{1}.
%else
%idefine %{1}.(_x_) %{1} + %{2} %+ . %+ _x_
%endif
%endm
STRUC HighLow
.High RESW 1
.Low RESW 1
ENDSTRUC
SECTION .data
ddBlah DD 123456789
strFmt DB `High Word: %d\nLow Word: %d\nAddress of High Word: 0x%08X\nAddress of Low Word: 0x%08X`, 0
strBuf TIMES 1025 DB 0
SECTION .text
Global start
start:
Xor Eax, Eax
Xor Ebx, Ebx
ASSUME ddBlah, HighLow
Mov Ax, [ddBlah.(Low)]
Mov Bx, [ddBlah.(High)]
Lea Edx, [ddBlah.(Low)]
Lea Ecx, [ddBlah.(High)]
ASSUME ddBlah, NOTHING
Push Edx
Push Ecx
Push Eax
Push Ebx
Push DWORD strFmt
Push DWORD strBuf
Extern wsprintfA
Call wsprintfA
Add Esp, (3*4)
Push DWORD 0
Push DWORD 0
Push DWORD strBuf
Push DWORD 0
Extern _MessageBoxA@16
Call _MessageBoxA@16
Push DWORD 0
Extern _ExitProcess@4
Call _ExitProcess@4
|
The problem is with this line
%idefine %{1}.(_x_) %{1} + %{2} %+ . %+ _x_
Mov Ax, WORD[ddBlah.(Low)]
ddBlah.(Low) will be defined as ddBlah+HighLow._x_
should be defined as ddBlah+HighLow.Low
_x_ is added as string in the define but should be added as parameter Low
So naturally I get compile time error symbol HighLow._x_ not defined. |
|
Back to top |
|
|
fbkotler
Joined: 05 Oct 2009 Posts: 5 Location: New Hampshire, USA
|
Posted: Fri Oct 09, 2009 7:43 pm Post subject: |
|
|
Hi Klod,
Being able to attach a .zip file would be nice, but I cut 'n pasted your code - works fine for me(!). This is on Linux, but assembled as "-f win32". I can't run it, of course, or even link the object file, but Nasm does its part without complaint, and adding the "-e" switch looks "as intended".
Linux and Windows builds of Nasm use exactly the same source code (#IFDEFs excepted). Interfacing with the OS (file I/O and memory management, mostly) is completely different, but "text bashing" should be the same. However, there are subtle differences between compilers. (very recent versions of gcc are more aggressive about what's "allowed" between "sequence points", for example)
If this really turns out to work on Linux, but not on Windows, it may make a difference whether you downloaded a precompiled binary or built it yourself. If this turns out to be an issue, SpooK is the logical guy to discuss it with (he wrote the 64-bit extensions for outcoff.c... and outmacho.c...)
I would point out that "add esp, 4 * 3" is no longer correct, but that shouldn't matter to this issue...
Best,
Frank |
|
Back to top |
|
|
Klod
Joined: 05 Oct 2009 Posts: 5
|
Posted: Sat Oct 10, 2009 12:21 am Post subject: |
|
|
Hi Frank,
I was in a hurry this morning when I posted. The code sample I had originaly posted was I test piece.
Code: | %define ddBlah(x) ddBlah+HighLow %+x
Mov Ax, word[ddBlah(.Low)]
Mov Bx, word[ddBlah(.High)] ;This is what I wanted
Mov edx, ddBlah(.High) ;get the address
%undef ddBlah |
This works correctly. x is treated as parameter not as string. this is what I tryed to do.
Quote: | So, is it working for you? I don't see what you're trying to do with "mov reg16, 32-bit address"... |
I belive this is the error you spotted in the. Mov Ax, [ddBlah(.Low)], I had not specified the size and it should have been Mov Ax, word[ddBlah(.Low)]
I have looked at the problem from a straight preprocessor point of view because the simbols are not being defined as I "expected".
To ilustrate my problem further,
%imacro ASSUME 2
%ifidni %2, NOTHING
%undef %{1}.
%else
%define %{1}(x) ddBlah+HighLow %+x
%endif
%endm
does not work either
It seems to me that any attempt to define anything inside the ASSUME macro will change the behaviour of x from parameter to string.
Regards Klod
|
|
Back to top |
|
|
fbkotler
Joined: 05 Oct 2009 Posts: 5 Location: New Hampshire, USA
|
Posted: Sat Oct 10, 2009 1:26 am Post subject: |
|
|
The line you posted:
%define %{1}(x) ddBlah+HighLow %+x
lacks a space after "%+", which the docs claim is required. Works okay for me that way, too...
"mov ax, ???" shouldn't need a "word" qualifier - the register size specifies the operation size... If "???" is a 32-bit address, you get that "COFF does not support non-32-bit relocations" error - different issue.
I can't seem to duplicate this problem of "x" or "_x_" being treated as a string instead of a parameter. You might try "%xdefine" and see if it helps. Try it with a space after "%+", too...
Of course, you could always switch to Linux. :)
Best,
Frank |
|
Back to top |
|
|
Klod
Joined: 05 Oct 2009 Posts: 5
|
Posted: Sat Oct 10, 2009 3:51 am Post subject: |
|
|
Hi Frank
thanks for your reply
I have a brutal week behind me and I'm mentally drained.
Sorry, I copied the wrong statement, should have been
Mov Bx, ddBlah(.High) ;Mov EBX,ddBlah(.High)
Believe me, I tried every possible combination of arrangements of the parameters. including the %+ x.
I have copied Synfires test code into a text file, assembled it and it fails. I uploaded the file back. I compiled it on 3 different machines, (2 XP pro and 1 XP Home) and it fails with the same error messages on all.
http://www.asmcommunity.net/board/index.php?topic=29571.msg209046#msg209046
I hoped other window users would download it, compile it on real window hardware and voila.... So as it stands -->Klod bad Nasm good
It appears that I'm the only NASM user on windows???
I will give this thread a rest for a while and continue using Nasm's normal syntax/
Thanks for your help
Klod |
|
Back to top |
|
|
fbkotler
Joined: 05 Oct 2009 Posts: 5 Location: New Hampshire, USA
|
Posted: Sat Oct 10, 2009 6:40 am Post subject: |
|
|
Maybe "Nasm good, Nasm-for-Windows bad".
I agree that it's time to give this thread a rest. In order to download your/SpooK's test file, I hadda join their club. Maybe see you around there...
Best,
Frank |
|
Back to top |
|
|
|
|
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
|
|