V22.0436 - Prof. Grishman

Assignment 4 - MIPS Assembly Language

Write a MIPS program, using a loop, which computes the maximum of five consecutive (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.  Verify the operation of your code using a MIPS assembler/simulator.

Reminder: MIPS uses byte addressing, so the addresses of successive words differ by 4, not 1.

Due October 15th.

Mail your homework (the assembly language program file) to  grishman@cs.nyu.edu and mark the mail CompArch -- Asgn 4. The program itself should be an attachment with the file name myname.asm.

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, is available at http://courses.missouristate.edu/KenVollmar/MARS/).

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 directive ".text".  Precede 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 $ra" instruction;  this will return to the kernel, which will then terminate execution. (For MARS, finish with li $v0, 10   followed by   syscall.)

So the basic structure of a program (to add 3 and 4) would be
aa: .word 3
bb: .word 4
cc: .word 0
main: lw $2, aa
lw $3, bb
add $4, $2, $3
sw $4, cc
jr $ra

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
Appendix A gives much more information about the assembler.