diff --git a/cos235-hw01-pease-nicholas-0001.tgz b/cos235-hw01-pease-nicholas-0001.tgz new file mode 100644 index 0000000..872c015 Binary files /dev/null and b/cos235-hw01-pease-nicholas-0001.tgz differ diff --git a/cos235-hw04-pease-nicholas-0001.tgz b/cos235-hw04-pease-nicholas-0001.tgz new file mode 100644 index 0000000..b0082fb Binary files /dev/null and b/cos235-hw04-pease-nicholas-0001.tgz differ diff --git a/cos235-hw04-pease-nicholas-0001/README b/cos235-hw04-pease-nicholas-0001/README new file mode 100644 index 0000000..b7c5e3e --- /dev/null +++ b/cos235-hw04-pease-nicholas-0001/README @@ -0,0 +1,17 @@ +COS235 HW4 +Nicholas Pease +15 NOV 2024 + + +Description: + +This is a program that executes a recursive program to display some dots and ints on a screen. + +Execution: + +This program requires RARS (https://github.com/TheThirdOne/rars) and JDK. + +To execute the program with RARS, run the following command +java -jar rars1_6.jar hw.s + +With rars1_6 being the current version of RARS and in the same directory as the file \ No newline at end of file diff --git a/hw1.s b/cos235-hw04-pease-nicholas-0001/hw.s similarity index 77% rename from hw1.s rename to cos235-hw04-pease-nicholas-0001/hw.s index b6b6fc0..b68b29e 100644 --- a/hw1.s +++ b/cos235-hw04-pease-nicholas-0001/hw.s @@ -1,3 +1,4 @@ +# COS235- HW4 # Nicholas Pease # 31 OCT 2024 .data: @@ -7,22 +8,34 @@ .text: main: li a7, 5 # input unsigned int (A) + la a0, inputUInt ecall mv a1, a0 # a1 = A li a7, 5 # input unsigned int (B) + la a0, inputUInt ecall - mv a2, a0 # a2 = B + mv a2, a0 + # a2 = B # CALL RECURSIVE FUNCTION - jal ra, kapow + jal kapow + jal kapow # PRINT RETURN VALUE - mv a0, a0 + li a7, 34 + ecall + + mv t0, a0 + li a0, 9 + li a7, 11 + ecall + mv a0, t0 + li a7, 1 ecall - jal ra, newline + jal newline li a7, 10 ecall # Exit program @@ -52,33 +65,36 @@ kapow: bne t0,a2,kapow_forLoop # END FOR LOOP + li a0, 32 + li a7, 11 + ecall + li a7, 1 # print int mv a0, a2 # print Y ecall - jal ra, newline # print newline + jal newline # print newline - li t0, 1 - blt t0, a2, kapow_gt1 # if Y > 1, jump + li a0, 1 + blt a0, a2, kapow_gt1 # if Y > 1, jump blt zero, a2, kapow_gt0 # if Y > 0, jump # others y < 0 - li a0, 1 j kapow_return kapow_gt0: - mv a0, a1 + mv a0, a1 # return X j kapow_return kapow_gt1: li t0, 2 div a2,a2,t0 # Y = Y / 2 - jal ra, kapow # recursive call + jal kapow # recursive call mv a3, a0 # a3 = first return value lw t1, 0(sp) # load original Y (t1) li t0, 2 # remainder number (t0) rem t0,t1,t0 # t0 = Y (t1) % 2 (t0) add a2, t0, a2# Y = prevY + y%2 - jal ra, kapow + jal kapow mul a0, a3, a0 # return = x * y kapow_return: diff --git a/hw.s b/hw.s index 5ad4b3a..b68b29e 100644 --- a/hw.s +++ b/hw.s @@ -20,8 +20,18 @@ main: # CALL RECURSIVE FUNCTION jal kapow + jal kapow # PRINT RETURN VALUE + li a7, 34 + ecall + + mv t0, a0 + li a0, 9 + li a7, 11 + ecall + mv a0, t0 + li a7, 1 ecall @@ -55,6 +65,10 @@ kapow: bne t0,a2,kapow_forLoop # END FOR LOOP + li a0, 32 + li a7, 11 + ecall + li a7, 1 # print int mv a0, a2 # print Y ecall diff --git a/input b/input index 451c1a5..35658e7 100644 --- a/input +++ b/input @@ -1,2 +1,2 @@ -2 -2 \ No newline at end of file +15 +15 \ No newline at end of file