For these programming exercises, use only those instructions that have been discussed so far in these notes:
add | lhu | sb |
addi | lui | sh |
addiu | lw | sll |
addu | mfhi | sra |
and | mflo | srl |
andi | mult | sub |
div | multu | subu |
divu | nor | sw |
lb | or | xor |
lbu | ori | xori |
lh |
In the Simulator/Settings/MIPS menu of SPIM set Bare Machine ON, Accept Pseudo Instructions OFF, Enable Delayed Branches ON, Enable Delayed Loads ON, Enable Mapped I/O OFF, Load Exception Handler OFF.
Run the programs by single stepping (pushing F10). Observing the results in the SPIM Int Regs window. Check the Registers menu that the registers are displayed in HEX.
Your program has a data section declared as follows:
.data .byte 12 .byte 97 .byte 133 .byte 82 .byte 236
Write a program that adds the values up, computes the average, and stores the result in a memory location. Is the average correct?
Hint: there are two easily-made errors in this program.
Click here to go back to the main menu.
* == easy program ** == moderately easy program *** == harder program **** == project