Author Topic: difference between bits 32 and use32  (Read 9725 times)

nobody

  • Guest
difference between bits 32 and use32
« on: April 03, 2008, 10:24:29 PM »
Hi

I've got such a program for windows:

---------------
extern ExitProcess
import ExitProcess kernel32.dll
extern MessageBoxA
import MessageBoxA user32.dll

section .data USE32
Title db 'Window',0
Content db 'Message',0

section .code USE32

..start:

push dword 0 ; MB_OK
push dword Title
push dword Content
push dword 0 ; no parent window
call [MessageBoxA]

push dword 0
call [ExitProcess]
---------------

Why when i change 'section .code USE32' to 'section .code BITS 32' nasm (nasm -fobj prog.asm) gives different obj?

Pawel S.

nobody

  • Guest
Re: difference between bits 32 and use32
« Reply #1 on: April 10, 2008, 10:44:48 PM »
Then don't change it.

Alternatively, RTFM.

nobody

  • Guest
Re: difference between bits 32 and use32
« Reply #2 on: April 13, 2008, 03:02:55 PM »
I have read that manual, and also that they are aliases, but if I don't change anything else in code (except USE32 to BITS 32), and don't change assembly options, so what is changing?

Pawel S.

nobody

  • Guest
Re: difference between bits 32 and use32
« Reply #3 on: April 13, 2008, 05:52:39 PM »
Hi Pawel,

This is subtle...

"use32" is an alias for the *directive* "bits 32" - the actual raw form is "[bits 32]" - "bits 32" without the brackets is also a macro. This is what you'd use - at the top of the file, typically - to tell Nasm to emit 32-bit code.

What you've got there is not a "directive", but an "attribute" or "property" of the "section"/"segment" (also aliases) directive. In this case, "bits 32" isn't going to do anything. The "alias" can be seen in "standard.mac" - it defines "use32" as "[bits 32]", not the other way around...

"use32" was made an "alias" for convenience, but in this case, it only causes confusion...

If you look in the manual under "output formats", "extensions to the segment directive", instead of in the "directives" section, "bits", etc., you'll see the difference.

By rights, Nasm should complain about "section foo bits 32"... apparently it doesn't... ("progbits"/"nobits" *are* valid...)

FWIW, you may also want to add "class=code" to your ".code" section. I don't know what it does, but Ollydbg, at least, is happier when you do it.

"-f win32" is the more "modern" way to make a Windows file (yeah, I know it doesn't know "import"...) "-f obj" will work, but since it defaults to 16-bit, there are some extra hoops to jump through.

In this case, "well, don't change it" is the correct answer.

Best,
Frank