Skip to content

Instantly share code, notes, and snippets.


urish/7-boom.asm Secret

Created May 26, 2017
What would you like to do?
.globl _start
ldr %r0, =hello_message
mov %r1, #hello_message_len
bl _print
mov %r0, #199
push { %r0}
bl _boom
bl _newline
pop {%r0}
cmp %r0, #0
beq _exit
sub %r0, %r0, #1
push {%r0}
bl _boom
bl _newline
b _mefareklemisparim
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
ldr %r0, =boom_message
mov %r1, #boom_message_len
bl _print
pop {%r0, %r1, %r2, %r3, %r14}
bx %r14
_mispar: // prints the number in r0
push { %r1, %r2, %r3,%r4, %r14 }
mov %r4, #0
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
bl _sifra
cmp %r4, #0
beq _sofsof
pop { %r0 }
bl _sifra
sub %r4, %r4, #1
b _losiamnu
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
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
hello_message: .ascii "7-BOOM by Ariella Eliassaf & Uri Shaked\n\n"
hello_message_len = . - hello_message
.ascii "\n"
.ascii "BOOM"
boom_message_len = . - boom_message
.ascii "0123456789"
message_len = . - message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment