MIPS 寄存器
MIPS comes with 32 general purpose registers named $0. . . $31
Registers also have symbolic names reflecting their conventional8 use:
$0 $zero constant 0
$1 $at used by assembler
$2 $v0 function result
$3 $v1 function result
$4 $a0 argument 1
$5 $a1 argument 2
$6 $a2 argument 3
$7 $a3 argument 4
$8 $t0 unsaved temporary
$9 $t1 unsaved temporary
$10 $t2 unsaved temporary
$11 $t3 unsaved temporary
$12 $t4 unsaved temporary
$13 $t5 unsaved temporary
$14 $t6 unsaved temporary
$15 $t7 unsaved temporary
$16 $s0 saved temporary
$17 $s1 saved temporary
$18 $s2 saved temporary
$19 $s3 saved temporary
$20 $s4 saved temporary
$21 $s5 saved temporary
$22 $s6 saved temporary
$23 $s7 saved temporary
$24 $t8 unsaved temporary
$25 $t9 unsaved temporary
$26 $k0 reserved for OS kernel
$27 $k1 reserved for OS kernel
$28 $gp pointer to global data
$29 $sp stack pointer
$30 $fp frame pointer
$31 $ra return address
Registers also have symbolic names reflecting their conventional8 use:
$0 $zero constant 0
$1 $at used by assembler
$2 $v0 function result
$3 $v1 function result
$4 $a0 argument 1
$5 $a1 argument 2
$6 $a2 argument 3
$7 $a3 argument 4
$8 $t0 unsaved temporary
$9 $t1 unsaved temporary
$10 $t2 unsaved temporary
$11 $t3 unsaved temporary
$12 $t4 unsaved temporary
$13 $t5 unsaved temporary
$14 $t6 unsaved temporary
$15 $t7 unsaved temporary
$16 $s0 saved temporary
$17 $s1 saved temporary
$18 $s2 saved temporary
$19 $s3 saved temporary
$20 $s4 saved temporary
$21 $s5 saved temporary
$22 $s6 saved temporary
$23 $s7 saved temporary
$24 $t8 unsaved temporary
$25 $t9 unsaved temporary
$26 $k0 reserved for OS kernel
$27 $k1 reserved for OS kernel
$28 $gp pointer to global data
$29 $sp stack pointer
$30 $fp frame pointer
$31 $ra return address
寄存器号 符号名 用途
0 始终为0 看起来象浪费,其实很有用
1 at 保留给汇编器使用
2-3 v0,v1 函数返回值
4-7 a0-a3 前头几个函数参数
8-15 t0-t7 临时寄存器,子过程可以不保存就使用
24-25 t8,t9 同上
16-23 s0-s7 寄存器变量,子过程要使用它必须先保存
然后在退出前恢复以保留调用者需要的值
26,27 k0,k1 保留给异常处理函数使用
28 gp global pointer;用于方便存取全局或者静态变量
29 sp stack pointer
30 s8/fp 第9个寄存器变量;子过程可以用它做frame pointer
31 ra 返回地址
硬件上这些寄存器并没有区别(除了0号),区分的目的是为了不同的编译器产生的代码可以通用