我正在尝试编写一个程序,让用户输入一个选项,它从另一个文件分支并运行一个程序。我试过寻找答案,但我没有任何运气。我将所有要使用的文件都放在同一个目录中,并将它们全部更改为 .global,然后进入设置以组合目录中的所有文件。
.data
options: .asciiz "Enter 1 for Roadway\nEnter 2 for Equipment\nEnter 3 for Labor\nEnter 4 for Total Projects Costs\n"
.text
.global main
main:
li $v0, 4
la $a0, options
syscall
li $v0, 5
move $t0, $a0
syscall
beq $t0, 1, option1
#beq $t0, 2, option2
#beq $t0, 3, option3
#beq $t0, 4, option4
li $v0, 10
syscall
option1:
#this is where I'd like to run code from another file
jr, $ra
MARS 模拟器具有“设置/组装目录中的所有文件”设置,允许将多个文件链接到单个程序中。
示例...我在磁盘上创建了新目录并将两个 .asm 文件保存到其中:
.text
.globl printAsciiz
# $t5 = address of ASCIIz string, modifies $v0
printAsciiz:
# store original $a0 to stack (to preserve it)
addi $sp, $sp, -4
sw $a0, ($sp)
# output the message from t5
li $v0, 4
move $a0, $t5
syscall
# restore $a0 from stack
lw $a0, ($sp)
addi $sp, $sp, 4
# return from function
jr $ra
.data
msg: .asciiz "Hello world\n"
.text
.globl main
main:
# call output function from other file
la $t5, msg
jal printAsciiz
# terminate program
li $v0, 10
syscall
现在,当切换到编辑器选项卡时main.asm
(!重要,当编辑选项卡切换到时func.asm
,构建过程将func.asm
作为独立应用程序执行结果 - 有点笨拙和奇怪的行为),然后点击构建按钮(使用“所有文件" 设置为 ON),生成的二进制文件将main.asm
通过加载$t5
地址开始,然后printAsciiz
从func.asm
.
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句