.data
source: .word 3, 1, 4, 1, 5, 9, 0
dest: .word 0, 0, 0, 0, 0, 0, 0
countmsg: .asciiz " values copied. "
.text
main: add $s0, $0, $ra # Save our return address
la $a0, source
la $a1, dest
loop: lw $v1, 0($a0) # read next word from source
addi $v0, $v0,1 # increment count words copied
sw $v1, 0($a1) # write to destination
addi $a0, $a0,1 # advance pointer to next source
addi $a1, $a1,1 # advance pointer to next dest
bne $v1, $zero, loop # loop if word copied not zero
loopend:
move $a0, $v0 # We want to print the count
li $v0, 1
syscall # Print it
la $a0, countmsg # We want to print the count message
li $v0, 4
syscall # Print it
li $a0, 0x0A # We want to print '\n'
li $v0, 11
syscall # Print it
jr $s0 # Return from main. We stored $ra in $s0
你好,基本上我希望我的程序将整数从内存地址 $a0 复制到内存地址 $a1,直到它读取零值。不应复制零值。复制的整数个数应存储在 $v0 中。有人可以告诉我为什么这不起作用以及我可能出错的地方吗?干杯。