BullyWiiPlaza
BullyWiiPlaza

Reputation: 19225

Assembling 64-bit instructions to raw machine code with nasm

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.

Upvotes: 8

Views: 7396

Answers (1)

BullyWiiPlaza
BullyWiiPlaza

Reputation: 19225

Adding BITS 64 to the top of the assembly source file did the trick.

Upvotes: 9

Related Questions