我是SPIM
的新手,并用它来编写模拟编译器,并将其作为编译器设计课程的一部分。
考虑以下程序:
.data
string_access_violation: .asciiz "Access Violation"
string_illegal_div_by_0: .asciiz "Division By Zero"
string_invalid_ptr_dref: .asciiz "Invalid Pointer Dereference"
global_c: .word 0
_2_func_name: .asciiz "mul"
_5_func_name: .asciiz "inc"
_8_func_name: .asciiz "foo"
_9_func_name: .asciiz "bar"
_10_func_name: .asciiz "main"
.text
.globl main
func1:
sw $t0, -4($fp)
sw $t1, -8($fp)
sw $t2, -12($fp)
...
mul:
...
func3:
...
main:
jal _0_init_i
jal _1_init_c
addi $sp, $sp, -12
sw $fp, 0($sp)
sw $ra, 4($sp)
尝试运行它时出现以下错误:
spim: (parser) syntax error on line 86 of file FOLDER_5_OUTPUT/MIPS.txt
mul:
^
The following symbols are undefined:
main
Instruction references undefined symbol at 0x00400014
[0x00400014] 0x0c000000 jal 0x00000000 [main] ; 188: jal main
但是main
确实存在并声明为全局。我想念什么?
编辑:可以找到整个代码here。