使用(QTSPIM)在MIPS中打印字符串困难
基本上,每当我在一定的代码之后打印时,在这种情况下,循环, SPIM控制台中的输出要么是一个空的字符(看起来像一个空心正方形),要么是一个空字符串(几个空格)。需要一些帮助来弄清楚我缺少的东西...
.data
arrayY: .word 1, 2, 3, 4, 5 # array of 5 elements
arrayZ: .word -5, -4, -3, -2, -1 # array of 5 elements
arrayX: .word 20 # init array 5 elements
var1: .asciiz "X: "
var2: .asciiz ", "
.text
.globl main
main:
addi $a2, $zero, 5 # init n
addi $s0, $zero, 2 # init s
addi $s1 $zero, 1 # init t
addi $sp, $sp, -12
sw $s1, 4($sp) # push to stack
sw $s0, 0($sp)
jal AVA
AVA:
li $v0, 0
li $v1, 0
addi $t1, $a2, -1
addi $t1, $zero, 20
addi $t0, $zero, 0
LOOP:
beq $t0, $t1, exit
lw $t2, arrayY($t0)
lw $t3, arrayZ($t0)
subu $t4, $zero, $t3
add $t5, $t4, $t2
addi $t3, $zero, 2
mult $t3, $s0
add $t6, $t3, $s1
lw $s0, 0($sp)
lw $s1, 4($sp)
addi $sp, $sp, 12
add $t7, $t5, $t6
sw $t7, arrayX($t0)
addi $t0, $t0, 4
j LOOP
exit:
addi $t0, $zero, 0
move $a0, $0
move $v0, $0
li $v0, 4
la $a0, var1
syscall
LOOP1:
beq $t0, $t1, exit1
lw $t2, arrayY($t0)
move $a0, $t2
li $v0, 1
syscall
addi $t0, $t0, 4
j LOOP1
exit1:
li $v0, 10 # exit
syscall
预期输出:
X: 12345
实际输出:
12345
如果我在代码中较早打印字符串,则在两个循环之前,都会按预期打印字符串。我是MIP的新手,以为也许我必须在循环之后重置寄存器,但这并没有做不同的事情。
Basically whenever I print after a certain section of code, in this case the loop,
the output in SPIM's console is either an empty character (looks like a hollow square) or an empty string (several spaces). Need some help figuring out what I'm missing...
.data
arrayY: .word 1, 2, 3, 4, 5 # array of 5 elements
arrayZ: .word -5, -4, -3, -2, -1 # array of 5 elements
arrayX: .word 20 # init array 5 elements
var1: .asciiz "X: "
var2: .asciiz ", "
.text
.globl main
main:
addi $a2, $zero, 5 # init n
addi $s0, $zero, 2 # init s
addi $s1 $zero, 1 # init t
addi $sp, $sp, -12
sw $s1, 4($sp) # push to stack
sw $s0, 0($sp)
jal AVA
AVA:
li $v0, 0
li $v1, 0
addi $t1, $a2, -1
addi $t1, $zero, 20
addi $t0, $zero, 0
LOOP:
beq $t0, $t1, exit
lw $t2, arrayY($t0)
lw $t3, arrayZ($t0)
subu $t4, $zero, $t3
add $t5, $t4, $t2
addi $t3, $zero, 2
mult $t3, $s0
add $t6, $t3, $s1
lw $s0, 0($sp)
lw $s1, 4($sp)
addi $sp, $sp, 12
add $t7, $t5, $t6
sw $t7, arrayX($t0)
addi $t0, $t0, 4
j LOOP
exit:
addi $t0, $zero, 0
move $a0, $0
move $v0, $0
li $v0, 4
la $a0, var1
syscall
LOOP1:
beq $t0, $t1, exit1
lw $t2, arrayY($t0)
move $a0, $t2
li $v0, 1
syscall
addi $t0, $t0, 4
j LOOP1
exit1:
li $v0, 10 # exit
syscall
Expected output :
X: 12345
Actual output :
12345
If I print the string earlier in the code, before both loops it prints the string as expected. I'm new to MIPS and thought maybe I had to reset the registers after the loop or something but that didn't do anything differently.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,在开始时执行此操作:
然后使用模拟器菜单 - >显示符号。 在第一个单一步骤之前执行此菜单项 - 这些符号在执行过程中不会移动,因此在第一个指令之前,请先了解数据布局,因为它们知道它们不会从那里更改。
使用这些信息,您可以跟踪所有数据项的位置,有多大,在什么之后发生了什么等等等等…… 然后,您可以更了解谁在覆盖什么,也许是为什么!
So, do this at the beginning:
Then use Simulator menu -> Display Symbols. Do this menu item before the first single step — these symbols don't move during execution, so get to know your data layout before the first instruction knowing they won't change from there.
Using that information you can track where all your data items are and how big they are, what comes after what, etc... Then you can make more sense of who is overwriting what, and perhaps why!