From 172d735728892d3d000642a8de1ceb33c36c7be9 Mon Sep 17 00:00:00 2001 From: "exercism-solutions-syncer[bot]" <211797793+exercism-solutions-syncer[bot]@users.noreply.github.com> Date: Tue, 25 Nov 2025 11:23:12 +0000 Subject: [PATCH] [Sync Iteration] arm64-assembly/collatz-conjecture/1 --- .../collatz-conjecture/1/collatz_conjecture.s | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 solutions/arm64-assembly/collatz-conjecture/1/collatz_conjecture.s diff --git a/solutions/arm64-assembly/collatz-conjecture/1/collatz_conjecture.s b/solutions/arm64-assembly/collatz-conjecture/1/collatz_conjecture.s new file mode 100644 index 0000000..85b1b46 --- /dev/null +++ b/solutions/arm64-assembly/collatz-conjecture/1/collatz_conjecture.s @@ -0,0 +1,50 @@ +// collatz_conjecture.s + +// Implements Collatz conjecture + +.equ ERROR_INVALID_NUMBER, -1 +.equ INVALID, 0 +.equ COUNTER_INIT, 0 +.equ BASE_CASE, 1 +.equ DIVISION_BASE, 1 +.equ INCREMENT, 1 +.equ IS_EVEN, 1 +.equ FACTOR, 3 + +.global steps +steps: + // x0 has the number (16) + // x1 will be the step counter + cmp x0, #INVALID // is it 0? + ble error // exits + + mov x1, #COUNTER_INIT // counter = 0 + +loop: + cmp x0, #BASE_CASE // compares x0 to 1 + beq done // when equal, exits loop + + tst x0, #IS_EVEN // is it even? + beq even // if so, go to division + + mov x2, #FACTOR // stores the factor 3 + mul x0, x0, x2 // multiplies + add x0, x0, #INCREMENT // adds 1 + + add x1, x1, #INCREMENT // counter++ + b loop // returns to loop + +even: + asr x0, x0, #DIVISION_BASE // divides by 2 + + add x1, x1, #INCREMENT // counter++ + b loop // returns to loop + +done: + mov x0, x1 // returns counter + ret // farewell + +error: + mov x0, #ERROR_INVALID_NUMBER // error message + ret // bye +