03. Registers and memory
Supplemental: MIPS Assembly Language by Gary Shute
- Convention
- A set of terms on using architecture features in program. A convention can be broken by cost of (painful) incompatibility.
Registers
Alternate Name |
Register Name |
Use |
$zero |
$0 |
constant value 0 |
$s0 - $s8 |
$16 - $23, $30 |
saved values - preserved across calls |
$sp |
$29 |
stack pointer - preserved across calls |
$ra |
$31 |
return address - not preserved across calls |
$a0 - $a3 |
$4 - $7 |
the first four parameters - not preserved across calls |
$t0 - $t9 |
$8 - $15, $24 - $25 |
temporaries - not preserved across calls |
$v0 - $v1 |
$2 - $3 |
expression evaluation and subprogram return value - not preserved across calls |
$at |
$1 |
reserved by the assembler - dangerous to use |
$gp |
$28 |
global pointer - dangerous to use |
$k0 - $k1 |
$26 - $27 |
reserved by the operating system - dangerous to use |
Flat memory model
Data placement directives
Directive |
Operand Syntax |
Meaning |
.globl |
label { , label }* |
Declare labels to be global |
.data |
none |
Start a data declaration section |
.text |
none |
Start an instruction section |
.word |
integer [ : non-negative integer ] |
Declare a C int variable |
.asciiz |
string |
Declare a string variable |
.align |
number |
Align next address by 2**number bytes |
Code addressing
- strict %4
- i-commands (branch) and j-command (jump)
- two-bit cropping
E. g. (beware of meaningless code):
H/W
EJudge: DoubleSum 'Double sum'
Enter four integers, one in line, and add uniconditionally first one to third one, and second one to fourth one. Print results in two lines.
234 -23 23 64
257 41