Introduction to MIPS
Some basic facts about MIPS:
- a word in MIPS is 32 bits, or 4 bytes
- MIPS instructions are 32 bits (4 bytes) long
- MIPS memory addresses are 32 bits (4 bytes) long
- MIPS has 32 integer registers, each of which is 32 bits (4 bytes) long
- arithmetic and logical operations are always done with registers
- load operations copy a value from memory to a register
- store operations copy a value from a register to memory
- MIPS is a load-store architecture: all arithmetic and logical
operations are done in registers; only load and store operations access
memory
- There are three types of instructions: basic instructions,
pseudo instructions, and directives
- basic instructions are executed directly by the MIPS hardware
- pseudo instructions are translated by the assembler into one
(or a sequence of) basic instruction(s)
- directives are instructions for the assembler itself
- there are three instruction formats: R-type, J-type, and I-type
(more on these later)
- a character is 8 bits (1 byte) long
- an integer is 32 bits (4 bytes) long
The Format of a MIPS Program
The components of a MIPS program are as follows:
- comments
- Comments start with a # sign. Everything is a comment from the # to
the end of the line.
- labels
- Labels are user defined names, assigned to statements and variables.
A label starts with a letter, followed by letters and/or digits,
and ends with a :
- variables
- Variables are defined at the beginning of the program. The directive
.data starts the variable section.
- code
- The code comes after the variables. There are two directives for the
code. The .globl directive specifies the external name
of the function. For now, that name will be main. Later
we will discuss how to create additional functions. This is
followed by the .text directive, which
starts the code section. The label main comes right after the
.text directive to indicate where execution should begin.
The layout of a MIPS program is as follows:
# comments describing the program
#
.data
# variable declarations go here
.globl main
.text
main:
# program code goes here
Constants
- character
- character constants are enclosed in single quotes, for example 'a',
'Q', '4', '&'
- numeric
- numeric constants are written in base 10, with an optional leading sign,
for example 5, -17
- string
- string constants are enclosed in double quotes, for example
"this is a string"
Email Me |
Office Hours |
My Home Page |
Department Home |
MCC Home Page
© Copyright Emmi Schatz 2009