NOTE: This originally had an incorrect date of the 7th

- P&H (4th): Sections 2.7, 2.8. 2.10

a. |
andn $t1, $t2, $t3 |
// bit-wise AND of $t2, !$t3 |

b. |
xnor $t1, $t2, $t3 |
// bit-wise exclusive-NOR of $t2, $t3 (ie. complement of exclusive-OR) |

If

$t2=0x0FAA85AEand

$t3=0xCCDF003C, what is the resulting value in

$t1?

Implement the operations using a

a. |
A = ++B & 4*C[0] |

b. |
A = A ? A^B : C[2] |

c. |
while (A < 10){ C[A] = B + A++; } |

d. |
A += (C[4] = (C[5] + B)/2) |

Assume that the C variables are mapped to the following registers:

A => $s0, B => $s1, C => $s2.

Write a sequence of MIPS instructions for each C statement.

Do question 2.18.5 (both part a and b) from the P&H book

Consider the following MIPS assembly code fragments: a. |
addi $t1, $0, 100 LOOP: lw $s1, 0($s0) add $s2, $s2, $s1 addi $s0, $s0, 4 subi $tl, $tl, 1 bne $t1, $0, LOOP |

b. |
addi $t1, $s0, 400 LOOP: lw $s1, 0($s0) add $s2, $s2, $s1 lw $s1, 4($s0) add $s2, $s2, $s1 addi $s0, $s0, 8 bne $t1, $s0, LOOP |

Translate the loops above into C. Assume that the C-level integer

iis held in register

$t1,

$s2holds the C-level integer called

result, and

$s0holds the base address of the integer

MemArray.

void square(int* x), which squares the value stored in

x. We won't worry about overflow in this exercise.

First, write the C function. Make sure it does not use the multiplication operation (

*), and it is correct for all possible input values.

Write the corresponding MIPS instructions. Assume that

xis mapped to the argument register

$a0. Feel free to use the temporary registers

$t0 - $t7.