Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save HouzuoGuo/67f926e159767bc6e414f13de6c97008 to your computer and use it in GitHub Desktop.
Save HouzuoGuo/67f926e159767bc6e414f13de6c97008 to your computer and use it in GitHub Desktop.
section .text
global _start
_start:
push 1
push 2
call add2 ; rax = add2(1, 2)
push 3
push 4
call add2 ; rax = add2(3, 4)
jmp .exit
.exit:
mov rax, 60 ; syscall 60 is exit
mov rdi, 1 ; exit code is 1
syscall
# rax = add2(i1, i2), the function demonstrates local variable usage as well.
add2:
push rbp
mov rbp, rsp
mov rax, [rbp+16] ; int64 i1
mov rdx, [rbp+16+8] ; int64 i2
sub rsp, 8 ; int64 localA
sub rsp, 8 ; int64 localB
push rdx ; localB = i2
push rax ; localA = i1
add rax, rdx ; i1 += i2
; return rax(i.e. i1)
mov rsp, rbp
pop rbp
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment