CSE 30 -- Lecture 3 -- Oct 1


In this lecture, we went over more base conversions and a sample program for the one-instruction computer.

OIC

The oic program is at ../public/bin/oic. Running
% oic -h
will cause the program to print out a short usage message.

The Gauss-sum program is in ../public/oic/sum.oic.

;
; Computes sum from i = 1 to N, where N is stored at memory location
; 0, and the sum will be placed in location 1.
;
; Scratch locations used: 2,3,4
;

;
; i	: 0x2
; j	: 0x3
; k	: 0x4

0x100
0x000100010101	; 0x100		subge sum,sum,next
0x000200020102	; 0x101		subge i,i,next		i = 0
0x0002010c0103	; 0x102	loop:	subge i,$-1,next	i = i + 1
0x000300030104	; 0x103		subge j,j,next
0x000300000105	; 0x104		subge j,N,next		j = -N
0x000400040106	; 0x105		subge k,k,next
0x000400030107	; 0x106		subge k,j,next		k = N
0x000400020109	; 0x107		subge k,i,cont		k = N - i
		;					if (N >= i)
		;					  stay in loop
0x000200020108	; 0x108	done:	subge i,i,done		end
0x00040004010a	; 0x109	cont:	subge k,k,next
0x00040002010b	; 0x10a		subge k,i,next		k = -i
0x000100040102	; 0x10b		subge sum,k,loop	sum = sum - k
		;					    = sum + i;
		;		sum >= 0 must be true, so always
		;		goes to 0x102 (sum < 0 possible only
		;		due to overflow, which we ignore)
0xffffffffffff	; 0x10c					constant -1
and the input data is
0
0x000000000008
to run the program, do (after making a local copy of the .oic files):
% oic -e 0x100 -s 0 -c 5 sum.oic input.oic
Starting program at PC = 256 (0x0100)
End-of-program infinite loop at 264
0000 0000 0008
0000 0000 0024
0000 0000 0000
ffff ffff fff8
ffff ffff ffff
Program completed in 80 (0x50) steps
%
The result of 1+2+...+8 is in memory location 1: 0x24.
[ search CSE | CSE home | bsy's home page | webster i/f | yahoo | hotbot | lycos | altavista ]
picture of bsy

bsy+www@cs.ucsd.edu, last updated Mon Nov 30 21:53:22 PST 1998.

email bsy & tutors


Don't make me hand over my privacy keys!