【发布时间】:2019-10-24 01:17:50
【问题描述】:
我正在尝试在 Assembly 中查找并打印数组的最小值和最大值。我现在的主要问题是增加数组索引的值。当我将文件加载到 QTSimp 时,我不断收到语法错误。我确信还有更多问题,但我稍后会解决。
我的问题是为什么我不能将数组增加到下一个值?什么是语法错误?
这是我的代码:
.data
array: .word 5, 7, 12, 3, 4, 9, 6, 11, 2, 10
array_size: .word 10
array_min: .asciiz "\nMin: "
array_max: .asciiz "\nMax: "
.text
.globl main
main:
la $a1, array # loading memory address of array
addi $t0, $zero, 0 # setting index incrementer to 0
lw $s1, 0($a1) # setting $s1 to the smallest index of the array
lw $s2, 0($a1) # setting $s2 to the smallest index of the array
while:
beq $t0, 10, exit # branch to exit if $t0 is 10
addi $t1, $t1, 4 # too add the next four bytes for the array index
blt array($t1), $s1, minimum # branch to minimum if $array[$t1] < $s1
blt array($t1), $s2, maximum # branch to maximum if $array[$t1] < $s2
minimum:
lw $s1, array($t1)
j while
maximum:
lw $s2, array($t1)
j while
addi $t0, $t0, 1 # increment $t0 by 1
j while # jump to the beginning of the while loop
exit:
li $v0, 4 # prints the array_min string
la $a0, array_min
syscall
li $v0, 1 # prints the smallest integer
move $a0, $s1
syscall
li $v0, 4 # prints the array_max string
la $a0, array_max
syscall
li $v0, 1 # prints the largest integer
move $a0, $s2
syscall
li $v0, 10 # terminates program
syscall
谢谢!
【问题讨论】:
-
您收到的错误消息的确切措辞是什么?将其包含在您的问题中。
-
对不起,它说: spim: (parser) syntax error on line 26 of file:* blt array($t1, $s1, minimum # branch to minimum if $array[$t1]
-
blt不能取内存操作数;只有加载/存储可以做到这一点。 MIPS 是加载/存储 RISC 机器,而不是 CISC。
标签: arrays assembly max mips qtspim