Any x86-64 Linux assembler?

7,216

Solution 1

There are quite a few assemblers available, including:

  • gas (part of binutils, and supported by GCC) — this is available everywhere, and uses AT&T style;
  • NASM (look for a nasm package in your distribution) — this supports Intel-style mnemonics;
  • Yasm which is a rewrite of NASM (look for a yasm package).

Here's a “Hello world” for gas:

    .global _start

    .text
_start:
    mov     $1, %rax
    mov     $1, %rdi
    mov     $hello, %rsi
    mov     $13, %rdx
    syscall

    mov     $60, %rax
    xor     %rdi, %rdi
    syscall

hello:
    .ascii  "Hello, world\n"

Save this to hello.S, and build it using gcc -c hello.S && ld -o hello hello.o.

The equivalent for NASM is:

    section .text
    global  _start

_start:
    mov     rax, 1
    mov     rdi, 1
    mov     rsi, hello
    mov     rdx, len
    syscall

    mov     rax, 60
    xor     rdi, rdi
    syscall

    hello   db "Hello, world",0x0A
    len     equ $ - hello

Save this as hello.asm, and build it using nasm -felf64 hello.asm && ld -o hello hello.o.

Solution 2

NASM is a good assembler for Linux/Unix. You can find plenty of examples from google for NASM 64-bit code.

For Centos you can install NASM with:

yum install nasm -y

For debian/ubuntu it's probably:

apt-get install nasm
Share:
7,216

Related videos on Youtube

user30167
Author by

user30167

Updated on September 18, 2022

Comments

  • user30167
    user30167 over 1 year

    I want to start learning assembly language, but all the googling didn't make any sense. I got some Exec format error and even used wine which is not good for understanding. So I wonder if anyone can tell what command line assembler will do on x86-64 architecture and probably some hello world example for Linux?