Bug when declaring struc as first element after [Section .bss]
Check the code sample below:
Code:
[Section .bss]
;hInstance resd 1 ;Instance
struc test
.first resb 1
.second resb 2
endstruc
hInstance resd 1 ;Instance
[section .text]
[GLOBAL] start
start:
push 0
extern GetModuleHandleA
call GetModuleHandleA
push eax
push hInstance
extern HexPrint
pop eax
mov [hInstance],eax
call HexPrint
push 0
extern ExitProcess
call ExitProcess
Sorr, forgot to mention that I use NASM 2.08rc1
Windows XP pro
\Nasm\bin\nasm -fwin32 StructureBug.asm -l StructureBug%.lst
Regards
Klod
Hi Klod,
This is subtle! "section .bss" is a macro, which expands to "[section .bss]" - and sets the "__SECT__" macro to .bss. The "struc" macro depends on "__SECT__" to get back from the "absolute" section to whatever section we were in. Supposed to be ".bss", but because "[section...]" didn't set "__SECT__", we switch back to ".text", where "__SECT__" was initialized. It *does* tell you this in the Friendly Manual...
http://www.nasm.us/doc/nasmdoc6.html#section-6.3.1 (http://www.nasm.us/doc/nasmdoc6.html#section-6.3.1)
... but perhaps doesn't make it fully clear. You've got to use the "user level" (macro) form of the "section" directive if the "struc" macro is going to work correctly.
Just remove the "[]" from your section declarations and it'll work fine (I think).
Best,
Frank
Thanks Frank for your quick reply. I missed this subtle difference.
Klod