User Tools

Site Tools


mips:mips32

Процессоры архитектуры MIPS32

Register Names

MIPS labels registers in two different ways. Integer registers are labelled from $r0 to $r31.

However, for the purposes of writing functions, it's often easier to label registers with mnemonics.

In particular, MIPS uses the following alternate names.

  • $zero This is hardwired 0 register. It's value is always zero no matter what you do with it.
  • $a0, $a1, $a2, $a3 There are the argument registers, and are used for passing up to four arguments to a function. Additional arguments use the stack. In addition, if the argument isn't 32 bits (a structure, for example), it must be passed on the stack.
  • $t0, $t1, …, $t9 These are temporary registers. When you make a subroutine call (i.e., jal), the callee does not need to save these registers if it wants to use these registers. However, if the caller wants to use the temporary registers after a jal call, it must push the temporary registers on the stack, just so the callee doesn't overwrite those registers.
  • $s0, $s1, …, $s7 These are saved registers. If a callee wants to use these registers, it must first push the register value onto the stack. Once it's done using the register, it must pop it from the stack and restore the value of the saved register. This is a convention only, meaning that assembly language programmers and compilers should observe these conventions, so code will work properly. However, the saving of these registers is not done automatically by the hardware.
  • $v0, $v1 These are return value registers. Usually only $v0 is use for the return value. However, if there's a need for 64 bits of result, there's a second register.
  • $sp The stack pointer points to the top of the stack. Stacks grow to smaller addresses, and the stack pointer contains the address of valid data (thus, $sp - 1 is an address of garbage data). It's assumed addresses smaller than $sp contain garbage data. However, it is possible for the stack to overflow, i.e., to have an address that becomes invalid.
  • $fp The frame pointer is a secondary pointer for function/subroutine calls. Usually, once jal occurs, you set $fp to $sp. Then, you adjust $sp for local variables. Once done, you can assign $sp back to $fp to quickly “pop” off everything from the stack used by a function.
  • $gp The global pointer is used to reference global variables. In general, we won't use it much in the course.
  • $ra Stores return address for jal calls.

All of the registers listed in the previous section correspond to some register labelled $r0 up to $r31.

Here's a chart. It's the same as the one on page 140 of Patterson and Hennessy.

Name Register Number Usage Preserved by callee
$zero 0 hardwired 0 N/A
$v0-$v1 2-3 return value and expression evaluation no
$a0-$a3 4-7 arguments no
$t0-$t7 8-15 temporary values no
$s0-$s7 16-23 saved values YES
$t8-$t9 24-25 more temporary values no
$gp 28 global pointer YES
$sp 29 stack pointer YES
$fp 30 frame pointer YES
$ra 31 return address YES

There are a few registers not listed. $at, which is register 1, is used by the assembler. $k0-$k1 which is registers 26-27 is used by the operating system.

It's easier to program using the mnemonics (i.e., names that suggest the purpose of the registers). An assembler should be able to handle either the $r0-$r31$ notation or the ones above.

While you should know the names of both sets of registers, you do not need to know how the correspond to one another. That is, it's more important to know there are temporary and saved registers and that an example is $t0 and $s0, but it's less important to know which register numbers they correspond to.

These alternate names make it easier to program because it's easier to remember what the registers are being used for by mnemonics.

telnet://devel8.cronyx.ru

mips/mips32.txt · Last modified: 2007/04/29 05:15 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki