Your assignment is to write a MIPS assembly language program that adds up the integers in a 5-word array and writes the sum to the console. Here is a skeleton assembly language file you can start with:
.globl main .data alpha: .word [put five "interesting" integers here] .text main: [write your code here] # Exit program li $v0, 10 syscall .end
Use pseudo-instructions to make your code easier to write. For example, use li ("load immediate") to initialize registers, and blt ("branch less than") for the test at the end of the loop.
Test your program using the SPIM simulator to make sure it works correctly. Examine the code window carefully and make sure you understand all four columns contents fully. (Help: The first column contains the memory address inside square brackets, the second column contains the memory contents, the third column gives the assembly language representation of the instructions generated by the assembler with pseudo-instructions converted to real instructions and with register names converted to register numbers, and the fourth column contains the assemly language statements you wrote.
Once your program is working and you have studied the code section of the SPIM window, do the following:
File: addem.ccv 0x34080000 ori $8, $0, 0 ori: Jmp=0 RgDs=1 ASrc=0 M2Rg=0 RgWr=0 MRd=1 MWr=0 Br=1 AOp1=1 AOp0=0 0x34040000 ori $4, $0, 0 ori: Jmp=0 RgDs=1 ASrc=0 M2Rg=0 RgWr=0 MRd=1 MWr=0 Br=1 AOp1=1 AOp0=0 0x34090014 ori $9, $0, 20 ori: Jmp=0 RgDs=1 ASrc=0 M2Rg=0 RgWr=0 MRd=1 MWr=0 Br=1 AOp1=1 AOp0=0 0x3c011001 lui $1, 4097 lui: Jmp=? RgDs=? ASrc=? M2Rg=? RgWr=? MRd=? MWr=? Br=? AOp1=? AOp0=? 0x00280821 addu $1, $1, $8 r_type: Jmp=0 RgDs=1 ASrc=0 M2Rg=0 RgWr=0 MRd=1 MWr=0 Br=0 AOp1=1 AOp0=0 0x8c250000 lw $5, 0($1) lw: Jmp=0 RgDs=0 ASrc=0 M2Rg=0 RgWr=1 MRd=1 MWr=1 Br=1 AOp1=0 AOp0=0 0x00852020 add $4, $4, $5 r_type: Jmp=0 RgDs=1 ASrc=0 M2Rg=0 RgWr=0 MRd=1 MWr=0 Br=0 AOp1=1 AOp0=0 0x21080004 addi $8, $8, 4 addi: Jmp=0 RgDs=1 ASrc=0 M2Rg=0 RgWr=0 MRd=1 MWr=0 Br=1 AOp1=1 AOp0=0 0x0109082a slt $1, $8, $9 r_type: Jmp=0 RgDs=1 ASrc=0 M2Rg=0 RgWr=0 MRd=1 MWr=0 Br=0 AOp1=1 AOp0=0 0x1420fffa bne $1, $0, -24 bne: Jmp=? RgDs=? ASrc=? M2Rg=? RgWr=? MRd=? MWr=? Br=? AOp1=? AOp0=? 0x34020001 ori $2, $0, 1 ori: Jmp=0 RgDs=1 ASrc=0 M2Rg=0 RgWr=0 MRd=1 MWr=0 Br=1 AOp1=1 AOp0=0 0x0000000c syscall r_type: Jmp=0 RgDs=1 ASrc=0 M2Rg=0 RgWr=0 MRd=1 MWr=0 Br=0 AOp1=1 AOp0=0 0x3402000a ori $2, $0, 10 ori: Jmp=0 RgDs=1 ASrc=0 M2Rg=0 RgWr=0 MRd=1 MWr=0 Br=1 AOp1=1 AOp0=0 0x0000000c syscall r_type: Jmp=0 RgDs=1 ASrc=0 M2Rg=0 RgWr=0 MRd=1 MWr=0 Br=0 AOp1=1 AOp0=0
Legend: The signal names are abbreviated to keep the lines short. A stands for ALU, M stands for Mem, Rg stands for Reg, Rd stands for Read, Wr stands for Write, Ds stands for Dst, and Jmp stands for Jump (see below). A value of '?' for a signal means that the instruction can't be handled by the datapath designed in the book; it would need additional features. And a value of 'X' (there are none in the sample output above) means the value of the signal doesn't matter, but a real controller would have to generate either a 1 or a 0 in place of the X.
Confessions: I captured the SPIM simulator's code window in a text file, and edited it so each line contained just columns 2 (the address) and 3 (the assembly language) of one instruction, and my program prints this line as it reads it. My program outputs a value for the Jump control signal developed just after Figure 5.22 in the book. The syscall instructions look like R-type instructions to my program, but that's not very meaningful. And the immediate format instructions won't work unless the datapath is modified to get the correct function code into the ALU; just setting ALUOp to 102 won't actually work. (How would you have to change the datapath to handle the immediate format instructions?)