[英]MIPS code doesn't print strings loaded from memory
So I am trying to find the maximum and minimum in a user input array, however for some reason my program isn't printing the strings that are loaded by their address at some points, ie lines 83-85 and lines 91-93 因此,我试图在用户输入数组中查找最大值和最小值,但是由于某些原因,我的程序未打印在某些点(即第83-85行和第91-93行)由其地址加载的字符串
Here's the code: 这是代码:
.data
array: .byte 40
output1: .asciiz "\nThe maximum value in array is: "
output2: .asciiz "\nThe minimum value in array is: "
newline: .asciiz "\n"
space: .asciiz " "
max: .word 0
min: .word 0
.text
.globl main
main:
li $t0, 0
li $t1, 0
reader:
bgt $t0, 36, printArray
li $v0, 5
syscall
move $t2, $v0
sw $t2, array($t0)
addi $t0, 4
b reader
printArray:
li $t0, 0 # reintialize counter
arrayLoop:
bgt $t0, 36, findMax
li $v0, 1
lw $a0, array($t0)
syscall
li $v0, 4
la $a0, space
syscall
add $t0, 4
b arrayLoop
findMax:
li $v0, 4
la $a0, newline
syscall
li $t0, 0 #resetting the counter
lw $t2, array($t0) #assuming index 0 to be max
add $t0, 4 #adding 4,so that t3 is at array[1]
greaterLoop:
bgt $t0, 36, findMin
lw $t3, array($t0)
bgt $t3, $t2, updateMax
add $t0, 4
b greaterLoop
updateMax:
move $t2, $t3
sw $t2, max
add $t0, 4
b greaterLoop
findMin:
li $v0, 4
la $a0, newline
syscall
li $t0, 0 #resetting the counter
lw $t2, array($t0)
add $t0, 4
smallerLoop:
bgt $t0, 36, printMinMax
lw $t3, array($t0)
blt $t3, $t2, updateMin
add $t0, 4
b smallerLoop
updateMin:
move $t2, $t3
sw $t2, min
add $t0, 4
b smallerLoop
printMinMax:
**li $v0, 4
la $a0, output1
syscall**
li $v0, 1
lw $a0, max
syscall
**li $v0, 4
la $a0, output2
syscall**
li $v0, 1
lw $a0, min
syscall
li $v0, 10
syscall
The problem occurs in the printMinMax function, where the syscalls for printing strings are done, however no strings are being printed. 该问题发生在printMinMax函数中,该函数完成了用于打印字符串的系统调用,但是未打印任何字符串。 The strings are saved in data as output1 and output2.
字符串将作为输出1和输出2保存在数据中。
This is a really weird issue and I don't know what's kind wrong as there's no error message as well. 这是一个很奇怪的问题,我也不知道是什么错误,因为也没有错误消息。
Jester helped me find the error. 小丑帮我找到错误。 I had to allocate 40 bytes using .space, not use .byte which is going to allocate value of 40 to one byte.
我不得不使用.space分配40个字节,而不是使用.byte来将40的值分配给一个字节。
Thanks a lot! 非常感谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.