NASM - The Netwide Assembler
NASM Forum => Programming with NASM => Topic started by: Snake38 on July 29, 2014, 06:44:57 PM
-
Hello, I'm new on forum but not new to assembly.
I'm just curious why NASM don't allow to mix 32/64 bits code? I mean if we write
; [...] some 32bit code [...]
bits 64
; [...] some 64bit code [...]
compiling with nasm -f win32 file.asm returns file.asm:3: error: win32 output format does not support 64-bit code.
Other assemblers let us do this and sometimes it's helpful. It's not so hard to change it for yourself but I don't want to change it every new version. Does that makes problems for somebody?
-
Well for one you are compiling using win32 if you used win64 maybe that will change things??? I would try that before anything else I use linux so for me I would use elf or elf64 and mixing code works just fine for me I might be wrong but that's how I would do it.
-
I see in nasm.c:90 is defined global int maxbits = 0;. Some of the output formats seems to be changing this to 64 like (filenames) outbin.c, outcoff.c, outelf64.c, outelf32x.c. In the nasm.c:2099 static int get_bits(char *value); there is the check if passed argument (to the bits statement) is not equal to maxbits and if so return error. So for win32 format giving bits 64 it checks if (64 != 0) { // error: [...] not support 64-bit code }.
-
Mhmm Then that must mean that doing something like nasm -f Win64 File.asm should work because it has a max bits check so it can have from 8 to 64 bit code.
-
But then executable is 64bit not 32 and that's what I need. On windows if you have 32bit executable you can run it on 64bit system.
-
Well thats not always true you can link it using go link here is some information regarding that: http://www.godevtool.com/GolinkHelp/GoLink.htm
-
GoLink automatically senses whether it is being given 32-bit or 64-bit input files and produces a 32-bit or 64-bit executable accordingly. No command line switching is needed. Because you cannot mix 32-bit and 64-bit code, GoLink will show an error if you try to mix these input files.
If I compile as win64 and link with GoLink I get 64bit executable.
-
Oh are you using a 32 bit machine??? If that's the case 64 bit code won't work at all. At least I don't think it's possible
-
No, I use 64 bit.
-
Then it should work with the 64 bit executable
-
It works with 64 bit executable but that's not my goal.
I want to generate 32 bit executable with some 64 bit code (I can make another file, compile and then embed generated binary data in the first one but that's not the goal). Just one thing is to "force" compiler to accept that theoretically wrong code.
-
Oh well I don't think I can help you there I really don't think it is possible but maybe I am wrong
-
Other assemblers let us do this...
Use the other assemblers then. I can't imagine that such a thing would possibly work (the thing is either in long mode or it's in compatibility mode). If other assemblers will do this, go for it!
(As you apparently know, "incbin" would let you do this in Nasm, if you really insist...)
Best,
Frank
-
What you can't imagine? Generating opcodes from 64 bit code and not looking on specified target bits? Just check forked version of NASM.
I use linux so for me I would use elf or elf64 and mixing code works just fine for me I might be wrong but that's how I would do it.
Why then allow this for other platforms?
-
I thought you were talking about generating a 64 bit executable not a 32 bit one when I said that and putting the elf in their was a mistake for mixing code I would only use elf64
-
But if you do that it works, you choose elfx32 and it allows you to do so. For windows there is no winx32.
-
I Honestly did not know that I never would actually try it myself using a 64 bit executable on a 64 bit machine seems like the ideal thing to do why then try to trick the compiler into doing something it's not supposed to do anyway???
-
Nevermind. Frank looks like he have no idea how this works = it's usless and not possible.
Will check for other solution.
-
Frank did say that you could use inc bin if you really wanted to assemble it as a binary then make a new file and do this
incbin "Somefile.bin"
then use nasm -f win32 File.asm