Introduction
A number of system services, mainly for input and output, are available for use by your MIPS program. They are described in the table below.
MIPS register contents are not affected by a system call, except for result registers as specified in the table below.
How to use SYSCALL system services
Step 1. Load the service number in register $v0.
Step 2. Load argument values, if any, in $a0, $a1, $a2, or $f12 as specified. Step 3. Issue the SYSCALL instruction.
Step 4. Retrieve return values, if any, from result registers as specified.
Example: display the value stored in $t0 on the console
li $v0, 1
# service 1 is print integer
add $a0, $t0, $zero
# load desired value into argument register $a0, using pseudo-op
syscall
#写数据的地方
.data
str: .asciiz "HelloWorld"
#写代码的地方
.text
main:
li $v0,4
la $a0,str
syscall
li $v0 10
syscall
写数据的地方
.data
str: .asciiz “HelloWord”
先写好数据,再去加载数据。
写代码的地方
.text
main:
li $v0,4
这里为什么要加载立即数4到v0寄存器中,这里涉及到系统调用服务,当寄存器v0中的值为4的时候,系统服务是打印字符串。
la $a0,str
这里将要打印的字符串的地址放到a0寄存器中。
syscall
这里执行系统调用
li $v0 10
这里为什么要加载立即数10到v0寄存器中,这里涉及到系统调用服务,当寄存器v0中的值为10的时候,系统退出(终止执行)
syscall
syscal的意思就是系统调用。
如果这些你不理解,不要紧,只要记住系统要执行什么功能,就先往v0寄存器中加载立即数,根据数值的不同,执行不同的功能。等你有一天学习了计算机组成原理以后再回来看,你就可以真正理解了。如果想要了解v0寄存器的更多的功能,点击MARS的Help,再点击syacall,这里我就讲到这里。


本文介绍了MIPS架构下如何使用系统调用服务,包括显示整数和字符串的方法。通过具体的MIPS汇编指令示例,展示了如何设置寄存器以实现所需的功能。

1万+

被折叠的 条评论
为什么被折叠?



