Programmer's View
Introduction
Before we begin programming in MIPS, we need to get a view of what
the CPU and memory looks like to the MIPS programmer. This view
is simplified compared to the actual CPU. That is, there are details
of the CPU that are hidden from the ISA programmer.
Is it good that these details are hidden? Most would say yes.
You want to expose enough of the hardware, so efficient programs
can be written, but not so much that it might inhibit future enhancement
of the CPU.
This is what abstraction is all about. Providing the user with
the interface they need, and hiding away implementation details. By
hiding such details, once can try to improve the speed of a CPU.
Thus, such details as the cache and pipeline are not something the
MIPS programmer is aware about.
Registers
MIPS has 32 integer registers. Each register can store 32 bits.
The registers are labeled $r0 through $r31. Some of the registers
are special:
- $r0 is hardwired 0. No matter what you do to this register,
it always contains the value 0.
- $r29 is the stack pointer. This stores the address of the
top of stack. Stacks grow to smaller addresses. The top of the
stack is the smallest address holding valid data. $r29 is only
the stack pointer by convention. No instruction implicitly
refers to $r29 (i.e., you must specify the register in the instruction).
- $r31 is the return address register. It's used in jal
instruction, which is how MIPS implements subroutines. This
register is used implicitly by the jal (and jalr).
There are 32 floating point registers, but for the most part
we won't talk that much about them. You can read about them
at your own leisure. These registers are used to perform
floating point operations.
There are two other integer registers called HI and LO, which
are used to store the upper and lower 32 bits of an integer multiply
instruction. Multiplying two 32 bit ints can create a 64 bit
result.
Memory
MIPS programs can access 32 bit addresses in memory. Recall
that memory is slow to access, while registers are fast to access.
Web Accessibility