Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assembling 64-bit instructions to raw machine code with nasm

Tags:

intel

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.

like image 739
BullyWiiPlaza Avatar asked Apr 20 '20 08:04

BullyWiiPlaza


People also ask

What is x64 assembly?

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.

Is nasm an assembly language?

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.


1 Answers

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

like image 67
BullyWiiPlaza Avatar answered Sep 28 '22 04:09

BullyWiiPlaza