Mips assembly examples
To help you refresh your MIPS assembly skills you are strongly encouraged to study this small collection of example programs. Each program demonstrates a small collection of features of the MIPS assembly language.
The mips-examples repository
Before you continue you should already have cloned the
mips-examples repository. If you have not done this already,
follow these instructions before you continue.
For each of the example files in the repository:
- Read the source code.
- Load the program in MARS and single step the program.
- Try to understand how the program works.
- Add your own experiments.
hello.s
- File
hello.s- Description
- A small “Hello World” program.
- Assembly directives
.data,.asciizand.text- Instructions
liandla.- System calls
print_stringandexit.
basics.s
- File
basics.s- Description
- The basics of MIPS assembly.
- Assembly directives
.data,.text,.space,.wordand.asciiz.- Instructions
li,la,lw,add,addi,swandmove.- System calls
print_string,print_int,print_charandexit.
jump_and_branches.s
- File
jump_and_branches.s- Description
- Unconditional and conditional branches.
- Implemented control structures
if-then-elseandinfinite loop.- Assembly directives
.data,.text, and.asciiz.- Instructions
j,bltandbge.
arrays.s
- File
arrays.s- Description
- Allocation and usage of arrays.
- Data structures
- Array of integers and array of strings.
subroutines.s
- File
subroutines.s- Description
- A short introduction to the basic use of subroutines.
- Instructions introduced
jal(Jump And Link) andjr(Jump Register).- Register introduced
$ra(Return Address)- Concepts introduced
- The register use convention.