From 574da511ec42932e189580314bf85a2a840d4379 Mon Sep 17 00:00:00 2001 From: Nicholas Date: Thu, 31 Oct 2024 12:58:53 -0400 Subject: [PATCH] Initial --- collaz.s | 54 ++++++++++++++++++++++++++++++++++++++++++++ hw.s | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 collaz.s create mode 100644 hw.s diff --git a/collaz.s b/collaz.s new file mode 100644 index 0000000..4bc3bc6 --- /dev/null +++ b/collaz.s @@ -0,0 +1,54 @@ +# COS235 - HW2 +# Nicholas Pease +# 1 OCT 2024 + +.data +inputUInt: .space 32 + +.text +main: + li a7, 5 # input unsigned int + la a0, inputUInt + ecall + + mv s2, a0 + + li a7, 1 # display input int + ecall + + li a7, 11 + li a0, 0x0a + ecall # newline + + li s3, 2 + li s4, 0 + li s5, 3 + li s6, 1 + whileLoop: + ble s2, s6, endLoop # end loop if less than 1 + remu t3,s2,s3 # t3 = t4(int) % 2 remainder + + bne t3, s4, odd + + even: + srl s2, s2,s6 + #divu s2, s2, s3 + j end + + odd: + mul s2, s2, s5 + add s2, s2, s6 + + end: + li a7, 1 + mv a0, s2 + ecall + li a7, 11 + li a0, 0x0a + ecall + + j whileLoop + + endLoop: + li a7, 10 + ecall \ No newline at end of file diff --git a/hw.s b/hw.s new file mode 100644 index 0000000..24a491f --- /dev/null +++ b/hw.s @@ -0,0 +1,68 @@ +# COS035 - HW3 +# Nicholas Pease +# 31 OCT 2024 +.data: +inputUInt: .space 32 + +.text: +main: + li a7, 5 # input unsigned int + la a0, inputUInt + ecall + + mv t0, a0 + jal hotpo_i # hotpo_i (non recursive) + + li a7, 11 + li a0, 0x0a + ecall # Newline + + li a7, 10 + ecall # Exit program + +# Collaz Conjecture (Iterative) +# t0: input int +# t1: 2 (divide by 2) +# t2: 0 (const) (compare if even [n / 2] remainder) +# t3: 3 (const) (odd multiply) +# t4: 1 (const) (odd add) +hotpo_i: + mv a0, t0 + li a7, 1 + ecall # Display input int + + li a7, 11 + li a0, 0x0a + ecall # Newline + + li t1, 2 + li t2, 0 + li t3, 3 + li t4, 1 + hotpoi_whileLoop: + ble t0, t4, hotpoi_endLoop # end loop if less than 1 + remu t5,t0,t1 # t5 = t0(int) % 2 remainder + + bne t5, t2, hotpoi_odd + + hotpoi_even: + srl t0, t0,t4 + #divu t0, t0, t1 + j hotpoi_end + + hotpoi_odd: + mul t0, t0, t3 + add t0, t0, t4 + + hotpoi_end: + li a7, 1 + mv a0, t0 + ecall + li a7, 11 + li a0, 0x0a + ecall + + j hotpoi_whileLoop + + hotpoi_endLoop: + ret \ No newline at end of file