/* multiply x and y, storing result in z */
s = 0;
i = -x;
while (i != 0) {
s = add(s,y);
i = i + 1;
}
where add is a function that we call.
Note: there is a bug here -- the result is left in s
and never copied to z; you can fix this yourself.
Here's the code:
mult: subz s,s,next ; s = 0;
subz i,i,next
subz i,x,next ; i = -x;
mloop: subz i,zero,mdone ; while (i != 0) {
; prepare to call add
subz t,t,next ; move s to a
subz t,s,next
subz a,a,next
subz a,t,next
subz t,t,next ; move y to b
subz t,y,next
subz b,b,next
subz b,t,next
subz addret,addret,next
subz addret,retproto,next
subz addret,negretaddr,next
subz t,t,add
retaddr:
subz t,t,next ; move c to s
subz t,c,next
subz s,s,next
subz s,t,next
subz i,neg1,next
subz t,t,mloop ; }
mdone: subz t,t,mdone ; infinite loop to indicate done
;
; Add subroutine
;
add: subz t,t,next ; t = -a-b
subz t,a,next
subz t,b,next
subz c,c,next ; c = -t
subz c,t,next
addret: 0 0 0 ; generated return instr goes here
;
; Data
;
t: 0 0 0
a: 0 0 0
b: 0 0 0
c: 0 0 0
s: 0 0 0
x: 0 0 3 ; inputs, should be elsewhere
y: 0 0 8 ; inputs, should be elsewhere
z: 0 0 0
i: 0 0 0
;
; Constants
;
zero: 0 0 0
neg1: 0xffff 0xffff 0xffff
retproto:
- ( t t 0 )
negretaddr:
-retaddr
This is the symbolic version; let's see what the hand-assembled
version looks like. Click on this with your
middle mouse button. This will open another window with that page so
you can set the two side-by-side and compare.
Write an OIC program that starts execution at address 0 which takes
two input values X and Y at address 0x1000
and 0x1001 respectively, and computes XY,
placing the result in address 0x1002. This program
must call a mult function rather than computing it
in-line. See the Q&A page regarding
00. Also, the input values must be
read-only -- your program should not try to modify the input memory
locations
(I said it in class, but just added the read-only
requirement to the web page).
You should look at mult.oic and mult.inp.oic to see how to separate the inputs from the actual code. You should turn in your program and all of your test inputs. The name of your program file should be exp.oic. Your test cases should be in files named test1.oic, test2,oic etc. If you wish to structure your program into several files, all of them should be named exp*.oic. No extraneous files with the same name pattern should exist. This means that to run your program, doing:
% oic -s 0x1000 -c 3 exp*.oic test1.oicshould work.
This is a multi-file turnin, so you will have to use the tar program (also read the instructions from help turnin).

bsy@cse.ucsd.edu, last updated