NASM - The Netwide Assembler
NASM Forum => Other Discussion => Topic started by: dapleal on July 01, 2012, 12:12:09 AM
-
Hi. I´ve been trying Nasm 2.10 and Nasmx-1.0 for win32 OOP, and it´s been quite an interesting learning experience. I'm having some trouble with STRUC/ENDSTRUC and ISTRUC/IEND in Nasm 2.1. (I´m using ALINK). Say, If I declare two STRUC/ENDSTRUC definitions [struc A/endstruc, struc B/endstruc ], the compiler displays an error msg pointing to the first ENDSTRUC. The same happens with the ISTRUC/IEND at [segment .data]. It seems to me that the compiler does not allow more than one ENDSTRUC or IEND within the code. Is that right ? Cause Nasm documentation is not clear enough on that subject, and if I delete the error lines, it doesn´t work either. Any ideas ? Could it be a linker problem ?
-
The following is a simple (but not meant to be directly executed) example that successfully assembles to coff/win32.
[BITS 32]
struc A
.test RESD 1
endstruc
struc B
.test RESD 1
endstruc
[section .text]
lea ebx,[iA]
mov eax,DWORD[ebx+A.test]
[section .data]
iA:
istruc A
at A.test, DD 1
iend
iB:
istruc B
at B.test, DD 1
iend
If you get any errors with the above example, it is entirely ALINK.
-
OK. It works. I've just had to type an entry point (..start:) underneth the [section .text] line.
I'm compiling like this: (as usuall, but not used STRUC/ENDSTRUC till now)
nasm -f obj (name).asm
alink (name).obj -o PE -subsys windows
It generates the .exe file, but still displays the following error msg:
"Relocs 0:Warning 32 bit offset in 16 bit field"
That´s what´s been killing me all day.
Any suggestion of another free linker just for testing ?
Thanks for the help.
-
You can give a chance to Jeremy Gordon's neat linker GoLink (http://www.godevtool.com/) and say goodbye to imports libs mess also you can try out Polink from PellesC or the classic Microsoft link.exe.
Regards.
-
+1 for GoLink. It is/was bundled with NASMX. IIRC, NASM32/NASMX started with ALINK, then moved to PoLink due to shortcomings with ALINK, and finally to GoLink for further quality/feature considerations.
-
It generates the .exe file, but still displays the following error msg:
"Relocs 0:Warning 32 bit offset in 16 bit field"
"-f obj" is by default a 16-bit format. As you know(?), it is necessary to declare each section/segment "use32". It might not hurt to put "bits 32" at the top of the file, just to "catch" anything that's not in a segment. Although "-f obj" and Alink may be considered "obsolete", it "should" still work fine and I'm not aware of any disadvantage.
Best,
Frank
-
Hi. Just to tell I realized what I was doing wrong with “ISTRUC/IEND”. Sorry for the trouble, it works just like you said.
On page 70 of the NASMDOC.PDF file (NASM 2.10 documentation) there are two given examples on “STRUCTURE / ENDSTRUC”. While on the following page there´s only one given on “ISTRUC / IEND”.
I would dare to suggest you guys may also include the corresponding “ISTRUC/IEND” example to the other one. It may save hours of frustration to other beginners like me. That is:
struc mytype
.long: resd 1
.word: resw 1
.byte: resb 1
.str: resb 32
endstruc ; (page 70)
mystruc:
istruc mytype
at mytype.long, dd 123456
at mytype.word, dw 1024
at mytype.byte, db ’x’
at mytype.str, db ’hello, world’, 13, 10, 0
iend
(there is no such example on page 71 within the .pdf doc file)
What I was doing wrong was:
mystruc:
istruc mytype
at .long, dd 123456
at .word, dw 1024
at .byte, db ’x’
at .str, db ’hello, world’, 13, 10, 0
iend
Thanks for the help. Congratulations for the great job with NASM and NASMX.