;0 mult: subz s,s,next ; s = 0;
;1 subz i,i,next
;2 subz i,x,next ; i = -x;
;3 mloop: subz i,zero,mdone ; while (i != 0) {
; ; prepare to call add
;4 subz t,t,next ; move s to a
;5 subz t,s,next
;6 subz a,a,next
;7 subz a,t,next
;8 subz t,t,next ; move y to b
;9 subz t,y,next
;a subz b,b,next
;b subz b,t,next
;c subz addret,addret,next
;d subz addret,retproto,next
;e subz addret,negretaddr,next
;f subz t,t,add
;retaddr:
;10 subz t,t,next ; move c to s
;11 subz t,c,next
;12 subz s,s,next
;13 subz s,t,next
;14 subz i,neg1,next
;15 subz t,t,mloop ; }
;16 mdone: subz t,t,mdone ; infinite loop to indicate done
;;
;; Add subroutine
;;
;17 add: subz t,t,next ; t = -a-b
;18 subz t,a,next
;19 subz t,b,next
;1a subz c,c,next ; c = -t
;1b subz c,t,next
;1c addret: 0 0 0 ; generated return instr goes here
;;
;; Data
;;
;1d t: 0 0 0
;1e a: 0 0 0
;1f b: 0 0 0
;20 c: 0 0 0
;21 s: 0 0 0
;22 x: 0 0 3 ; inputs, should be elsewhere
;23 y: 0 0 8 ; inputs, should be elsewhere
;24 z: 0 0 0
;25 i: 0 0 0
;;
;; Constants
;;
;26 zero: 0 0 0
;27 neg1: 0xffff 0xffff 0xffff
;28 retproto:
; - ( t t 0 )
;29 negretaddr:
; -retaddr
;
Now, we know the addresses of every instruction and variable, and can
start the assembly process to get the machine
code.

bsy@cse.ucsd.edu, last updated