Assembly 基本MIPS代码未按预期工作

Assembly 基本MIPS代码未按预期工作,assembly,mips,mips32,Assembly,Mips,Mips32,您好,基本上我希望我的程序将整数从内存地址$a0复制到内存地址$a1,直到它读取零值为止。不应复制零值。复制的整数数应存储在$v0中。有人能告诉我为什么这不起作用,我可能出了什么问题吗?干杯。这里的问题是,您将指针$a0和$a1前进了1,但单词的长度是4字节 改为: .data source: .word 3, 1, 4, 1, 5, 9, 0 dest: .word 0, 0, 0, 0, 0, 0, 0 countmsg: .asciiz " values copied. " .

您好,基本上我希望我的程序将整数从内存地址$a0复制到内存地址$a1,直到它读取零值为止。不应复制零值。复制的整数数应存储在$v0中。有人能告诉我为什么这不起作用,我可能出了什么问题吗?干杯。

这里的问题是,您将指针$a0和$a1前进了1,但单词的长度是4字节

改为:

.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向前推进1,但一个字的长度是4字节

改为:

.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 

那么什么不起作用呢?当你在这里寻求帮助时,请准确地说出你的代码出了什么问题:例如,“我得到了这个错误消息”或“我得到了一个不正确的结果”。对不起,错误是“错误:无效的程序计数器值:0”。那么什么不起作用呢?当你在这里寻求帮助时,请准确说出您的代码出了什么问题:例如,“我收到了此错误消息”或“我得到了一个不正确的结果”。很抱歉,错误为“错误输入:无效的程序计数器值:0”