In: Computer Science
MIPS
a) Consider the C statement: a = (b + d) + (b - c) + (c + d)
Which of the following assembly instructions can be used to replicate all or part of this statement in MIPS, without changing or reducing the equation. Assume variables a, b, c, and d are assigned to registers $s0, $s1, $s2 and $s3 respectively.
1. sub $t0, $s2, $s3
2. sub $t0, $s0, $s3
3. sub $t1, $s1, $s2
4. sub $t2, $s1, $s3
5. add $t2, $s0, $s3
6. add $t0, $s2, $s3
b) Consider the MIPS instruction: add $t0, $s0, $s1. What would the corresponding machine code be? Write your answer in binary, or in hexadecimal with no spaces.
c) Consider the machine code: 1000 1110 0000 1000 0000 0000 0000 0100. What MIPS instruction does this represent?
1. lw $t0, 4($s0)
2. sw $t6, 100($s3)
3. add $t0, $t1, $t2
4. beq $t7, $t8, 68
a) a b c d are assigned to register $s0 $1 $2 $3 respectively
Given a = (b+d) + (b-c) +(c+d)
As in the question it is mentioned that we are not allowed to change or reduce the equation (statement)
1.(c+d) can be calculated using 6. add $t0, $s2, $s3
2.(b-c) can be calculated using 3. sub $t1, $s1, $s2
3.(b+d) can be calculated using add $t2, $s1, $s3 (not present in given 6 statements)
adding and storing content of $t0 $t1 $t2 we can get desired equation
b) add $t0, $s0, $s1
given instruction is register instruction
Register Instruction Format
Opcode | Source 1 | Source 2 | Destination | Shift Amount | Function |
---|---|---|---|---|---|
000000 | 5 bits | 5 bits | 5 bits | 5 bits | 6 bits |
000000 10000 10001 01000 00000 100000 (answer)
RI $s0 $s1 $t0 unused add
RI = register instruction
c) as all the option are having different instruction so just by looking opcode ie we can decide
100011 is opcode (first 6 bit ) which is opcode for load instruction.
so answer is option1 lw $t0, 4($s0)