基础知识介绍:
1. MIPS32的内部寄存器。
最简单的办法就是通过GDB的命令,可以获得下面的列表
(gdb) info registers zero at v0 v1 a0 a1 a2 a3 R0 00000000 00000001 0000000f 0000000f 00000000 0000000f 0000000e 00000071 t0 t1 t2 t3 t4 t5 t6 t7 R8 00000072 00000001 00000203 80003cb1 80003cb0 0000007f 00000080 00000008 s0 s1 s2 s3 s4 s5 s6 s7 R16 00000001 80003bb0 00000000 00000000 00000000 00000000 00000000 00000000 t8 t9 k0 k1 gp sp s8 ra R24 0000101a 0000000d 00000000 00000000 8000bbd0 807fffb8 00000000 80000830 sr lo hi bad cause pc 00000000 00000000 00000007 00000000 00000000 80000830 fsr fir 00000000 00000000 |
除了32个通用寄存器以及别名外,还有8个专用寄存器,分别是:
sr ( 全称Status ,CP0 Reg12) Processor status and control; interrupt control; and shadow set control
lo ( 全称WatchLo , CP0 Reg18) Low-order watchpoint address
hi ( 全称WatchHi, CP0 Reg19) High-order watchpoint address
bad ( 全称BadVAddr, CP0 Reg8) Reports the address for the most recent address-related exception
cause (CP0 Reg13) Cause of last exception
pc 很明显这个是程序计数寄存器,奇怪的是在32个通用寄存器以及CP0的32个寄存器中都没有找到他,最接近的一个是CP0Reg14 EPC (Program counter at last exception.)
fsr 浮点相关寄存器,具体用途不明
fir浮点相关寄存器,具体用途不明
下表描述32个通用寄存器的别名和用途
;REGISTER | NAME | USAGE |
$0 | $zero | 常量0(constant value 0) |
$1 | $at | 保留给汇编器(Reserved for assembler) |
$2-$3 | $v0-$v1 | 函数调用返回值(values for results and expression evaluation) |
$4-$7 | $a0-$a3 | 函数调用参数(arguments) |
$8-$15 | $t0-$t7 | 暂时的(或随便用的) |
$16-$23 | $s0-$s7 | 保存的(或如果用,需要SAVE/RESTORE的)(saved) |
$24-$25 | $t8-$t9 | 暂时的(或随便用的) |
$28 | $gp | 全局指针(Global Pointer) |
$29 | $sp | 堆栈指针(Stack Pointer) |
$30 | $fp | 帧指针(Frame Pointer) |
$31 | $ra | 返回地址(return address) |
Table: MIPS registers and the convention governing their use.
Register Name | Number | Usage |
zero | 0 | Constant 0 |
at | 1 | Reserved for assembler |
v0 | 2 | Expression evaluation and results of a function |
v1 | 3 | Expression evaluation and results of a function |
a0 | 4 | Argument 1 |
a1 | 5 | Argument 2 |
a2 | 6 | Argument 3 |
a3 | 7 | Argument 4 |
t0 | 8 | Temporary (not preserved across call) |
t1 | 9 | Temporary (not preserved across call) |
t2 | 10 | Temporary (not preserved across call) |
t3 | 11 | Temporary (not preserved across call) |
t4 | 12 | Temporary (not preserved across call) |
t5 | 13 | Temporary (not preserved across call) |
t6 | 14 | Temporary (not preserved across call) |
t7 | 15 | Temporary (not preserved across call) |
s0 | 16 | Saved temporary (preserved across call) |
s1 | 17 | Saved temporary (preserved across call) |
s2 | 18 | Saved temporary (preserved across call) |
s3 | 19 | Saved temporary (preserved across call) |
s4 | 20 | Saved temporary (preserved across call) |
s5 | 21 | Saved temporary (preserved across call) |
s6 | 22 | Saved temporary (preserved across call) |
s7 | 23 | Saved temporary (preserved across call) |
t8 | 24 | Temporary (not preserved across call) |
t9 | 25 | Temporary (not preserved across call) |
k0 | 26 | Reserved for OS kernel |
k1 | 27 | Reserved for OS kernel |
gp | 28 | Pointer to global area |
sp | 29 | Stack pointer |
fp or s8 | 30 | Frame pointer |
ra | 31 | Return address (used by function call) |