
Example 2
---------

Here is a very short example program that shows
the load-use interlock (the insertion of a bubble
whenever a load instruction is followed by an 
instruction dependent on the loaded value):

	lw	1, 0, data1	# $1= mem[data1]
	add	2, 1, 1
	halt
data1:	.fill	12345

This assembles to the following machine-code:

a403
0881
e071
3039

When we run it on a pipelined simulator we get the following:

memory[0]=a403
memory[1]=881
memory[2]=e071
memory[3]=3039
4 memory words
	instruction memory:
		instrMem[ 0 ] = lw 1 0 3
		instrMem[ 1 ] = add 2 1 1
		instrMem[ 2 ] = halt
		instrMem[ 3 ] = addi 4 0 57
@@@
state before cycle 0 starts
	pc 0
	data memory:
		dataMem[ 0 ] -23549
		dataMem[ 1 ] 2177
		dataMem[ 2 ] -8079
		dataMem[ 3 ] 12345
	registers:
		reg[ 0 ] 0
		reg[ 1 ] 0
		reg[ 2 ] 0
		reg[ 3 ] 0
		reg[ 4 ] 0
		reg[ 5 ] 0
		reg[ 6 ] 0
		reg[ 7 ] 0
	IFID:
		instruction: nop
		pc 0
	IDEX:
		instruction: nop
		pc 0
		operand0 0
		operand1 0
		operand2 0
	EXMEM:
		instruction: nop
		pc 0
		storeData 0
		aluResult 0
		branchTarget 0
	MEMWB:
		instruction: nop
		pc 0
		writeData 0
	WBEND:
		instruction: nop
		writeData 0
@@@
state before cycle 1 starts
	pc 1
	data memory:
		dataMem[ 0 ] -23549
		dataMem[ 1 ] 2177
		dataMem[ 2 ] -8079
		dataMem[ 3 ] 12345
	registers:
		reg[ 0 ] 0
		reg[ 1 ] 0
		reg[ 2 ] 0
		reg[ 3 ] 0
		reg[ 4 ] 0
		reg[ 5 ] 0
		reg[ 6 ] 0
		reg[ 7 ] 0
	IFID:
		instruction: lw 1 0 3
		pc 0
	IDEX:
		instruction: nop
		pc 0
		operand0 0
		operand1 0
		operand2 0
	EXMEM:
		instruction: nop
		pc 0
		storeData 0
		aluResult 0
		branchTarget 0
	MEMWB:
		instruction: nop
		pc 0
		writeData 0
	WBEND:
		instruction: nop
		writeData 0
@@@
state before cycle 2 starts
	pc 2
	data memory:
		dataMem[ 0 ] -23549
		dataMem[ 1 ] 2177
		dataMem[ 2 ] -8079
		dataMem[ 3 ] 12345
	registers:
		reg[ 0 ] 0
		reg[ 1 ] 0
		reg[ 2 ] 0
		reg[ 3 ] 0
		reg[ 4 ] 0
		reg[ 5 ] 0
		reg[ 6 ] 0
		reg[ 7 ] 0
	IFID:
		instruction: add 2 1 1
		pc 1
	IDEX:
		instruction: lw 1 0 3
		pc 0
		operand0 3
		operand1 0
		operand2 0
	EXMEM:
		instruction: nop
		pc 0
		storeData 0
		aluResult 0
		branchTarget 0
	MEMWB:
		instruction: nop
		pc 0
		writeData 0
	WBEND:
		instruction: nop
		writeData 0
@@@
state before cycle 3 starts
	pc 2
	data memory:
		dataMem[ 0 ] -23549
		dataMem[ 1 ] 2177
		dataMem[ 2 ] -8079
		dataMem[ 3 ] 12345
	registers:
		reg[ 0 ] 0
		reg[ 1 ] 0
		reg[ 2 ] 0
		reg[ 3 ] 0
		reg[ 4 ] 0
		reg[ 5 ] 0
		reg[ 6 ] 0
		reg[ 7 ] 0
	IFID:
		instruction: add 2 1 1
		pc 1
	IDEX:
		instruction: nop
		pc 0
		operand0 0
		operand1 0
		operand2 0
	EXMEM:
		instruction: lw 1 0 3
		pc 0
		storeData 0
		aluResult 3
		branchTarget 0
	MEMWB:
		instruction: nop
		pc 0
		writeData 0
	WBEND:
		instruction: nop
		writeData 0
@@@
state before cycle 4 starts
	pc 3
	data memory:
		dataMem[ 0 ] -23549
		dataMem[ 1 ] 2177
		dataMem[ 2 ] -8079
		dataMem[ 3 ] 12345
	registers:
		reg[ 0 ] 0
		reg[ 1 ] 0
		reg[ 2 ] 0
		reg[ 3 ] 0
		reg[ 4 ] 0
		reg[ 5 ] 0
		reg[ 6 ] 0
		reg[ 7 ] 0
	IFID:
		instruction: halt
		pc 2
	IDEX:
		instruction: add 2 1 1
		pc 1
		operand0 1
		operand1 0
		operand2 0
	EXMEM:
		instruction: nop
		pc 0
		storeData 0
		aluResult 0
		branchTarget 0
	MEMWB:
		instruction: lw 1 0 3
		pc 0
		writeData 12345
	WBEND:
		instruction: nop
		writeData 0
@@@
state before cycle 5 starts
	pc 4
	data memory:
		dataMem[ 0 ] -23549
		dataMem[ 1 ] 2177
		dataMem[ 2 ] -8079
		dataMem[ 3 ] 12345
	registers:
		reg[ 0 ] 0
		reg[ 1 ] 12345
		reg[ 2 ] 0
		reg[ 3 ] 0
		reg[ 4 ] 0
		reg[ 5 ] 0
		reg[ 6 ] 0
		reg[ 7 ] 0
	IFID:
		instruction: addi 4 0 57
		pc 3
	IDEX:
		instruction: halt
		pc 2
		operand0 -15
		operand1 0
		operand2 0
	EXMEM:
		instruction: add 2 1 1
		pc 1
		storeData 12345
		aluResult 24690
		branchTarget 0
	MEMWB:
		instruction: nop
		pc 0
		writeData 0
	WBEND:
		instruction: lw 1 0 3
		writeData 12345
@@@
state before cycle 6 starts
	pc 5
	data memory:
		dataMem[ 0 ] -23549
		dataMem[ 1 ] 2177
		dataMem[ 2 ] -8079
		dataMem[ 3 ] 12345
	registers:
		reg[ 0 ] 0
		reg[ 1 ] 12345
		reg[ 2 ] 0
		reg[ 3 ] 0
		reg[ 4 ] 0
		reg[ 5 ] 0
		reg[ 6 ] 0
		reg[ 7 ] 0
	IFID:
		instruction: nop
		pc 4
	IDEX:
		instruction: addi 4 0 57
		pc 3
		operand0 57
		operand1 0
		operand2 0
	EXMEM:
		instruction: halt
		pc 2
		storeData 0
		aluResult 0
		branchTarget 0
	MEMWB:
		instruction: add 2 1 1
		pc 1
		writeData 24690
	WBEND:
		instruction: nop
		writeData 0
@@@
state before cycle 7 starts
	pc 6
	data memory:
		dataMem[ 0 ] -23549
		dataMem[ 1 ] 2177
		dataMem[ 2 ] -8079
		dataMem[ 3 ] 12345
	registers:
		reg[ 0 ] 0
		reg[ 1 ] 12345
		reg[ 2 ] 24690
		reg[ 3 ] 0
		reg[ 4 ] 0
		reg[ 5 ] 0
		reg[ 6 ] 0
		reg[ 7 ] 0
	IFID:
		instruction: nop
		pc 5
	IDEX:
		instruction: nop
		pc 4
		operand0 0
		operand1 0
		operand2 0
	EXMEM:
		instruction: addi 4 0 57
		pc 3
		storeData 0
		aluResult 57
		branchTarget 0
	MEMWB:
		instruction: halt
		pc 2
		writeData 0
	WBEND:
		instruction: add 2 1 1
		writeData 24690
machine halted
total of 7 cycles executed
