I want to assemble 64-bit
assembly instructions into raw machine code using nasm
. If I do, I get an error:
error: instruction not supported in 16-bit mode
Example input:
mov rax, 0x12345678
Example command:
$ nasm input.s -o output
By default, nasm
uses the bin output format which assumes 16-bit
. All the other options seem to support 64-bit
but only when generating full executes/object files and not when generating just the raw machine code.
Is there a way to use the binary format but with 64-bit
instead?
I found another way of accomplishing this task using the GNU assembler
but I was wondering if you could do the same thing in nasm
as well.
x64 is a generic name for the 64-bit extensions to Intel‟s and AMD‟s 32-bit x86 instruction set architecture (ISA). AMD introduced the first version of x64, initially called x86-64 and later renamed AMD64. Intel named their implementation IA-32e and then EMT64.
The Netwide Assembler (NASM) is an assembler and disassembler for the Intel x86 architecture. It can be used to write 16-bit, 32-bit (IA-32) and 64-bit (x86-64) programs. It is considered one of the most popular assemblers for Linux.
Adding BITS 64
to the top of the assembly source file did the trick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With