【发布时间】:2021-06-17 06:17:58
【问题描述】:
这是我的代码:
.data
num1: .word # num1 variable
num2: .word # num2 variable
max: .word # max variable
msg: .asciiz "Enter an integer " # msg
msg2: .asciiz "The bigger value is " # msg2
.text
main:
la $a0, msg # prints msg
li $v0, 4
syscall
la $v0, 5 # reads data
syscall
# loads address of num1 to $t0
la $t0, num1
# moves the content of $v0 to $t0
move $t0,$v0
la $a0, msg # print msg
li $v0, 4
syscall
la $v0, 5 # read data
syscall
# loads address of num1 to $t1
la $t1, num2
# moves the content of $v0 to $t1
move $t1,$v0
# loads address of max to t2
la $t2, max
# if $t0 (num1) > $t2 (num2), execute if part/label
bgt $t0,$t1,if # go to if label
# else
else:
# moves the contents of $t1 (num2) to $t2 (max)
move $t2,$t1
la $a0, msg2 # print msg2
li $v0, 4
syscall
move $a0, $t2 # print max
li $v0, 1
syscall
li $v0, 10 # exit
syscall
# if
if:
# moves contents of $t0 (num1) to $t2 (max)
move $t2,$t0
la $a0, msg2 # print msg2
li $v0, 4
syscall
move $a0, $t2 # print max
li $v0, 1
syscall
li $v0, 10 # exit
syscall
每次我尝试在 QTSimp 中运行此代码时,我都会收到错误消息 “spim:文件 C:/Users/danie/Desktop/program_1.asm 第 3 行的(解析器)语法错误 .word # num1 变量"
我做错了什么?谢谢
【问题讨论】:
-
为你的单词提供一个初始化器。例如。
.word 0. -
.word没有 args(如果它确实组装了)将保留 0 字节的空间,用于字初始值设定项的空列表。就像 C 中的uint32_t array[0] = {};。这显然不是你想要的,所以汇编器阻止你编写无用的东西是件好事。