After playing a lot with ARM assembly I am starting to code a bit in x86 Assembly (especifically Linux NASM, so the AT&T syntax). Below you’ll find three basic programs to print “Hello World” and variations.
1. Using Syscall Write
.text
.globl main
main:
movl $4, %eax
movl $1, %ebx
movl $string1,%ecx
movl $20, %edx
int $0x80
.data
string1: .string "hello worldn"
2. Using Printf
.text
.globl main
.extern printf
main:
pushl $string1
call printf
popl %ebx
movl $0, %eax
ret
.data
string1: .string "hello worldn"
3. Using Printf with Variables
.text
.globl main
.extern printf
main:
movl $23, %ebx
pushl %ebx
pushl $string1
call printf
addl $8, %esp
movl $0, %eax
ret
.data
string1: .string "hello %d worldn"