V22.0436 - Prof. Grishman

Assignment 4 - MIPS Assembly Language

Write a MIPS program, using a loop, which computes the sum of five consecutive (32-bit) words in memory and stores the result in a word labeled sum.  Declare and initialize this array as part of your program.  Verify the operation of your code using the SPIM assembler/simulator.

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

Due in two weeks: October 16th.

Mail your homework (the assembly language program file) to  grishman@cs.nyu.edu and to ysc270@nyu.edu (Mr. Yu-shun Cheng) and mark the mail CompArch -- Asgn 4.

SPIM Assembler Notes

The simulator is on the CD and can also be downloaded from the SPIM web site,  http://www.cs.wisc.edu/~larus/spim.html

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.  Finish your program with a "jr $ra" instruction;  this will return to the kernel, which will then terminate execution.

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.