table: .word 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
.word 11, 12, 13, 14, 15, 16, 17, 18, 19, 20
.word 21, 22, 23, 24, 25, 26, 27, 28, 29, 30
.word 31, 32, 33, 34, 35, 36, 37, 38, 39, 40
.word 41, 42, 43, 44, 45, 46, 47, 48, 49, 50
.word 51, 52, 53, 54, 55, 56, 57, 58, 59, 60
.word 61, 62, 63, 64, 65, 66, 67, 68, 69, 70
.word 71, 72, 73, 74, 75, 76, 77, 78, 79, 80
.word 81, 82, 83, 84, 85, 86, 87, 88, 89, 90
.word 91, 92, 93, 94, 95, 96, 97, 98, 99, 100
print_str("Enter a column number to print (0-9): ")
li $v0, 5
syscall
move $t0, $v0 # set initial row $t0 to inuput
move $t1, $zero # set initial col $t1 to 0
li $t4, 4 # set size $t4 to wordsize = 4
li $t3, 10 # set col size $t3 to 10
loopTwo:
bge $t1, 10, main
mul $t2, $t0, $t3
add $t2, $t2, $t1
mul $t2, $t2, $t4
lw $a0, table($t2)
li $v0, 1
syscall
li $a0, 32
li $v0, 11
syscall
addi $t1, $t1, 1
j loopTwo
我有它用于打印2d阵列的行。我只需要帮助弄清楚如何制作它,就可以打印出数组的一列。
例如输入:0输出1,11,21,31,41,51,61,71,81,91
print_str("Enter a row number to print (0-9): ")
li $v0, 5
syscall
move $t1, $v0 # set initial row $t1 to inuput
move $t0, $zero # set initial col $t0 to 0
li $t4, 4 # set size $t4 to wordsize = 4
li $t3, 10 # set col size $t3 to 10
loopTwo:
bge $t0, 10, main
mul $t2, $t0, $t3
add $t2, $t2, $t1
mul $t2, $t2, $t4
lw $a0, table($t2)
li $v0, 1
syscall
li $a0, 32
li $v0, 11
syscall
addi $t0, $t0, 1
j loopTwo
这使它起作用