MIPS系统调用指令 [英] MIPS syscall instruction
问题描述
我反汇编了一些 MIPS 机器代码,得到以下代码片段.
I disassembled some MIPS machine code and I got below code snippet.
00 00 00 0C syscall 0 # System Call
00 00 00 00 nop
03 E0 00 08 jr $ra # Jump Register
00 00 00 00 nop
我想知道syscall 0
的含义.
我知道调用 syscall
需要 syscall
号码.并且传递了 syscall
号通过 $v0
注册.
I know syscall
number is required to call a syscall
. And the syscall
number is passed
by $v0
register.
没有使用 $v0
而只有 syscall 0
这是否等于:
move $v0, 0
syscall
?
推荐答案
检查了 MIPS 文档:
Checked the MIPS document:
面向程序员的 MIPS32TM 架构第二卷:MIPS32TM指令集
MIPS32TM Architecture For Programmers Volume II: The MIPS32TM Instruction Set
它说:
格式:SYSCALL 6 MIPS32 (MIPS I) 目的:引起系统调用异常描述:发生系统调用异常,立即且无条件地将控制转移到异常处理程序.这代码字段可用作软件参数,但异常处理程序仅通过加载包含指令的内存字.
Format: SYSCALL 6 MIPS32 (MIPS I) Purpose: To cause a System Call exception Description: A system call exception occurs, immediately and unconditionally transferring control to the exception handler. The code field is available for use as software parameters, but is retrieved by the exception handler only by loading the contents of the memory word containing the instruction.
看起来指令中确实有立即数位",但用法是太复杂,所以很少使用.反而:系统调用似乎组装相同系统调用 0而 $v0 用于传递系统调用号.更简单、更快捷.
Looks like there really are "immediate bits" in the instruction, but the usage is too complicated, so it's seldom used. Instead: syscall seems to assemble the same as syscall 0 and the $v0 is used to pass the system call number instead. Easier and faster.
立即位"的使用似乎需要旧方法":使用返回地址作为指针并从指令中对系统调用号进行位屏蔽/移位.
The use of the "immediate bits" seems to require the "old way": using the return address as a pointer and bit-masking/shifting the syscall number from the instruction.
即:从处理器的角度来看,立即数位是无关紧要的".
[edit] That is: from the processor's point of view, the immediate bits are "don't care".
这篇关于MIPS系统调用指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!