Joe*_*oel 3 assembly mips computer-architecture spim command-line-arguments
我是大会的新手.我在从命令行参数中读取字符串时遇到了一些麻烦.
我想将thisismymessage第二个参数中的字符串读入缓冲区.
我想过使用SYSCALL,但不知道如何使用.
$ spim -f program.s file thisismymessage
Run Code Online (Sandbox Code Playgroud)
这里有几行代码来说明你要问的内容:
# $a0 = argc, $a1 = argv
# 4($a1) is first command line argv 8($a1) is second
main:
lw $a0, 8($a1) # get second command line argv
li $v0, 4 # print code for the argument (string)
syscall # tells system to print
li $v0, 10 # exit code
syscall # terminate cleanly
Run Code Online (Sandbox Code Playgroud)
参数的数量是$ A0,你可以检查对加载的整数值(LI)参数的数量成用于验证的临时寄存器.
命令行参数值argv存储在$ a1中,可以通过加载单词来访问.一个字是4个字节,因此我们可以使用0($ a1)访问argv [0],使用4($ a1)访问argv [1],依此类推.
在这种情况下,我们需要argv [2],我们可以将8($ a1)中的单词(lw)加载到我们选择的任何寄存器中.在这种情况下,我将它加载到$ a0,因为我之后直接打印它.
回顾一下:
# $a0 is argc, $a1 is argv
lw $t0, 8($a1) # gets argv[2] and stores it in $t0
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10373 次 |
| 最近记录: |