exercise review vod

This commit is contained in:
2025-08-03 01:22:44 -04:00
parent e54e352a6e
commit 4c7d454690
3 changed files with 17 additions and 13 deletions
+10 -6
View File
@@ -20,7 +20,8 @@ add_u equ add ; dst_reg, reg_a, reg_b (unsigned)
add_si equ addi ; dst_reg, src_reg, immediate value (signed)
add_ui equ addiu ; dst_reg, src_reg, immediate value (unsigned)
; Branch
branch_equal equ beq ; reg, value(reg, immediate), dst_label
branch_equal equ beq ; reg, value(reg, immediate), dst_label
branch_lt_equal equ ble ; reg, value(reg, immediate), dst_label
; Registers
; Temporaries, may be changed by subroutines
@@ -36,12 +37,15 @@ main:
; Attempt:
load_imm rtemp_0, 1
load_imm rtemp_1, 0
; load_imm rtemp_1, 0
move rtemp_1, $zero
loop:
add_s rtemp_1, rtemp_1, rtemp_0
add_si rtemp_0, rtemp_0, 1
branch_equal rtemp_0, 10, end
add_s rtemp_1, rtemp_1, rtemp_0
add_si rtemp_0, rtemp_0, 1
branch_lt_equal rtemp_0, 10, loop
nop
j loop
; branch_equal rtemp_0, 10, end
; nop
; j loop
end:
.close
+4 -4
View File
@@ -56,13 +56,13 @@ main:
; 5. Subtract $t0-$t1 and store it back into $t0
; 6. Increment $t2
; 7. }
; Attempt:
move rtemp_2, $zero
load_imm rtemp_0, 27
load_imm rtemp_1, 3
load_imm rtemp_2, 0
// load_imm rtemp_2, 0
loop: :: branch_lt rtemp_0, rtemp_1, loop_break :: nop ; loop if < rtemp_0, rtemp_1 {
sub_s rtemp_0, rtemp_0, rtemp_1 ; -= rtemp_0, rtemp_1
add_si rtemp_2, rtemp_2, 1 ; ++ rtemp_2
sub_s rtemp_0, rtemp_0, rtemp_1 ; -= rtemp_0, rtemp_1
add_si rtemp_2, rtemp_2, 1 ; ++ rtemp_2
j loop :: loop_break: ; }
.close
+3 -3
View File
@@ -32,7 +32,7 @@ function build-program { param(
write-host 'Done!'
pop-location
}
# build-program 'fillmem' 'fillmem'
# build-program 'warmup' 'exercise_1'
# build-program 'warmup' 'exercise_2'
build-program 'fillmem' 'fillmem'
build-program 'warmup' 'exercise_1'
build-program 'warmup' 'exercise_2'
build-program 'warmup' 'exercise_3'