gpt4 book ai didi

assembly - 这个 MIPS/QtSPIM While 循环代码有什么问题

转载 作者:行者123 更新时间:2023-12-04 06:10:40 25 4
gpt4 key购买 nike

程序以预期的输出运行,但出现以下错误

代码

.data

.text
.globl main
main:
addi $t0, $t0, 0 # i = 0
addi $t2, $0, 10 # n = 10
j WhileCond # goto WhileCond

WhileLoop:
li $v0, 1 # print_int
move $a0, $t0 # $a0 = i (print i)
addi $t0, $t0, 1
syscall

WhileCond:
blt $t0, $t2, WhileLoop # if i < 10 goto WhileLoop

j $ra

用户文本段
[00400000] 21080000  addi $8, $8, 0           ; 10: addi $t0, $t0, 0 # i = 0 
[00400004] 200a000a addi $10, $0, 10 ; 11: addi $t2, $0, 10 # n = 10
[00400008] 08100007 j 0x0040001c [WhileCond] ; 12: j WhileCond # goto WhileCond
[0040000c] 34020001 ori $2, $0, 1 ; 15: li $v0, 1 # print_int
[00400010] 00082021 addu $4, $0, $8 ; 16: move $a0, $t0 # $a0 = i (print i)
[00400014] 21080001 addi $8, $8, 1 ; 17: addi $t0, $t0, 1
[00400018] 0000000c syscall ; 18: syscall
[0040001c] 010a082a slt $1, $8, $10 ; 21: blt $t0, $t2, WhileLoop # if i
[00400020] 1420fffb bne $1, $0, -20 [WhileLoop-0x00400020]
[00400024] 03e00008 jr $31 ; 23: j $ra

错误
Exception occurred at PC=0x00000000
Bad address in text read: 0x00000000
Instruction references undefined symbol at 0x800001dc
[0x800001dc] 0x143a0000 bne $1, $26, 0 [ok_pc-0x800001d8]

最佳答案

addi $t0, $t0, 0    # i = 0

不会设置 $t0到 0 而是保持不变。 ( move $t0, $zero ) 或 ( addi $t0, $0, 0 ) 都可以工作。

你也确定 $t0$t2保存在系统调用中?

最后,您发布的错误似乎没有出现在您的代码中。您是否有寄存器的堆栈跟踪/转储或其他任何可能有助于跟踪它的东西?

关于assembly - 这个 MIPS/QtSPIM While 循环代码有什么问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7821025/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com