Author Topic: Bug  (Read 7168 times)

nobody

  • Guest
Bug
« on: January 07, 2010, 02:51:00 AM »
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

nobody

  • Guest
Re: Bug
« Reply #1 on: January 07, 2010, 02:58:51 AM »
Sorr, forgot to mention that I use NASM 2.08rc1
Windows XP pro
\Nasm\bin\nasm  -fwin32  StructureBug.asm -l StructureBug%.lst

Regards
Klod

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Bug
« Reply #2 on: January 07, 2010, 05:11:41 AM »
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

... 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

nobody

  • Guest
Re: Bug
« Reply #3 on: January 08, 2010, 03:59:53 AM »
Thanks Frank for your quick reply. I missed this subtle difference.

Klod