Lab 2 Introduction to MIPS instructions

Important: use the singlecycle.sim-pl architecture; NOT the architecture of the previous lab. Assignment 1 ————- The following C program can be (cross)compiled for a MIPS processor:

int a, b, result
int main(){
    a = 0x12345;
    b = 7;
    result = a + b;
    return 1;
}

Note: the 0x12345 means the hexadecimal representation of a number. An assembly listing of this C code contains the following statements:

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?

Explain the first 2 lines of the assembly code. Use the MIPS instruction reference card (either from the book, or several online pdf versions).

What would the third line (sw) do?

Line 29 contains the actual addition statement. There is something strange going on here. What statement would you have expected in this case?

Assignment 2a

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.

Assignment 2b

Load the singlecycle mips architecture in the Executer of SIM-PL. Open in the source window the compiled_addition.wasm file. Step through the program by first compiling the assembly file, press the reset/init button and start by pressing the step button (brown arrow).

Instead of adding 7 we want to subtract 0x98 (hexadecimal!). Modify the assembly code to do this.

Assignment 3

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.

Assignment 4

The sw instruction writes a value into a memory location (a,b,result). What does the ALU do during this sw instruction?

What do you think is the function of the sign extender block in the schematic?

Assignment 5

Write an assembly program directly in the executer source code window for this singlecycle mips architecture which mimics a walking light pattern of 3 bits in a register (32 bits!!):

pattern = 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
....

Assignment 6 (advanced assignment)

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)