0x21 0x21 0x1 ;0 mult: subz s,s,next ; s = 0; 0x25 0x25 0x2 ;1 subz i,i,next 0x25 0x22 0x3 ;2 subz i,x,next ; i = -x; 0x25 0x26 0x16 ;3 mloop: subz i,zero,mdone ; while (i != 0) { ; ; prepare to call add 0x1d 0x1d 0x5 ;4 subz t,t,next ; move s to a 0x1d 0x21 0x6 ;5 subz t,s,next 0x1e 0x1e 0x7 ;6 subz a,a,next 0x1e 0x1d 0x8 ;7 subz a,t,next 0x1d 0x1d 0x9 ;8 subz t,t,next ; move y to b 0x1d 0x23 0xa ;9 subz t,y,next 0x1f 0x1f 0xb ;a subz b,b,next 0x1f 0x1d 0xc ;b subz b,t,next 0x1c 0x1c 0xd ;c subz addret,addret,next 0x1c 0x28 0xe ;d subz addret,retproto,next 0x1c 0x29 0xf ;e subz addret,negretaddr,next 0x1d 0x1d 0x17 ;f subz t,t,add ;retaddr: 0x1d 0x1d 0x11 ;10 subz t,t,next ; move c to s 0x1d 0x20 0x12 ;11 subz t,c,next 0x21 0x21 0x13 ;12 subz s,s,next 0x21 0x1d 0x14 ;13 subz s,t,next 0x25 0x27 0x15 ;14 subz i,neg1,next 0x1d 0x1d 0x3 ;15 subz t,t,mloop ; } 0x1d 0x1d 0x16 ;16 mdone: subz t,t,mdone ; infinite loop to indicate done ;; ;; Add subroutine ;; 0x1d 0x1d 0x18 ;17 add: subz t,t,next ; t = -a-b 0x1d 0x1e 0x19 ;18 subz t,a,next 0x1d 0x1f 0x1a ;19 subz t,b,next 0x20 0x20 0x1b ;1a subz c,c,next ; c = -t 0x20 0x1d 0x1c ;1b subz c,t,next 0 0 0 ;1c addret: 0 0 0 ; generated return instr goes here ;; ;; Data ;; 0 0 0 ;1d t: 0 0 0 0 0 0 ;1e a: 0 0 0 0 0 0 ;1f b: 0 0 0 0 0 0 ;20 c: 0 0 0 0 0 0 ;21 s: 0 0 0 0 0 3 ;22 x: 0 0 3 ; inputs, should be elsewhere 0 0 8 ;23 y: 0 0 8 ; inputs, should be elsewhere 0 0 0 ;24 z: 0 0 0 0 0 0 ;25 i: 0 0 0 ;; ;; Constants ;; 0 0 0 ;26 zero: 0 0 0 0xffff 0xffff 0xffff ;27 neg1: 0xffff 0xffff 0xffff ;28 retproto: 0xffe2 0xffe3 0x0000 ; - ( t t 0 ) ;29 negretaddr: 0xffff 0xffff 0xfff0 ; -retaddr (constant was wrong) ;The see now the value in retproto was arrived at, write down
t t 0as
0x001d 0x001d 0x0000and then compute its two's complement (as if it was a 48-bit number). Similarly, negretaddr contains just the two's complement of retaddr.
Voila!
bsy@cse.ucsd.edu, last updated