Skip to content

Instantly share code, notes, and snippets.

@gandaro
Created March 3, 2012 15:55
Show Gist options
  • Save gandaro/1966795 to your computer and use it in GitHub Desktop.
Save gandaro/1966795 to your computer and use it in GitHub Desktop.
“Hello world” written using AT&T assembly
.data
hello:
.string "Hello world!\n"
.text
.globl _start
_start:
movl $4, %eax # write(1, hello, strlen(hello))
movl $1, %ebx
movl $hello, %ecx
movl $13, %edx
int $0x80
movl $1, %eax # exit(0)
movl $0, %ebx
int $0x80
@xatja
Copy link

xatja commented Mar 25, 2022

You need to move 14 to edx to include the newline.

@7etsuo
Copy link

7etsuo commented Sep 21, 2022

You need to move 14 to edx to include the newline.

This is better than counting with your fingers.

hello:
    .string "Hello world!\n"
hello_end: 
   .equ len, hello - hello_end
.text
.globl _start 
_start:
        movq $1, %rax
        movq $1, %rdi 
        movq $string, %rsi
        movq $len, %rdx
        syscall
        movq $60, %rax
        movq $0, %rdi
        syscall

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment