This commit is contained in:
2024-10-31 12:58:53 -04:00
parent 070bf714c6
commit 574da511ec
2 changed files with 122 additions and 0 deletions
+54
View File
@@ -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
+68
View File
@@ -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