CSCI-UA.0436 - Prof. Grishman
Assignment 4 - MIPS Assembly Language
Write a MIPS program, using a loop, which computes the maximum of
(32-bit) words in memory (treating the words as two's complement
integers) and stores the result in a word labeled max.
Declare and initialize this array as part of your program.
the operation of your code using a MIPS assembler/simulator.
Reminder: MIPS uses byte addressing, so the addresses of
words differ by 4, not 1.
Due October 17th.
Mail your homework (the assembly language program file) to email@example.com and firstname.lastname@example.org and mark
the mail CompArch -- Asgn 4.
program itself should be an attachment with the file name
MIPS Assembler Notes
Several assembler / simulator systems have been developed for MIPS.
The original one, SPIM, can be downloaded from the SPIM
web site, http://www.cs.wisc.edu/~larus/spim.html.
An alternative Java-based MIPS IDE, MARS, which runs on both PC's
Macs, and which we have used in class, is available at
You may use either numeric register identifiers ($1, $2, $3, ...) or
symbolic register identifiers ($s1, $s2, $s3, ...). If you use
numeric identifiers, do not
use $1; it is used by the assembler to expand instructions
involving 32-bit constants into two MIPS instructions.
Precede the instruction portion of your program with the assembler
the data portion of your program with
the assembler directive ".data".
Label the first instruction you want executed "main:". The kernel
code will transfer there with a jal
(jump and link) instruction. For SPIM,
finish your program with a "jr
this will return
to the kernel, which will then terminate execution. For MARS, finish
with li $v0, 10 followed by syscall.
(For the in-class examples, we just let the program 'fall off the
So the basic structure of a SPIM program (to add 3 and 4) would be
Although the basic idea for this course is to program 'close to the
machine', the assembler in fact does lots of things which allow the
programmer to ignore constraints in the actual hardware, such as
aa: .word 3
bb: .word 4
cc: .word 0
main: lw $2, aa
lw $3, bb
add $4, $2, $3
sw $4, cc
Appendix B gives much more information about the assembler.
- loads and stores with addresses outside the allowed range for
address constants are expanded to 2-instruction sequences
- arithmetic with constants outside the allowed range for
are expanded to 2 or 3-instruction sequences
- pseudoinstructions are provided for the conditional branches
provided in the hardware, including blt (branch on less than), ble (branch on less
greater than), bge
(branch on greater than or equal)
- a load address (la)
aa puts the address of aa into register $2
- a load immediate (li)
10 puts the constant 10 into register $2