diff --git a/1/homework/exp1/exp1_2.asm b/1/homework/exp1/exp1_2.asm new file mode 100644 index 0000000..a07ab41 --- /dev/null +++ b/1/homework/exp1/exp1_2.asm @@ -0,0 +1,26 @@ +.data +.text +li $v0, 5 # read in i +syscall +move $s1, $v0 # use s1 to store i + +li $v0, 5 # read in j +syscall +move $s2, $v0 # use s2 to store j + +sub $s1, $zero, $s1 # i = -i + +bgez $s2, no_neg_j # if >= 0, then no neg +sub $s2, $zero, $s2 # j = -j + +no_neg_j: move $s0, $zero # use s0 as temp, temp = 0 +count_up_j: bge $s0, $s2, done_count_up # if temp >= j, stop iteration +addi $s1, $s1, 1 # i = i + 1 +addi $s0, $s0, 1 # ++temp +j count_up_j + +done_count_up: move $a0, $s1 +li $v0 1 +syscall + +move $v0, $s1 # set return value \ No newline at end of file