; multiples two unsigned numbers a and b, ; storing result into c. ; ; Bennet Yee, cs30f, Oct 6, 1997. ; ; The input numbers a, b, and output value c ; are stored in memory locations ; 0x100, 0x101, and 0x102 respectively. ; ; The equivalent C code is (roughly) ; ; i = -a; ; t = 0; ; while (i != 0) { ; t = t - b; ; i = i + 1; ; } ; c = -t 0 ; start addr for this file 0xc 0xc 1 ;0 subz i,i,next 0xc 0x100 2 ;1 subz i,a,next i = -a ; In our loop, we will increment ; i until it reaches 0. 0xd 0xd 3 ;2 subz t,t,next t = 0 ; t will accumulate a copies ; of -b. ; loop: 0xc 0xb 7 ;3 subz i,zero,loop_done if (i == 0) we go to loop_done 0xd 0x101 5 ;4 subz t,b,next accumulate -b into t 0xc 0xa 6 ;5 subz i,neg1,next i = i + 1 0xb 0xb 3 ;6 subz zero,zero,loop "unconditionally" goto loop ; loop_done: 0x102 0x102 8 ;7 subz c,c,next 0x102 0xd 9 ;8 subz c,t,next c = -t 0xb 0xb 9 ;9 subz zero,zero,this done ; ; Constants ; 0xffff 0xffff 0xffff ;a: neg1 0 0 0 ;b: zero ; ; Variables ; 0 0 0 ;c: i 0 0 0 ;d: t