为什么该程序出现MIPS语法错误?

时间:2018-10-23 18:02:50

标签: scripting mips qtspim

我有一个简单的程序来打印我的名字,但是当我汇编它时,它说第一行包含语法错误。我很确定我已经正确地写了开头的几行,所以我不确定为什么。当我在在线模拟器上运行它时,它说“语法错误”,并在我的计算机上的QTSPIM模拟器上显示“指令引用了0x00400014处的未定义符号   [0x00400014] 0x0c000000 jal 0x00000000 [main]; 188:jal main”

.text 
main:
li $v0, 11 #Load command to print characters in v0 register
la $a0, 64 #Load character '@' into 4 register
syscall
sub $v0, 10 #Subract from v0 to get 1, command to print integers
sub $a0, 64 # sub from to print 0
syscall
addi $a0, 49, $zero #Make 4 register store 1
syscall 
addi $a0, 6, $zero #Make 4th register store 6
syscall
sub $a0, 5 #Make 4th register store 1
syscall
addi $a0, $zero, 6 #Make 4th register store 7
syscall
sub $a0, 3 #Make 4th register store 4
syscall
syscall
addi $a0, $zero, 4 #Make 4th register store 8
syscall
addi $v0, 10 #Print out char again
sub $a0, 46 #Print out new line (ASCII 10)
syscall
addi $a0, $zero, 56 #Store 'B'
syscall
addi $a0, $zero, 42 #Store 'l'
syscall
sub $a0, 11 #Store 'a'
syscall
addi $a0, $zero, 2 #Store 'c'
syscall
addi $a0, $zero, 8 #Store 'k'
syscall
sub $a0, 64 #Store ','
syscall
sub $a0, 12 #Store space ' ' 
syscall
addi $a0, $zero, 52 #Store 'T'
syscall
addi $a0, $zero,27 #Store 'e'
syscall
addi $a0, $zero, 13 #Store 'r'
syscall
sub $a0, 13 #Restore 'e'
syscall
addi $a0, $zero, 7 #Store 'l'
syscall
sub $a0, 98 #Start new line
syscall
sub $v0, 1 #Store exit commmand in v0
syscall

1 个答案:

答案 0 :(得分:0)

首先,您需要组织并标识您的代码,这将对您有所帮助。

第二,代码中存在语法错误:

必须如何做:(我是从Mars软件获得的。)

sub $t1,$t2,$t3         Subtraction with overflow : set $t1 to ($t2 minus $t3)
addi $t1,$t2,-100       Addition immediate with overflow : set $t1 to ($t2 plus signed 16-bit immediate)

我真的不明白您要打印什么。为什么您要对v0进行多项操作,而不是直接设置其值?

我已将您的代码固定为可打印

@0161748
Black, Terel

这是我了解您想要的。如果还有其他问题,请修改您的评论,使其更具体。

.text 

main:
    li $v0, 11 #Load command to print characters in v0 register
    la $a0, 64 #Load character '@' into 4 register
    syscall

    sub $v0, $v0, 10 #Subract from v0 to get 1, command to print integers
    sub $a0, $a0, 64 # sub from $a0 to print 0
    syscall

    addi $a0, $zero, 1 #Make 4 register store 1
    syscall 

    addi $a0, $zero, 6 #Make 4th register store 6
    syscall

    sub $a0, $a0, 5 #Make 4th register store 1
    syscall

    addi $a0, $a0, 6 #Make 4th register store 7
    syscall

    sub $a0, $a0, 3 #Make 4th register store 4
    syscall

    addi $a0, $a0, 4 #Make 4th register store 8
    syscall

    addi $v0, $v0, 10 #Print out char again
    addi $a0, $zero, 10 #Print out new line (ASCII 10)
    syscall

    addi $a0, $zero, 66 #Store 'B'
    syscall

    addi $a0, $zero, 108 #Store 'l'
    syscall

    addi $a0, $zero, 97 #Store 'a'
    syscall

    addi $a0, $zero, 99 #Store 'c'
    syscall

    addi $a0, $zero, 107 #Store 'k'
    syscall

    addi $a0, $zero, 44 #Store ','
    syscall

    addi $a0, $zero, 32 #Store space ' ' 
    syscall

    addi $a0, $zero, 84 #Store 'T'
    syscall

    addi $a0, $zero, 101 #Store 'e'
    syscall

    addi $a0, $zero, 114 #Store 'r'
    syscall

    addi $a0, $zero, 101 #Restore 'e'
    syscall

    addi $a0, $zero, 108 #Store 'l'
    syscall

    sub $a0, $a0, 98 #Start new line
    syscall

    sub $v0, $v0, 1 #Store exit commmand in v0
    syscall