CSE 30 -- Lecture 11 -- Nov 6


Assignment 5:

Implement a simulator for the One-Instruction Computer using the MIPS assembly language. Run the OIC multiplication program from assignment 1 on it.

The OIC simulator must emulate the OIC memory array as an array of 3 MIPS words; each OIC word is 3 MIPS words, so you can translate the add-two-numbers program:

		.data
A:		.word 5
B:		.word 6
sum:		.space 1
scr:		.space 1
		.text
add_A_B:	subz scr,scr,next
		subz sum,sum,next
		subz scr,A,next
		subz scr,B,next
		subz sum,scr,next
end:		subz scr,scr,end
into this sequence of .word directives:
	.data
OICmem:	.word 6,6,1		#   mem[0]
	.word 7,7,2		# 	1
	.word 6,8,3		#	2
	.word 6,9,4		#	3
	.word 7,6,5		#	4
	.word 6,6,5		#	5
	.word 0,0,0		#	6 scr
	.word 0,0,0		#	7 sum
	.word 0,0,5		#	8 A
	.word 0,0,6		#	9 B
	.text
main:	# your simulator code goes here
	# ...
You must implement unsigned 96-bit subtraction for the subz instruction and perform inter-word borrows appropriately.

The end: subz scr,scr,end instruction is how you should terminate your OIC program. Your OIC simulator must detect that the PC did not change and terminate. (This is not fully satisfactory if you are using self-modifying OIC code; if you really want to do this right, detect the condition that the PC did not change and that the memory at the PC did not change.)

Note that a borrow occurs when you do a 32-bit unsigned subtraction if the result is larger than the minuend. Both the minuend and the subtrahend is from 0 to 232-1. So when you subtract the subtrahend from the minuend, the furthest you can wrap around 0 is to 1 larger than the minuend itself, so if you compute

	subu $t0, $t1, $t2
and $t0 > $t1 holds afterwards, you know that a borrow occurred, and you'll need to subtract 1 from the next higher base 232 digit.

Alternatively, you could test to see if the subtrahend is larger than the minuend to test to see if a borrow must occur when the subtraction takes place. You should avoid using this method -- while it is perfectly valid for subtraction, it does not extend itself to multiprecision addition, and the test that I gave above does. Make sure you understand how the borrow test I gave you works.

This assignment is due before class next Wednesday via electronic turnin.

You should not try to use labels on the .word directives other than the starting OICmem label. The MIPS assembler translates those labels into numeric addresses, but they will be MIPS addresses, not OIC addresses.

For those of you whose own code doesn't work, didn't take notes when I went over the OIC multiplication assignment during lecture, and can't find the sample solution in the Web pages, here's an example of such code. I almost decided against providing the code again here, since the students who did pay attention, took notes (or got it right themselves), or actually read the Web notes should have an advantage over you.

I also went over some of the problems from the midterm. See the midterm answers.


[ CSE 80 | ACS home | CSE home | CSE calendar | bsy's home page ]
picture of bsy

bsy@cse.ucsd.edu, last updated Mon Nov 11 12:35:13 PST 1996.

email bsy