Skip to content

Instantly share code, notes, and snippets.

@aleph-naught2tog
Last active December 30, 2018 05:32
Show Gist options
  • Save aleph-naught2tog/13e87163b744373557ac5cbcec5d71c5 to your computer and use it in GitHub Desktop.
Save aleph-naught2tog/13e87163b744373557ac5cbcec5d71c5 to your computer and use it in GitHub Desktop.
Assembler
# hello_asm.s
# as hello_asm.s -o hello_asm.o
# ld hello_asm.o -e _main -o hello_asm -macosx_version_min 10.6 -lSystem
.section __DATA,__data
str:
.asciz "Hello world!\n"
.section __TEXT,__text
.globl _main
_main:
# src, dest
# 4 = syswrite => %eax register
# here, %eax = what to call
# this is the opcode
movl $0x2000004, %eax
# 1 = stdout => %edi register
# here, %edi = where to call/first arg? ish?
movl $1, %edi
# afaik, rsi, rdx, etc are registers for our variables?
# GOT references the Global Offset Table
# aka, where the string above is stored.
# %rip = instruction pointer (accesses the GOT)
# aka, grab the value at that spot
# and put it into %rsi
movq str@GOTPCREL(%rip), %rsi
# the length of the value to print -- 100? apparently
# and put it into %rdx
movq $100, %rdx
# and make the call
# this calls whatever is in %eax, I think
syscall
# === finish up ===
# put 0 in as our exit code/return value
movl $0, %edi
# and exit (opcode 1 => exit)
movl $0x2000001, %eax
syscall
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment