I am writing a hello world program for linux x86_64 using GAS assembler and here is my code in AT&T syntax.
#.intel_syntax noprefix
.section .data
msg:
.ascii "hello world\n"
.section .text
.globl _start
_start:
movq $1, %rax
movq $1, %rdi
movq $msg, %rsi
movq $12, %rdx
syscall
movq $60, %rax
movq $0, %rdi
syscall
This works and prints "hello world". Here is intel syntax:
.intel_syntax noprefix
.section .data
msg:
.ascii "hello world\n"
.section .text
.globl _start
_start:
mov rax, 1
mov rdi, 1
mov rsi, msg
mov rdx, 12
syscall
mov rax, 60
mov rdi, 0
syscall
This compiles and runs fine but does not print "hello world". I am assuming the mistake is in mov rsi, msg
? If so, what is the correct syntax?
Try mov rsi, offset msg
. gas uses a masm-like syntax where mov rsi, msg
moves the content of msg
to rsi
instead of moving the address. The offset
keyword has to be used to avoid this issue.
If you want to program in Intel syntax, I advise you to pick a better assembler like nasm.
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