Skip to content

Instantly share code, notes, and snippets.

@codekittie
Created December 6, 2020 05:57
Show Gist options
  • Save codekittie/1642709c87e40d059a92008c1186ae18 to your computer and use it in GitHub Desktop.
Save codekittie/1642709c87e40d059a92008c1186ae18 to your computer and use it in GitHub Desktop.
Khety's first sola C assembly mixin
global main
extern printf
section .text
main:
mov rax, 1 ; start current number as 1 in rax
mov r8, 5 ; move counter into r8
loop: ; add a label to jump to
push rax
push r8
xor rax, rax
mov rdi, format
mov rsi, [rsp+8] ; set up print
call printf ; print the current number
pop r8
pop rax ; restore registers
inc rax ; add 1 to rax
dec r8 ; subtract 1 from r8
cmp r8, 0 ; compare r8 to 0
jne loop ; if compare is not equal to zero jump to label
mov rax, 60
mov rdi, 0
syscall ; exit
section .data
format: db "%ld", 10, 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment