25 points
1) Write the MIPS assembly for the following function:
char thefunction(char *s)
	{
	char *t = s;
	while ( *s ) { *s = *s + *(s+1); ++s; }
	return(t);
	}

Hint: In C, using the * operator on a pointer dereferences the pointer and gets the actual value stored at that location in memory. For example, in the code above, *s returns the character that is stored at the memory location pointed to by s.

25 points
2) Optimize the following assembly sequence so that it executes in the minimum number of cycles.  Do not unroll the loop (re-arranging / re-writing is fine).  Assume a 5-stage pipelined processor:
	addi	$4, $0, 0
	addi	$5, $0, 10
	lw	$1, 0($2)
loop:
	add	$1, $1, $4
	sw	$1, 0($2)
	addi	$4, $4, 1
	beq	$4, $5, exit
	nop
	j	loop
exit:

25 points
3) Modify the following single-cycle architecture to support a SUBTRACT_AND_BRANCH_IF_WAS_ZERO instruction.  This instruction semantically looks like:
	PC <- Reg[RT] == 0 ? PC + Imm : PC + 4
	Reg[RT] = Reg[RT] - Reg[RS]

25 points
4) Observe the missing forwarding network (highlighted).  Write a code sequence that works on the unmodified machine but produces incorrect results on this modified machine.  Show the moment in time where incorrect results are generated (i.e. which instructions are where in the pipe).