Skip to content

Instantly share code, notes, and snippets.

@urish

urish/7-boom.asm Secret

Created May 26, 2017 07:33
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save urish/4151e0acdc315c6ee548ba6e9ee3a66e to your computer and use it in GitHub Desktop.
Save urish/4151e0acdc315c6ee548ba6e9ee3a66e to your computer and use it in GitHub Desktop.
.text
.globl _start
_start:
ldr %r0, =hello_message
mov %r1, #hello_message_len
bl _print
mov %r0, #199
push { %r0}
bl _boom
bl _newline
_mefareklemisparim:
pop {%r0}
cmp %r0, #0
beq _exit
sub %r0, %r0, #1
push {%r0}
bl _boom
bl _newline
b _mefareklemisparim
_exit:
mov %r0, #0 // exit status 0 (ok)
mov %r7, #1 // syscall 1 (exit)
swi #0
_boom: // prints the number in r0 if it does not divide by 7
push {%r0, %r1, %r2, %r3, %r14}
mov %r3, #7
udiv %r1, %r0, %r3
mul %r2, %r1, %r3
cmp %r0, %r2
beq _print_boom
blne _mispar
b _sof_boom
_print_boom:
ldr %r0, =boom_message
mov %r1, #boom_message_len
bl _print
_sof_boom:
pop {%r0, %r1, %r2, %r3, %r14}
bx %r14
_mispar: // prints the number in r0
push { %r1, %r2, %r3,%r4, %r14 }
mov %r4, #0
_HOZERHALILA:
cmp %r0, #10
blt _sifra_ahrona
// r0 < 10 - then print r0
// r0 > 10 - divide by 10
// print remainder
// repeat
mov %r3, #10
udiv %r1, %r0, %r3
mul %r2, %r1, %r3
sub %r0, %r0, %r2
push {%r0}
add %r4, %r4, #1
mov %r0, %r1
b _HOZERHALILA
_sifra_ahrona:
bl _sifra
_losiamnu:
cmp %r4, #0
beq _sofsof
pop { %r0 }
bl _sifra
sub %r4, %r4, #1
b _losiamnu
_sofsof:
pop { %r1, %r2,%r3,%r4, %r14 }
bx %r14
_sifra: // prints the digit in r0
push { %r1, %r14 }
ldr %r1, =message
add %r1, %r1, %r0
mov %r0, %r1
mov %r1, #1
bl _print
pop { %r1, %r14 }
bx %r14
_newline:
push { %r0, %r1, %r14}
ldr %r0, =kfotzli
mov %r1, #1
bl _print
pop { %r0, %r1, %r14}
bx %r14
_print: // prints the text in r0, how many characters to print in r1
push { %r0, %r1, %r2, %r7 }
mov %r2, %r1 // length
mov %r1, %r0 // what to print
mov %r0, #1 // fd 1 (stdout)
mov %r7, #4 // syscall 4 (write)
swi #0
pop { %r0, %r1, %r2, %r7 }
bx %r14
.data
hello_message: .ascii "7-BOOM by Ariella Eliassaf & Uri Shaked\n\n"
hello_message_len = . - hello_message
kfotzli:
.ascii "\n"
boom_message:
.ascii "BOOM"
boom_message_len = . - boom_message
message:
.ascii "0123456789"
message_len = . - message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment