【问题标题】:Syntax error in MIPS?MIPS 中的语法错误?
【发布时间】:2018-02-27 05:55:28
【问题描述】:

所以,我目前正在为我的大学学位学习 MIPS,我遇到了一个困扰我的语法错误,我似乎无法指出我哪里出错了,我的一段代码是一个在用户输入两个数字的地方,控制台应该返回一组数字,由于用户输入的两个数字而增加并完成打印,我目前在 PCSpim 上遇到语法错误,上面写着“spim:( parser) 文件第 55 行的语法错误" 第 55 行是我要发送的代码的addi $t0, $t0, $t2,如果有人能指出我在哪里解决这个问题的大致方向,那就太好了。

.data
 text: .asciiz "Enter any number: "
 message: .asciiz " After while loop is done "
 str: .asciiz "Enter a number to add: "
 newline: .asciiz "\n"
 space: .asciiz ","

.text

 main:


# Printing out the text
li $v0, 4
la $a0, text
syscall

# Getting user input
li $v0, 5
syscall

# Moving the integer input to another register
move $t1, $v0

# Printing out the newline
li $v0, 4
la $a0, newline
syscall

# Printing out the text
li $v0, 4
la $a0, str
syscall

# Getting user input
li $v0, 5
syscall

# Moving the integer input to another register
move $t2, $v0

# Printing out the newline
li $v0, 4
la $a0, newline
syscall

 # i = 0

 addi $t0, $zero, 0

 while: 

 bgt $t0, $t1, exit
 jal printNumber

 addi $t0, $t0, $t2

 j while

 exit:
    li $v0, 4
    la $a0, message
    syscall

 #End of program
 li $v0, 10
 syscall

 printNumber:
   la $v0, 1
   add $a0, $t0, $zero
   syscall

   li $v0, 4
   la $a0, space
   syscall

   jr $ra

【问题讨论】:

    标签: mips mars-simulator pcspim


    【解决方案1】:

    看起来 addi 需要第三个值是立即值而不是寄存器...如果它是寄存器,则应该添加

    【讨论】:

    • 所以我应该这样做add $t0, $t0, $t2,它应该可以正常工作吗?
    • 抱歉回复晚了,但我检查了它,它确实有效,非常感谢
    • @alonerebos,你应该投票并接受正确的答案......必须保持互联网积分流动。
    猜你喜欢
    • 1970-01-01
    • 2017-08-02
    • 2015-07-09
    • 1970-01-01
    • 2018-07-23
    • 1970-01-01
    • 1970-01-01
    • 2018-03-26
    • 2023-03-03
    相关资源
    最近更新 更多