arm assembly collatz conjecture
/*
* collatz.s
* Computes the collatz conjecture of n
*/
.syntax unified
.global _start
_start:
mov r0, 0
mov r1, 6 @n = 6
loop:
cmp r1, 1
ble _exit
and r2, r1, 1
cmp r2, 1
beq odd
bne even
even:
mov r1, r1, ASR 1 @ r1/2
add r0, r0, 1
bal loop
odd:
mov r3, 3
mul r1, r3 @ r1 * 3
add r1, r1, 1 @ r1 + 1
add r0, r0, 1
bal loop
_exit:
mov r7, 1
swi 0