How to program in MIPS32 Assembly!
Commenting: use hash mark, ex: # this is a comment
| Declaring Segments | Explanation |
|---|---|
| .data | start of "data related section" |
| .text | start of "code related section" |
| Declaring Integer and Floating Point data | Explanation |
|---|---|
| .word w1,w2,...,wn | Allocates for n 32 bit items and initializes them to listed values |
| .word w:n | Allocates n 32 bits items and initializes them to w |
| Note for word | MIPS32 uses word(32 bits) to store an integer, it can be used to store any 32 bit items. |
| .float f1, f2,...,fn | Allocates for n single-precision floating point numbers and initializes them to listed values. |
| .double d1, d2,...,dn | Allocates for n double-precision. |
| .byte | Allocates n 8 bits |
| .half | allocates n 16 bits |
| .space | allocates b uninitialized bytes |
| .ascii "string" | allocates and initilizes mem for/with "string" |
| .asciiz | same as .ascii but also add null-termination, like c-style strings. |
| .globl symbol | makes a global symbol |
| Note on globl | main is typically global. |
| .align n | Aligns next data item on 2^n byte boundry. |
Common Types of Instructions:
| Instruction | Explination |
|---|---|
| addi | Item 2 |
| Item 4 | Item 5 |
MARS specific:
##########################################################################
# Title: Author:
MIPS32 Assembly Language Getting Started
# Class: CS2318-??? Due: Submitted:
##########################################################################
# Functional description:
# ...
##########################################################################
# Register usage:
# ...
##########################################################################
# Pseudocode description:
# ...
############################ data segment ################################
13
############################ data segment ################################
.data
...
############################ code segment ################################
.text
.globl main
main:
...
li $v0, 10 # exit
syscall
##########################################################################
# Function name:
MIPS32 Assembly Language Getting Started
# Function name:
##########################################################################
# Functional description:
# ...
##########################################################################
# Input/output description:
# ...
##########################################################################
# Example calling sequence:
# ...
##########################################################################
# R i t
how parameters are passed
& how results are returned
14
# Register usage:
# ...
##########################################################################
# Pseudocode description:
# ...
##########################################################################
<proc name>:
...