0
我試圖將一個數組的偶數內容複製到另一個數組。我的代碼運行沒有問題,但從數組打印的值是000000而不是數組的值。陣列MIPS
我的目標是將array0的偶數複製到array1並將它們打印到屏幕上。
我的代碼:
.data
array0: .word 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
length: .word 10
array1: .space 20
nl: .asciiz ""
label: .asciiz "Values: "
.text
.globl main
main:
lw $t2, length
move $t0, $zero
move $t1, $zero
move $t2, $zero
move $t3, $zero
la $a0, label
li $v0, 4
syscall
start:
lw $t5, array0($t0)
andi $t4, $t5, 1
beq $t4, 0, even
addi $t1, $t1, 1
addi, $t0, $t0, 4
blt $t1, $t2, start
j end
even:
sw $t5, array1($t3)
addi $t1, $t1, 1
addi $t0, $t0, 4
addi $t3, $t3, 4
blt $t1, $t2, start
end:
lw $a0, array1($t6)
li $v0, 1
syscall
la $a0, nl
la $v0, 4
syscall
addi $t6, $t6, 4
bne $t6, 20, end
li $v0, 10
syscall
.end main
您將'length'加載到'$ t2',然後通過'$ zero'覆蓋'$ t2'。你確定這是你想要做的嗎? – MikeCAT