Skip to content

Instantly share code, notes, and snippets.

@JnCrMx
Created March 22, 2021 09:59
Show Gist options
  • Save JnCrMx/71fbb34361cfbe06c0c1df67026724a9 to your computer and use it in GitHub Desktop.
Save JnCrMx/71fbb34361cfbe06c0c1df67026724a9 to your computer and use it in GitHub Desktop.
Weird Assembly program to print the numbers from 1 to 100.
section .text
global _start
print:
xor rax, rax
inc rax
xor rdi, rdi
xor rdx, rdx
inc rdx
inc rdx
inc rdx
inc rdx
syscall
ret
_start:
xor rax, rax
xor rbx, rbx
inc rax
inc rax
inc rax
mov rcx, rax
inc rax
shl rax, cl
dec rsp
mov [rsp], rax
xor rax, rax
inc rax
inc rax
inc rax
mov rcx, rax
inc rcx
shl rax, cl
mov cl, al
mov ch, al
dec rsp
mov [rsp], cl
dec rsp
mov [rsp], cl
dec rsp
mov [rsp], cl
inc cl
inc cl
inc cl
inc cl
inc cl
inc cl
inc cl
inc cl
inc cl
inc cl
mov rsi, rsp
dec rsp
mov [rsp], cl
dec rsp
mov [rsp], ch
loop:
mov ch, [rsp]
inc rsp
mov cl, [rsp]
inc rsp
inc rsp
inc rsp
mov al, [rsp]
inc al
mov [rsp], al
cmp al, cl
jne next
mov [rsp], ch
dec rsp
mov al, [rsp]
inc al
mov [rsp], al
inc rsp
cmp al, cl
jne next
dec rsp
mov [rsp], ch
dec rsp
mov al, [rsp]
inc al
mov [rsp], al
inc rsp
inc rsp
jmp last
next:
dec rsp
dec rsp
dec rsp
dec rsp
call print
jmp loop
last:
dec rsp
dec rsp
dec rsp
dec rsp
call print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment