Skip to content

Instantly share code, notes, and snippets.

@cedriczirtacic
Last active August 25, 2017 20:49
Show Gist options
  • Save cedriczirtacic/edbfd072b84a695557f0a50d12f21f4f to your computer and use it in GitHub Desktop.
Save cedriczirtacic/edbfd072b84a695557f0a50d12f21f4f to your computer and use it in GitHub Desktop.
assembly rot13()
//as -o rot13.o rot13.S && ld -o rot13 rot13.o
.section .data
string:
.asciz "Hello World.\n"
.section .text
.global _start
_start:
leaq string, %rdi
call rot13
xorq %rdi, %rdi
xorq %rax, %rax
movb $60, %al
movb $0, %dil
syscall
rot13:
push %rbp
movq %rsp, %rbp
movq %rdi, -8(%rbp)
movq -8(%rbp), %rbx
.L01:
cmpb $0, (%rbx)
je .L02
cmpb $'A', (%rbx)
jb .L03
cmpb $'z', (%rbx)
ja .L03
cmpb $'a', (%rbx)
jae .LOWERCASE
.UPPERCASE:
addb $0x0d, (%rbx)
cmpb $'Z', (%rbx)
jbe .L03
subb $0x1a, (%rbx)
jmp .L03
.LOWERCASE:
addb $0x0d, (%rbx)
cmpb $'z', (%rbx)
jbe .L03
subb $0x1a, (%rbx)
.L03:
addq $1, %rbx
jmp .L01
.L02:
movq $0, %rax
leave
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment