Lab 2 – MIPS instruction set
The objective of this experiment is to research the MIPS architecture and more in-depth the instruction set . Hence the chapter 2 of Patterson and Hennesee.
Download the components for lab 2 from the course webpage.
If you are required to change assembly source code please indicate in the source code the lines which are changed leaving the old lines intact as comment.For the experiments where you have to write a complete program please submit the source file (extension .wasm ) .
Note: the 0x12345 is the hexadecimal representation of a number.
The code snippet below is an assembly listing from a compiled C program:
21 000c 3C020001 li $2,65536 # 0x10000 22 0010 34422345 ori $2,$2,0x2345 23 0014 AFC20008 sw $2,8($fp) 24 0018 24020007 li $2,7 # 0x7 25 001c AFC2000C sw $2,12($fp) 26 0020 8FC30008 lw $3,8($fp) 27 0024 8FC2000C lw $2,12($fp) 28 0028 00000000 nop 29 002c 00621021 addu $2,$3,$2 30 0030 AFC20010 sw $2,16($fp)
- What does the the second column represent? Can you explain the content?
- Explain the first 2 lines of the assembly code. Use the MIPS reference (either from the book or several online pdf versions).
- Advanced Question – Explain the third line (sw instruction). $fp is a frame pointer, see page 103 in Patterson & Hennessy.
- Line 29 contains the actual addition statement. What MIPS instruction would you have expected.
- Give a complete description of the third column for the ORI instruction in the assembly listing. I.e. instruction format, the value of the MIPS fields.
- Instead of adding 7 we want to subtract 0x98 (hexadecimal!). Modify the assembly code to do this. Provide what you have changed as your answer.
- The last step can be done more convenient by using an immediate statement. Change your program to do this subtraction using an immediate value of 0x98.
- The sw instructions write values into 3 memory locations (a,b,result). What does the ALU do during this sw instruction?
- Explain the function of the sign extender block in the schematic
- Write an assembly program which mimics a walking light pattern of 3 bits in a register (32 bits!!) . Do this in the executer “Program Editor” window using Lab 2 singlecycle mips architecture.
For example if the pattern is 110:
Register value = 00......00000110 Register value = 00......00001100 Register value = 00......00011000 .... Register value = 11......00000000 Register value = 10......00000001 Register value = 00......00000011 ....
- Change the program to allow a change of direction depending on the contents of a register (1 = shift lift, 0 = shift right). Allow different patterns and different shift lengths (more than 32 bits)
- In the early days of computing Binary-coded decimal numbers where used often. Write a small program that converts a hexadecimal encoded number to a binary-coded decimal number.
A clear explanation of BCD code can be found at the wiki page