Home » Recent acquisitions » Acorn ADFS disks » adfs_ArchimedesWorld_15_03.adf » !AcornAns_AcornAns » Flocking/C/s/macros1

Flocking/C/s/macros1

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » Recent acquisitions » Acorn ADFS disks » adfs_ArchimedesWorld_15_03.adf » !AcornAns_AcornAns
Filename: Flocking/C/s/macros1
Read OK:
File size: 21B7 bytes
Load address: 0000
Exec address: 0000
File contents
; rbbc
; Reverse Bit Binary Counter.
; A macro to increment a register according to a reverse bit binary count.
; It takes four parameters, each of which should be a register name.
;
; $r:   holds value to be rbbc incremented. Will be modified
; $k:   k is st k-1=bit # (1 to 31) of msb in register (lsb in rbbc) (thence old w=3*(32-k)).
; $e:   scratch register used to hold an address in the code
;
        MACRO
$label  rbbc    $r, $k, $e

        ASSERT  $r <> $k
        ASSERT  $r <> $e
        ASSERT  $k <> $e

        LCLA    counter
counter SETA    31

$label	RSB	$k, $k, #32
	RSB	$k, $k, $k, ASL #2
	ADD     $e, pc, $k, ASL #2      ;this relys on there being exactly one instruction between here & TST
        MOV     pc, $e

        WHILE   counter > 1
        TST     $r, #1<<counter
        EOR     $r, $r, #1<<counter
        BEQ     %ft0
counter SETA    counter-1
        WEND

        TST     $r, #1<<1
        EOR     $r, $r, #1<<1
        EORNE   $r, $r, #1<<0           ;nb an rbbc carry will automatically cause a wrap around back to zero

0

        MEND



; div16
; assumes abs number < 65536 * abs divisor.
; calculates integer part of 65536*number/divisor, as a signed 32 bit number.
; used in matrix inversion routine where it is necessary to divide two fixed point numbers (16 bit fraction).
; if range check on above assumption is required, the caller must perform it.
; It takes 5 parameters - all register names.
;
; $number:      number
; $divisor:     divisor - sign of divisor may be corrupted
; $num:         scratch & result - may be the same as $number
; $sign:        scratch
; $rem:         scratch
;
        MACRO
$label  div16   $number, $divisor, $num, $sign, $rem

        ASSERT  $num <> $divisor
        ASSERT  $num <> $sign
        ASSERT  $num <> $rem
        ASSERT  $number <> $divisor
        ASSERT  $number <> $sign
        ASSERT  $number <> $rem
        ASSERT  $divisor <> $sign
        ASSERT  $divisor <> $rem
        ASSERT  $sign <> $rem

        LCLA    counter
counter SETA    32

$label  MOVS    $rem, $divisor, LSL #1
        RSBCS   $divisor, $divisor, #0
        ADC     $sign, $sign, $sign             ;1st 3 instructions allow setting of low bit sign as either 0
                                                ;or 1 according to sign of divisor, in only 1 instruction.
        TEQ     $number, #0
        RSBMI   $num, $number, #0
        [       $num <> $number
        MOVPL   $num, $number                   ;only assemble this case if regs different, as is otherwise a nop.
        ]
        EORMI   $sign, $sign, #1

        MOV     $rem, $num, LSR #16
        MOV     $num, $num, LSL #16

        WHILE   counter > 0                     ;unwound loop uses about 600 bytes extra memory
        MOVS    $num, $num, ASL #1              ;speed increase (ARM3) from about 1.27e-5 to .75e-5 seconds
        ADC     $rem, $rem, $rem
        CMP     $rem, $divisor
        SUBHS   $rem, $rem, $divisor
        ORRHS   $num, $num, #1
counter SETA    counter-1
        WEND

        CMP     $rem, $divisor, ASR #1
        ADDGE   $num, $num, #1
        TST     $sign, #1
        RSBNE   $num, $num, #0

        MEND



; mul16
; multiplication of an integer x by a 16-bit fixed point number a, with no restrictions on x or a
; other than that x*a/65536 must fit into a signed 32-bit representation.
; calculates r=x*a/65536
; It takes 6 parameters - all register names.
;
; $x:   x
; $a:   a - a will be corrupted
; $r:   result - may be the same as $x
; $u:   scratch
; $v:   scratch
; $w:   scratch
;
        MACRO
$label  mul16   $x, $a, $r, $u, $v, $w

        ASSERT  $r <> $a
        ASSERT  $r <> $u
        ASSERT  $r <> $v
        ASSERT  $r <> $w
        ASSERT  $x <> $a
        ASSERT  $x <> $u
        ASSERT  $x <> $v
        ASSERT  $x <> $w
        ASSERT  $a <> $u
        ASSERT  $a <> $v
        ASSERT  $a <> $w
        ASSERT  $u <> $v
        ASSERT  $u <> $w
        ASSERT  $v <> $w

$label  MOVS    $w, $a, LSL #1
        RSBCS   $a, $a, #0
        TEQ     $x, #0
        RSBMI   $r, $x, #0
        [       $r <> $x
        MOVPL   $r, $x
        ]                       ;now have C bit set iff a<0, N bit set iff x<0
        MOV     $w, pc, LSR #31
        MOV     $w, $w, LSL #28 ;get w=(2^28)*N {N is b31, V is b28, C is b29 in pc/psr}
        TEQP    $w, pc, LSR #1  ;EOR w into pc/psr {ie N EOR C is put into V}  - this is a way of storing
                                ;sign of result in overflow flag, saving on a register
        MOV     $w, $r, LSR #16
        BIC     $r, $r, $w, LSL #16
        MOV     $v, $a, LSR #16
        BIC     $a, $a, $v, LSL #16
        MUL     $u, $a, $r
        TST     $u, #1<<15      ;notice this is the only operation altering psr & that it will not corrupt V
                                ;note it will corrupt C, as immediate operand 32768 requires a shift
        MOV     $u, $u, LSR #16
        ADDNE   $u, $u, #1
        MLA     $u, $r, $v, $u	;6/9/94 - reverse v & r to optimise for argument a small
        MLA     $u, $a, $w, $u
        MUL     $r, $w, $v	;6/9/94 - reverse v & w to optimise for argument a small
        ADD     $r, $u, $r, LSL #16
        RSBVS   $r, $r, #0

        MEND



; mul16c
; multiplication of an integer x by a 16-bit fixed point number a, where a is a contraction
; ie calculates r=x*a/65536, assuming: abs a < 65536
; if the possibility exists that a>=65536, caller should check this & either not call routine, or set a=65535
; It takes 4 parameters - all register names.
;
; $x:   x
; $a:   a - require abs a <65536, a will be corrupted
; $r:   result - may be the same as $x
; $w:   scratch
;
        MACRO
$label  mul16c  $x, $a, $r, $w

        ASSERT  $r <> $a
        ASSERT  $r <> $w
        ASSERT  $x <> $a
        ASSERT  $x <> $w
        ASSERT  $a <> $w

$label  MOVS    $w, $a, LSL #1
        RSBCS   $a, $a, #0
        TEQ     $x, #0
        RSBMI   $r, $x, #0
        [       $r <> $x
        MOVPL   $r, $x
        ]
        MOV     $w, pc, LSR #31 ;see mul16 above, for comments re this part
        MOV     $w, $w, LSL #28
        TEQP    $w, pc, LSR #1

        TST     $a, #1<<16      ;bodge to allow code to function if $a is upto 2*65536-1
        MOVNE   $r, $r, LSL #1  ;can occur in a contractive fn due to change of coordinates to handle 1x2 pixel aspect ratio
        MOVNE   $a, $a, LSR #1  ;change made 3/4/94 - estimate overhead to ria of upto 3%

        MOV     $w, $r, LSR #16
        BIC     $r, $r, $w, LSL #16
        MUL     $r, $a, $r
        TST     $r, #1<<15      ;remember, can't use movs r,r,lsr #16, as this would corrupt V, which is storing sign of result
        MOV     $r, $r, LSR #16
        ADDNE   $r, $r, #1
        MLA     $r, $a, $w, $r

        RSBVS   $r, $r, #0

        MEND



; sqrt16
; integer square root returning 16-bit fixed point number, assuming x is 16-bit fixed point
; ie returns sqrt(x<<16)
; It takes 6 parameters - all register names
;
; $x:   x
; $r:   result - may be the same as x
; $n:   copy of x used during calculation
; $t:   transient scratch
; $d:   remainder
; $o:   constant value of 1
;
        MACRO
$label  sqrt16  $x, $r, $n, $t, $d, $o

        ASSERT  $x <> $n
        ASSERT  $x <> $t
        ASSERT  $x <> $d
        ASSERT  $x <> $o
        ASSERT  $n <> $t
        ASSERT  $n <> $d
        ASSERT  $n <> $o
        ASSERT  $t <> $d
        ASSERT  $t <> $o
        ASSERT  $d <> $o

        LCLA    counter

$label  MOV     $n, $x
        MOV     $o, #1
        MOV     $x, #0
        MOV     $d, #0

        AND     $t, $n, #(3<<30)
        MOV     $t, $t, LSR #30
        ORR     $d, $d, $t
        ADD     $t, $o, $x, LSL #1
        CMP     $d, $t
        SUBGE   $d, $d, $t
        ADDGE   $x, $x, #1

counter SETA    28
        WHILE   counter < 32             ;want >= 0, however counter is unsigned, so after 0 it goes high, thus < 32 will catch it!
        MOV     $x, $x, LSL #1
        MOV     $d, $d, LSL #2
        AND     $t, $n, #(3<<counter)
        [       counter <> 0
        MOV     $t, $t, LSR #counter
        ]
        ORR     $d, $d, $t
        ADD     $t, $o, $x, LSL #1
        CMP     $d, $t
        SUBGE   $d, $d, $t
        ADDGE   $x, $x, #1
counter SETA    counter-2
        WEND

counter SETA    14
        WHILE   counter < 32
        MOV     $x, $x, LSL #1
        MOV     $d, $d, LSL #2
        ADD     $t, $o, $x, LSL #1
        CMP     $d, $t
        SUBGE   $d, $d, $t
        ADDGE   $x, $x, #1
counter SETA    counter-2
        WEND

        [       $r <> $x
        MOV     $r, $x
        ]

        MEND



        END
00000000  3b 20 72 62 62 63 0a 3b  20 52 65 76 65 72 73 65  |; rbbc.; Reverse|
00000010  20 42 69 74 20 42 69 6e  61 72 79 20 43 6f 75 6e  | Bit Binary Coun|
00000020  74 65 72 2e 0a 3b 20 41  20 6d 61 63 72 6f 20 74  |ter..; A macro t|
00000030  6f 20 69 6e 63 72 65 6d  65 6e 74 20 61 20 72 65  |o increment a re|
00000040  67 69 73 74 65 72 20 61  63 63 6f 72 64 69 6e 67  |gister according|
00000050  20 74 6f 20 61 20 72 65  76 65 72 73 65 20 62 69  | to a reverse bi|
00000060  74 20 62 69 6e 61 72 79  20 63 6f 75 6e 74 2e 0a  |t binary count..|
00000070  3b 20 49 74 20 74 61 6b  65 73 20 66 6f 75 72 20  |; It takes four |
00000080  70 61 72 61 6d 65 74 65  72 73 2c 20 65 61 63 68  |parameters, each|
00000090  20 6f 66 20 77 68 69 63  68 20 73 68 6f 75 6c 64  | of which should|
000000a0  20 62 65 20 61 20 72 65  67 69 73 74 65 72 20 6e  | be a register n|
000000b0  61 6d 65 2e 0a 3b 0a 3b  20 24 72 3a 20 20 20 68  |ame..;.; $r:   h|
000000c0  6f 6c 64 73 20 76 61 6c  75 65 20 74 6f 20 62 65  |olds value to be|
000000d0  20 72 62 62 63 20 69 6e  63 72 65 6d 65 6e 74 65  | rbbc incremente|
000000e0  64 2e 20 57 69 6c 6c 20  62 65 20 6d 6f 64 69 66  |d. Will be modif|
000000f0  69 65 64 0a 3b 20 24 6b  3a 20 20 20 6b 20 69 73  |ied.; $k:   k is|
00000100  20 73 74 20 6b 2d 31 3d  62 69 74 20 23 20 28 31  | st k-1=bit # (1|
00000110  20 74 6f 20 33 31 29 20  6f 66 20 6d 73 62 20 69  | to 31) of msb i|
00000120  6e 20 72 65 67 69 73 74  65 72 20 28 6c 73 62 20  |n register (lsb |
00000130  69 6e 20 72 62 62 63 29  20 28 74 68 65 6e 63 65  |in rbbc) (thence|
00000140  20 6f 6c 64 20 77 3d 33  2a 28 33 32 2d 6b 29 29  | old w=3*(32-k))|
00000150  2e 0a 3b 20 24 65 3a 20  20 20 73 63 72 61 74 63  |..; $e:   scratc|
00000160  68 20 72 65 67 69 73 74  65 72 20 75 73 65 64 20  |h register used |
00000170  74 6f 20 68 6f 6c 64 20  61 6e 20 61 64 64 72 65  |to hold an addre|
00000180  73 73 20 69 6e 20 74 68  65 20 63 6f 64 65 0a 3b  |ss in the code.;|
00000190  0a 20 20 20 20 20 20 20  20 4d 41 43 52 4f 0a 24  |.        MACRO.$|
000001a0  6c 61 62 65 6c 20 20 72  62 62 63 20 20 20 20 24  |label  rbbc    $|
000001b0  72 2c 20 24 6b 2c 20 24  65 0a 0a 20 20 20 20 20  |r, $k, $e..     |
000001c0  20 20 20 41 53 53 45 52  54 20 20 24 72 20 3c 3e  |   ASSERT  $r <>|
000001d0  20 24 6b 0a 20 20 20 20  20 20 20 20 41 53 53 45  | $k.        ASSE|
000001e0  52 54 20 20 24 72 20 3c  3e 20 24 65 0a 20 20 20  |RT  $r <> $e.   |
000001f0  20 20 20 20 20 41 53 53  45 52 54 20 20 24 6b 20  |     ASSERT  $k |
00000200  3c 3e 20 24 65 0a 0a 20  20 20 20 20 20 20 20 4c  |<> $e..        L|
00000210  43 4c 41 20 20 20 20 63  6f 75 6e 74 65 72 0a 63  |CLA    counter.c|
00000220  6f 75 6e 74 65 72 20 53  45 54 41 20 20 20 20 33  |ounter SETA    3|
00000230  31 0a 0a 24 6c 61 62 65  6c 09 52 53 42 09 24 6b  |1..$label.RSB.$k|
00000240  2c 20 24 6b 2c 20 23 33  32 0a 09 52 53 42 09 24  |, $k, #32..RSB.$|
00000250  6b 2c 20 24 6b 2c 20 24  6b 2c 20 41 53 4c 20 23  |k, $k, $k, ASL #|
00000260  32 0a 09 41 44 44 20 20  20 20 20 24 65 2c 20 70  |2..ADD     $e, p|
00000270  63 2c 20 24 6b 2c 20 41  53 4c 20 23 32 20 20 20  |c, $k, ASL #2   |
00000280  20 20 20 3b 74 68 69 73  20 72 65 6c 79 73 20 6f  |   ;this relys o|
00000290  6e 20 74 68 65 72 65 20  62 65 69 6e 67 20 65 78  |n there being ex|
000002a0  61 63 74 6c 79 20 6f 6e  65 20 69 6e 73 74 72 75  |actly one instru|
000002b0  63 74 69 6f 6e 20 62 65  74 77 65 65 6e 20 68 65  |ction between he|
000002c0  72 65 20 26 20 54 53 54  0a 20 20 20 20 20 20 20  |re & TST.       |
000002d0  20 4d 4f 56 20 20 20 20  20 70 63 2c 20 24 65 0a  | MOV     pc, $e.|
000002e0  0a 20 20 20 20 20 20 20  20 57 48 49 4c 45 20 20  |.        WHILE  |
000002f0  20 63 6f 75 6e 74 65 72  20 3e 20 31 0a 20 20 20  | counter > 1.   |
00000300  20 20 20 20 20 54 53 54  20 20 20 20 20 24 72 2c  |     TST     $r,|
00000310  20 23 31 3c 3c 63 6f 75  6e 74 65 72 0a 20 20 20  | #1<<counter.   |
00000320  20 20 20 20 20 45 4f 52  20 20 20 20 20 24 72 2c  |     EOR     $r,|
00000330  20 24 72 2c 20 23 31 3c  3c 63 6f 75 6e 74 65 72  | $r, #1<<counter|
00000340  0a 20 20 20 20 20 20 20  20 42 45 51 20 20 20 20  |.        BEQ    |
00000350  20 25 66 74 30 0a 63 6f  75 6e 74 65 72 20 53 45  | %ft0.counter SE|
00000360  54 41 20 20 20 20 63 6f  75 6e 74 65 72 2d 31 0a  |TA    counter-1.|
00000370  20 20 20 20 20 20 20 20  57 45 4e 44 0a 0a 20 20  |        WEND..  |
00000380  20 20 20 20 20 20 54 53  54 20 20 20 20 20 24 72  |      TST     $r|
00000390  2c 20 23 31 3c 3c 31 0a  20 20 20 20 20 20 20 20  |, #1<<1.        |
000003a0  45 4f 52 20 20 20 20 20  24 72 2c 20 24 72 2c 20  |EOR     $r, $r, |
000003b0  23 31 3c 3c 31 0a 20 20  20 20 20 20 20 20 45 4f  |#1<<1.        EO|
000003c0  52 4e 45 20 20 20 24 72  2c 20 24 72 2c 20 23 31  |RNE   $r, $r, #1|
000003d0  3c 3c 30 20 20 20 20 20  20 20 20 20 20 20 3b 6e  |<<0           ;n|
000003e0  62 20 61 6e 20 72 62 62  63 20 63 61 72 72 79 20  |b an rbbc carry |
000003f0  77 69 6c 6c 20 61 75 74  6f 6d 61 74 69 63 61 6c  |will automatical|
00000400  6c 79 20 63 61 75 73 65  20 61 20 77 72 61 70 20  |ly cause a wrap |
00000410  61 72 6f 75 6e 64 20 62  61 63 6b 20 74 6f 20 7a  |around back to z|
00000420  65 72 6f 0a 0a 30 0a 0a  20 20 20 20 20 20 20 20  |ero..0..        |
00000430  4d 45 4e 44 0a 0a 0a 0a  3b 20 64 69 76 31 36 0a  |MEND....; div16.|
00000440  3b 20 61 73 73 75 6d 65  73 20 61 62 73 20 6e 75  |; assumes abs nu|
00000450  6d 62 65 72 20 3c 20 36  35 35 33 36 20 2a 20 61  |mber < 65536 * a|
00000460  62 73 20 64 69 76 69 73  6f 72 2e 0a 3b 20 63 61  |bs divisor..; ca|
00000470  6c 63 75 6c 61 74 65 73  20 69 6e 74 65 67 65 72  |lculates integer|
00000480  20 70 61 72 74 20 6f 66  20 36 35 35 33 36 2a 6e  | part of 65536*n|
00000490  75 6d 62 65 72 2f 64 69  76 69 73 6f 72 2c 20 61  |umber/divisor, a|
000004a0  73 20 61 20 73 69 67 6e  65 64 20 33 32 20 62 69  |s a signed 32 bi|
000004b0  74 20 6e 75 6d 62 65 72  2e 0a 3b 20 75 73 65 64  |t number..; used|
000004c0  20 69 6e 20 6d 61 74 72  69 78 20 69 6e 76 65 72  | in matrix inver|
000004d0  73 69 6f 6e 20 72 6f 75  74 69 6e 65 20 77 68 65  |sion routine whe|
000004e0  72 65 20 69 74 20 69 73  20 6e 65 63 65 73 73 61  |re it is necessa|
000004f0  72 79 20 74 6f 20 64 69  76 69 64 65 20 74 77 6f  |ry to divide two|
00000500  20 66 69 78 65 64 20 70  6f 69 6e 74 20 6e 75 6d  | fixed point num|
00000510  62 65 72 73 20 28 31 36  20 62 69 74 20 66 72 61  |bers (16 bit fra|
00000520  63 74 69 6f 6e 29 2e 0a  3b 20 69 66 20 72 61 6e  |ction)..; if ran|
00000530  67 65 20 63 68 65 63 6b  20 6f 6e 20 61 62 6f 76  |ge check on abov|
00000540  65 20 61 73 73 75 6d 70  74 69 6f 6e 20 69 73 20  |e assumption is |
00000550  72 65 71 75 69 72 65 64  2c 20 74 68 65 20 63 61  |required, the ca|
00000560  6c 6c 65 72 20 6d 75 73  74 20 70 65 72 66 6f 72  |ller must perfor|
00000570  6d 20 69 74 2e 0a 3b 20  49 74 20 74 61 6b 65 73  |m it..; It takes|
00000580  20 35 20 70 61 72 61 6d  65 74 65 72 73 20 2d 20  | 5 parameters - |
00000590  61 6c 6c 20 72 65 67 69  73 74 65 72 20 6e 61 6d  |all register nam|
000005a0  65 73 2e 0a 3b 0a 3b 20  24 6e 75 6d 62 65 72 3a  |es..;.; $number:|
000005b0  20 20 20 20 20 20 6e 75  6d 62 65 72 0a 3b 20 24  |      number.; $|
000005c0  64 69 76 69 73 6f 72 3a  20 20 20 20 20 64 69 76  |divisor:     div|
000005d0  69 73 6f 72 20 2d 20 73  69 67 6e 20 6f 66 20 64  |isor - sign of d|
000005e0  69 76 69 73 6f 72 20 6d  61 79 20 62 65 20 63 6f  |ivisor may be co|
000005f0  72 72 75 70 74 65 64 0a  3b 20 24 6e 75 6d 3a 20  |rrupted.; $num: |
00000600  20 20 20 20 20 20 20 20  73 63 72 61 74 63 68 20  |        scratch |
00000610  26 20 72 65 73 75 6c 74  20 2d 20 6d 61 79 20 62  |& result - may b|
00000620  65 20 74 68 65 20 73 61  6d 65 20 61 73 20 24 6e  |e the same as $n|
00000630  75 6d 62 65 72 0a 3b 20  24 73 69 67 6e 3a 20 20  |umber.; $sign:  |
00000640  20 20 20 20 20 20 73 63  72 61 74 63 68 0a 3b 20  |      scratch.; |
00000650  24 72 65 6d 3a 20 20 20  20 20 20 20 20 20 73 63  |$rem:         sc|
00000660  72 61 74 63 68 0a 3b 0a  20 20 20 20 20 20 20 20  |ratch.;.        |
00000670  4d 41 43 52 4f 0a 24 6c  61 62 65 6c 20 20 64 69  |MACRO.$label  di|
00000680  76 31 36 20 20 20 24 6e  75 6d 62 65 72 2c 20 24  |v16   $number, $|
00000690  64 69 76 69 73 6f 72 2c  20 24 6e 75 6d 2c 20 24  |divisor, $num, $|
000006a0  73 69 67 6e 2c 20 24 72  65 6d 0a 0a 20 20 20 20  |sign, $rem..    |
000006b0  20 20 20 20 41 53 53 45  52 54 20 20 24 6e 75 6d  |    ASSERT  $num|
000006c0  20 3c 3e 20 24 64 69 76  69 73 6f 72 0a 20 20 20  | <> $divisor.   |
000006d0  20 20 20 20 20 41 53 53  45 52 54 20 20 24 6e 75  |     ASSERT  $nu|
000006e0  6d 20 3c 3e 20 24 73 69  67 6e 0a 20 20 20 20 20  |m <> $sign.     |
000006f0  20 20 20 41 53 53 45 52  54 20 20 24 6e 75 6d 20  |   ASSERT  $num |
00000700  3c 3e 20 24 72 65 6d 0a  20 20 20 20 20 20 20 20  |<> $rem.        |
00000710  41 53 53 45 52 54 20 20  24 6e 75 6d 62 65 72 20  |ASSERT  $number |
00000720  3c 3e 20 24 64 69 76 69  73 6f 72 0a 20 20 20 20  |<> $divisor.    |
00000730  20 20 20 20 41 53 53 45  52 54 20 20 24 6e 75 6d  |    ASSERT  $num|
00000740  62 65 72 20 3c 3e 20 24  73 69 67 6e 0a 20 20 20  |ber <> $sign.   |
00000750  20 20 20 20 20 41 53 53  45 52 54 20 20 24 6e 75  |     ASSERT  $nu|
00000760  6d 62 65 72 20 3c 3e 20  24 72 65 6d 0a 20 20 20  |mber <> $rem.   |
00000770  20 20 20 20 20 41 53 53  45 52 54 20 20 24 64 69  |     ASSERT  $di|
00000780  76 69 73 6f 72 20 3c 3e  20 24 73 69 67 6e 0a 20  |visor <> $sign. |
00000790  20 20 20 20 20 20 20 41  53 53 45 52 54 20 20 24  |       ASSERT  $|
000007a0  64 69 76 69 73 6f 72 20  3c 3e 20 24 72 65 6d 0a  |divisor <> $rem.|
000007b0  20 20 20 20 20 20 20 20  41 53 53 45 52 54 20 20  |        ASSERT  |
000007c0  24 73 69 67 6e 20 3c 3e  20 24 72 65 6d 0a 0a 20  |$sign <> $rem.. |
000007d0  20 20 20 20 20 20 20 4c  43 4c 41 20 20 20 20 63  |       LCLA    c|
000007e0  6f 75 6e 74 65 72 0a 63  6f 75 6e 74 65 72 20 53  |ounter.counter S|
000007f0  45 54 41 20 20 20 20 33  32 0a 0a 24 6c 61 62 65  |ETA    32..$labe|
00000800  6c 20 20 4d 4f 56 53 20  20 20 20 24 72 65 6d 2c  |l  MOVS    $rem,|
00000810  20 24 64 69 76 69 73 6f  72 2c 20 4c 53 4c 20 23  | $divisor, LSL #|
00000820  31 0a 20 20 20 20 20 20  20 20 52 53 42 43 53 20  |1.        RSBCS |
00000830  20 20 24 64 69 76 69 73  6f 72 2c 20 24 64 69 76  |  $divisor, $div|
00000840  69 73 6f 72 2c 20 23 30  0a 20 20 20 20 20 20 20  |isor, #0.       |
00000850  20 41 44 43 20 20 20 20  20 24 73 69 67 6e 2c 20  | ADC     $sign, |
00000860  24 73 69 67 6e 2c 20 24  73 69 67 6e 20 20 20 20  |$sign, $sign    |
00000870  20 20 20 20 20 20 20 20  20 3b 31 73 74 20 33 20  |         ;1st 3 |
00000880  69 6e 73 74 72 75 63 74  69 6f 6e 73 20 61 6c 6c  |instructions all|
00000890  6f 77 20 73 65 74 74 69  6e 67 20 6f 66 20 6c 6f  |ow setting of lo|
000008a0  77 20 62 69 74 20 73 69  67 6e 20 61 73 20 65 69  |w bit sign as ei|
000008b0  74 68 65 72 20 30 0a 20  20 20 20 20 20 20 20 20  |ther 0.         |
000008c0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
000008e0  20 20 20 20 20 20 20 3b  6f 72 20 31 20 61 63 63  |       ;or 1 acc|
000008f0  6f 72 64 69 6e 67 20 74  6f 20 73 69 67 6e 20 6f  |ording to sign o|
00000900  66 20 64 69 76 69 73 6f  72 2c 20 69 6e 20 6f 6e  |f divisor, in on|
00000910  6c 79 20 31 20 69 6e 73  74 72 75 63 74 69 6f 6e  |ly 1 instruction|
00000920  2e 0a 20 20 20 20 20 20  20 20 54 45 51 20 20 20  |..        TEQ   |
00000930  20 20 24 6e 75 6d 62 65  72 2c 20 23 30 0a 20 20  |  $number, #0.  |
00000940  20 20 20 20 20 20 52 53  42 4d 49 20 20 20 24 6e  |      RSBMI   $n|
00000950  75 6d 2c 20 24 6e 75 6d  62 65 72 2c 20 23 30 0a  |um, $number, #0.|
00000960  20 20 20 20 20 20 20 20  5b 20 20 20 20 20 20 20  |        [       |
00000970  24 6e 75 6d 20 3c 3e 20  24 6e 75 6d 62 65 72 0a  |$num <> $number.|
00000980  20 20 20 20 20 20 20 20  4d 4f 56 50 4c 20 20 20  |        MOVPL   |
00000990  24 6e 75 6d 2c 20 24 6e  75 6d 62 65 72 20 20 20  |$num, $number   |
000009a0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000009b0  3b 6f 6e 6c 79 20 61 73  73 65 6d 62 6c 65 20 74  |;only assemble t|
000009c0  68 69 73 20 63 61 73 65  20 69 66 20 72 65 67 73  |his case if regs|
000009d0  20 64 69 66 66 65 72 65  6e 74 2c 20 61 73 20 69  | different, as i|
000009e0  73 20 6f 74 68 65 72 77  69 73 65 20 61 20 6e 6f  |s otherwise a no|
000009f0  70 2e 0a 20 20 20 20 20  20 20 20 5d 0a 20 20 20  |p..        ].   |
00000a00  20 20 20 20 20 45 4f 52  4d 49 20 20 20 24 73 69  |     EORMI   $si|
00000a10  67 6e 2c 20 24 73 69 67  6e 2c 20 23 31 0a 0a 20  |gn, $sign, #1.. |
00000a20  20 20 20 20 20 20 20 4d  4f 56 20 20 20 20 20 24  |       MOV     $|
00000a30  72 65 6d 2c 20 24 6e 75  6d 2c 20 4c 53 52 20 23  |rem, $num, LSR #|
00000a40  31 36 0a 20 20 20 20 20  20 20 20 4d 4f 56 20 20  |16.        MOV  |
00000a50  20 20 20 24 6e 75 6d 2c  20 24 6e 75 6d 2c 20 4c  |   $num, $num, L|
00000a60  53 4c 20 23 31 36 0a 0a  20 20 20 20 20 20 20 20  |SL #16..        |
00000a70  57 48 49 4c 45 20 20 20  63 6f 75 6e 74 65 72 20  |WHILE   counter |
00000a80  3e 20 30 20 20 20 20 20  20 20 20 20 20 20 20 20  |> 0             |
00000a90  20 20 20 20 20 20 20 20  3b 75 6e 77 6f 75 6e 64  |        ;unwound|
00000aa0  20 6c 6f 6f 70 20 75 73  65 73 20 61 62 6f 75 74  | loop uses about|
00000ab0  20 36 30 30 20 62 79 74  65 73 20 65 78 74 72 61  | 600 bytes extra|
00000ac0  20 6d 65 6d 6f 72 79 0a  20 20 20 20 20 20 20 20  | memory.        |
00000ad0  4d 4f 56 53 20 20 20 20  24 6e 75 6d 2c 20 24 6e  |MOVS    $num, $n|
00000ae0  75 6d 2c 20 41 53 4c 20  23 31 20 20 20 20 20 20  |um, ASL #1      |
00000af0  20 20 20 20 20 20 20 20  3b 73 70 65 65 64 20 69  |        ;speed i|
00000b00  6e 63 72 65 61 73 65 20  28 41 52 4d 33 29 20 66  |ncrease (ARM3) f|
00000b10  72 6f 6d 20 61 62 6f 75  74 20 31 2e 32 37 65 2d  |rom about 1.27e-|
00000b20  35 20 74 6f 20 2e 37 35  65 2d 35 20 73 65 63 6f  |5 to .75e-5 seco|
00000b30  6e 64 73 0a 20 20 20 20  20 20 20 20 41 44 43 20  |nds.        ADC |
00000b40  20 20 20 20 24 72 65 6d  2c 20 24 72 65 6d 2c 20  |    $rem, $rem, |
00000b50  24 72 65 6d 0a 20 20 20  20 20 20 20 20 43 4d 50  |$rem.        CMP|
00000b60  20 20 20 20 20 24 72 65  6d 2c 20 24 64 69 76 69  |     $rem, $divi|
00000b70  73 6f 72 0a 20 20 20 20  20 20 20 20 53 55 42 48  |sor.        SUBH|
00000b80  53 20 20 20 24 72 65 6d  2c 20 24 72 65 6d 2c 20  |S   $rem, $rem, |
00000b90  24 64 69 76 69 73 6f 72  0a 20 20 20 20 20 20 20  |$divisor.       |
00000ba0  20 4f 52 52 48 53 20 20  20 24 6e 75 6d 2c 20 24  | ORRHS   $num, $|
00000bb0  6e 75 6d 2c 20 23 31 0a  63 6f 75 6e 74 65 72 20  |num, #1.counter |
00000bc0  53 45 54 41 20 20 20 20  63 6f 75 6e 74 65 72 2d  |SETA    counter-|
00000bd0  31 0a 20 20 20 20 20 20  20 20 57 45 4e 44 0a 0a  |1.        WEND..|
00000be0  20 20 20 20 20 20 20 20  43 4d 50 20 20 20 20 20  |        CMP     |
00000bf0  24 72 65 6d 2c 20 24 64  69 76 69 73 6f 72 2c 20  |$rem, $divisor, |
00000c00  41 53 52 20 23 31 0a 20  20 20 20 20 20 20 20 41  |ASR #1.        A|
00000c10  44 44 47 45 20 20 20 24  6e 75 6d 2c 20 24 6e 75  |DDGE   $num, $nu|
00000c20  6d 2c 20 23 31 0a 20 20  20 20 20 20 20 20 54 53  |m, #1.        TS|
00000c30  54 20 20 20 20 20 24 73  69 67 6e 2c 20 23 31 0a  |T     $sign, #1.|
00000c40  20 20 20 20 20 20 20 20  52 53 42 4e 45 20 20 20  |        RSBNE   |
00000c50  24 6e 75 6d 2c 20 24 6e  75 6d 2c 20 23 30 0a 0a  |$num, $num, #0..|
00000c60  20 20 20 20 20 20 20 20  4d 45 4e 44 0a 0a 0a 0a  |        MEND....|
00000c70  3b 20 6d 75 6c 31 36 0a  3b 20 6d 75 6c 74 69 70  |; mul16.; multip|
00000c80  6c 69 63 61 74 69 6f 6e  20 6f 66 20 61 6e 20 69  |lication of an i|
00000c90  6e 74 65 67 65 72 20 78  20 62 79 20 61 20 31 36  |nteger x by a 16|
00000ca0  2d 62 69 74 20 66 69 78  65 64 20 70 6f 69 6e 74  |-bit fixed point|
00000cb0  20 6e 75 6d 62 65 72 20  61 2c 20 77 69 74 68 20  | number a, with |
00000cc0  6e 6f 20 72 65 73 74 72  69 63 74 69 6f 6e 73 20  |no restrictions |
00000cd0  6f 6e 20 78 20 6f 72 20  61 0a 3b 20 6f 74 68 65  |on x or a.; othe|
00000ce0  72 20 74 68 61 6e 20 74  68 61 74 20 78 2a 61 2f  |r than that x*a/|
00000cf0  36 35 35 33 36 20 6d 75  73 74 20 66 69 74 20 69  |65536 must fit i|
00000d00  6e 74 6f 20 61 20 73 69  67 6e 65 64 20 33 32 2d  |nto a signed 32-|
00000d10  62 69 74 20 72 65 70 72  65 73 65 6e 74 61 74 69  |bit representati|
00000d20  6f 6e 2e 0a 3b 20 63 61  6c 63 75 6c 61 74 65 73  |on..; calculates|
00000d30  20 72 3d 78 2a 61 2f 36  35 35 33 36 0a 3b 20 49  | r=x*a/65536.; I|
00000d40  74 20 74 61 6b 65 73 20  36 20 70 61 72 61 6d 65  |t takes 6 parame|
00000d50  74 65 72 73 20 2d 20 61  6c 6c 20 72 65 67 69 73  |ters - all regis|
00000d60  74 65 72 20 6e 61 6d 65  73 2e 0a 3b 0a 3b 20 24  |ter names..;.; $|
00000d70  78 3a 20 20 20 78 0a 3b  20 24 61 3a 20 20 20 61  |x:   x.; $a:   a|
00000d80  20 2d 20 61 20 77 69 6c  6c 20 62 65 20 63 6f 72  | - a will be cor|
00000d90  72 75 70 74 65 64 0a 3b  20 24 72 3a 20 20 20 72  |rupted.; $r:   r|
00000da0  65 73 75 6c 74 20 2d 20  6d 61 79 20 62 65 20 74  |esult - may be t|
00000db0  68 65 20 73 61 6d 65 20  61 73 20 24 78 0a 3b 20  |he same as $x.; |
00000dc0  24 75 3a 20 20 20 73 63  72 61 74 63 68 0a 3b 20  |$u:   scratch.; |
00000dd0  24 76 3a 20 20 20 73 63  72 61 74 63 68 0a 3b 20  |$v:   scratch.; |
00000de0  24 77 3a 20 20 20 73 63  72 61 74 63 68 0a 3b 0a  |$w:   scratch.;.|
00000df0  20 20 20 20 20 20 20 20  4d 41 43 52 4f 0a 24 6c  |        MACRO.$l|
00000e00  61 62 65 6c 20 20 6d 75  6c 31 36 20 20 20 24 78  |abel  mul16   $x|
00000e10  2c 20 24 61 2c 20 24 72  2c 20 24 75 2c 20 24 76  |, $a, $r, $u, $v|
00000e20  2c 20 24 77 0a 0a 20 20  20 20 20 20 20 20 41 53  |, $w..        AS|
00000e30  53 45 52 54 20 20 24 72  20 3c 3e 20 24 61 0a 20  |SERT  $r <> $a. |
00000e40  20 20 20 20 20 20 20 41  53 53 45 52 54 20 20 24  |       ASSERT  $|
00000e50  72 20 3c 3e 20 24 75 0a  20 20 20 20 20 20 20 20  |r <> $u.        |
00000e60  41 53 53 45 52 54 20 20  24 72 20 3c 3e 20 24 76  |ASSERT  $r <> $v|
00000e70  0a 20 20 20 20 20 20 20  20 41 53 53 45 52 54 20  |.        ASSERT |
00000e80  20 24 72 20 3c 3e 20 24  77 0a 20 20 20 20 20 20  | $r <> $w.      |
00000e90  20 20 41 53 53 45 52 54  20 20 24 78 20 3c 3e 20  |  ASSERT  $x <> |
00000ea0  24 61 0a 20 20 20 20 20  20 20 20 41 53 53 45 52  |$a.        ASSER|
00000eb0  54 20 20 24 78 20 3c 3e  20 24 75 0a 20 20 20 20  |T  $x <> $u.    |
00000ec0  20 20 20 20 41 53 53 45  52 54 20 20 24 78 20 3c  |    ASSERT  $x <|
00000ed0  3e 20 24 76 0a 20 20 20  20 20 20 20 20 41 53 53  |> $v.        ASS|
00000ee0  45 52 54 20 20 24 78 20  3c 3e 20 24 77 0a 20 20  |ERT  $x <> $w.  |
00000ef0  20 20 20 20 20 20 41 53  53 45 52 54 20 20 24 61  |      ASSERT  $a|
00000f00  20 3c 3e 20 24 75 0a 20  20 20 20 20 20 20 20 41  | <> $u.        A|
00000f10  53 53 45 52 54 20 20 24  61 20 3c 3e 20 24 76 0a  |SSERT  $a <> $v.|
00000f20  20 20 20 20 20 20 20 20  41 53 53 45 52 54 20 20  |        ASSERT  |
00000f30  24 61 20 3c 3e 20 24 77  0a 20 20 20 20 20 20 20  |$a <> $w.       |
00000f40  20 41 53 53 45 52 54 20  20 24 75 20 3c 3e 20 24  | ASSERT  $u <> $|
00000f50  76 0a 20 20 20 20 20 20  20 20 41 53 53 45 52 54  |v.        ASSERT|
00000f60  20 20 24 75 20 3c 3e 20  24 77 0a 20 20 20 20 20  |  $u <> $w.     |
00000f70  20 20 20 41 53 53 45 52  54 20 20 24 76 20 3c 3e  |   ASSERT  $v <>|
00000f80  20 24 77 0a 0a 24 6c 61  62 65 6c 20 20 4d 4f 56  | $w..$label  MOV|
00000f90  53 20 20 20 20 24 77 2c  20 24 61 2c 20 4c 53 4c  |S    $w, $a, LSL|
00000fa0  20 23 31 0a 20 20 20 20  20 20 20 20 52 53 42 43  | #1.        RSBC|
00000fb0  53 20 20 20 24 61 2c 20  24 61 2c 20 23 30 0a 20  |S   $a, $a, #0. |
00000fc0  20 20 20 20 20 20 20 54  45 51 20 20 20 20 20 24  |       TEQ     $|
00000fd0  78 2c 20 23 30 0a 20 20  20 20 20 20 20 20 52 53  |x, #0.        RS|
00000fe0  42 4d 49 20 20 20 24 72  2c 20 24 78 2c 20 23 30  |BMI   $r, $x, #0|
00000ff0  0a 20 20 20 20 20 20 20  20 5b 20 20 20 20 20 20  |.        [      |
00001000  20 24 72 20 3c 3e 20 24  78 0a 20 20 20 20 20 20  | $r <> $x.      |
00001010  20 20 4d 4f 56 50 4c 20  20 20 24 72 2c 20 24 78  |  MOVPL   $r, $x|
00001020  0a 20 20 20 20 20 20 20  20 5d 20 20 20 20 20 20  |.        ]      |
00001030  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00001040  20 3b 6e 6f 77 20 68 61  76 65 20 43 20 62 69 74  | ;now have C bit|
00001050  20 73 65 74 20 69 66 66  20 61 3c 30 2c 20 4e 20  | set iff a<0, N |
00001060  62 69 74 20 73 65 74 20  69 66 66 20 78 3c 30 0a  |bit set iff x<0.|
00001070  20 20 20 20 20 20 20 20  4d 4f 56 20 20 20 20 20  |        MOV     |
00001080  24 77 2c 20 70 63 2c 20  4c 53 52 20 23 33 31 0a  |$w, pc, LSR #31.|
00001090  20 20 20 20 20 20 20 20  4d 4f 56 20 20 20 20 20  |        MOV     |
000010a0  24 77 2c 20 24 77 2c 20  4c 53 4c 20 23 32 38 20  |$w, $w, LSL #28 |
000010b0  3b 67 65 74 20 77 3d 28  32 5e 32 38 29 2a 4e 20  |;get w=(2^28)*N |
000010c0  7b 4e 20 69 73 20 62 33  31 2c 20 56 20 69 73 20  |{N is b31, V is |
000010d0  62 32 38 2c 20 43 20 69  73 20 62 32 39 20 69 6e  |b28, C is b29 in|
000010e0  20 70 63 2f 70 73 72 7d  0a 20 20 20 20 20 20 20  | pc/psr}.       |
000010f0  20 54 45 51 50 20 20 20  20 24 77 2c 20 70 63 2c  | TEQP    $w, pc,|
00001100  20 4c 53 52 20 23 31 20  20 3b 45 4f 52 20 77 20  | LSR #1  ;EOR w |
00001110  69 6e 74 6f 20 70 63 2f  70 73 72 20 7b 69 65 20  |into pc/psr {ie |
00001120  4e 20 45 4f 52 20 43 20  69 73 20 70 75 74 20 69  |N EOR C is put i|
00001130  6e 74 6f 20 56 7d 20 20  2d 20 74 68 69 73 20 69  |nto V}  - this i|
00001140  73 20 61 20 77 61 79 20  6f 66 20 73 74 6f 72 69  |s a way of stori|
00001150  6e 67 0a 20 20 20 20 20  20 20 20 20 20 20 20 20  |ng.             |
00001160  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00001170  20 20 20 3b 73 69 67 6e  20 6f 66 20 72 65 73 75  |   ;sign of resu|
00001180  6c 74 20 69 6e 20 6f 76  65 72 66 6c 6f 77 20 66  |lt in overflow f|
00001190  6c 61 67 2c 20 73 61 76  69 6e 67 20 6f 6e 20 61  |lag, saving on a|
000011a0  20 72 65 67 69 73 74 65  72 0a 20 20 20 20 20 20  | register.      |
000011b0  20 20 4d 4f 56 20 20 20  20 20 24 77 2c 20 24 72  |  MOV     $w, $r|
000011c0  2c 20 4c 53 52 20 23 31  36 0a 20 20 20 20 20 20  |, LSR #16.      |
000011d0  20 20 42 49 43 20 20 20  20 20 24 72 2c 20 24 72  |  BIC     $r, $r|
000011e0  2c 20 24 77 2c 20 4c 53  4c 20 23 31 36 0a 20 20  |, $w, LSL #16.  |
000011f0  20 20 20 20 20 20 4d 4f  56 20 20 20 20 20 24 76  |      MOV     $v|
00001200  2c 20 24 61 2c 20 4c 53  52 20 23 31 36 0a 20 20  |, $a, LSR #16.  |
00001210  20 20 20 20 20 20 42 49  43 20 20 20 20 20 24 61  |      BIC     $a|
00001220  2c 20 24 61 2c 20 24 76  2c 20 4c 53 4c 20 23 31  |, $a, $v, LSL #1|
00001230  36 0a 20 20 20 20 20 20  20 20 4d 55 4c 20 20 20  |6.        MUL   |
00001240  20 20 24 75 2c 20 24 61  2c 20 24 72 0a 20 20 20  |  $u, $a, $r.   |
00001250  20 20 20 20 20 54 53 54  20 20 20 20 20 24 75 2c  |     TST     $u,|
00001260  20 23 31 3c 3c 31 35 20  20 20 20 20 20 3b 6e 6f  | #1<<15      ;no|
00001270  74 69 63 65 20 74 68 69  73 20 69 73 20 74 68 65  |tice this is the|
00001280  20 6f 6e 6c 79 20 6f 70  65 72 61 74 69 6f 6e 20  | only operation |
00001290  61 6c 74 65 72 69 6e 67  20 70 73 72 20 26 20 74  |altering psr & t|
000012a0  68 61 74 20 69 74 20 77  69 6c 6c 20 6e 6f 74 20  |hat it will not |
000012b0  63 6f 72 72 75 70 74 20  56 0a 20 20 20 20 20 20  |corrupt V.      |
000012c0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000012d0  20 20 20 20 20 20 20 20  20 20 3b 6e 6f 74 65 20  |          ;note |
000012e0  69 74 20 77 69 6c 6c 20  63 6f 72 72 75 70 74 20  |it will corrupt |
000012f0  43 2c 20 61 73 20 69 6d  6d 65 64 69 61 74 65 20  |C, as immediate |
00001300  6f 70 65 72 61 6e 64 20  33 32 37 36 38 20 72 65  |operand 32768 re|
00001310  71 75 69 72 65 73 20 61  20 73 68 69 66 74 0a 20  |quires a shift. |
00001320  20 20 20 20 20 20 20 4d  4f 56 20 20 20 20 20 24  |       MOV     $|
00001330  75 2c 20 24 75 2c 20 4c  53 52 20 23 31 36 0a 20  |u, $u, LSR #16. |
00001340  20 20 20 20 20 20 20 41  44 44 4e 45 20 20 20 24  |       ADDNE   $|
00001350  75 2c 20 24 75 2c 20 23  31 0a 20 20 20 20 20 20  |u, $u, #1.      |
00001360  20 20 4d 4c 41 20 20 20  20 20 24 75 2c 20 24 72  |  MLA     $u, $r|
00001370  2c 20 24 76 2c 20 24 75  09 3b 36 2f 39 2f 39 34  |, $v, $u.;6/9/94|
00001380  20 2d 20 72 65 76 65 72  73 65 20 76 20 26 20 72  | - reverse v & r|
00001390  20 74 6f 20 6f 70 74 69  6d 69 73 65 20 66 6f 72  | to optimise for|
000013a0  20 61 72 67 75 6d 65 6e  74 20 61 20 73 6d 61 6c  | argument a smal|
000013b0  6c 0a 20 20 20 20 20 20  20 20 4d 4c 41 20 20 20  |l.        MLA   |
000013c0  20 20 24 75 2c 20 24 61  2c 20 24 77 2c 20 24 75  |  $u, $a, $w, $u|
000013d0  0a 20 20 20 20 20 20 20  20 4d 55 4c 20 20 20 20  |.        MUL    |
000013e0  20 24 72 2c 20 24 77 2c  20 24 76 09 3b 36 2f 39  | $r, $w, $v.;6/9|
000013f0  2f 39 34 20 2d 20 72 65  76 65 72 73 65 20 76 20  |/94 - reverse v |
00001400  26 20 77 20 74 6f 20 6f  70 74 69 6d 69 73 65 20  |& w to optimise |
00001410  66 6f 72 20 61 72 67 75  6d 65 6e 74 20 61 20 73  |for argument a s|
00001420  6d 61 6c 6c 0a 20 20 20  20 20 20 20 20 41 44 44  |mall.        ADD|
00001430  20 20 20 20 20 24 72 2c  20 24 75 2c 20 24 72 2c  |     $r, $u, $r,|
00001440  20 4c 53 4c 20 23 31 36  0a 20 20 20 20 20 20 20  | LSL #16.       |
00001450  20 52 53 42 56 53 20 20  20 24 72 2c 20 24 72 2c  | RSBVS   $r, $r,|
00001460  20 23 30 0a 0a 20 20 20  20 20 20 20 20 4d 45 4e  | #0..        MEN|
00001470  44 0a 0a 0a 0a 3b 20 6d  75 6c 31 36 63 0a 3b 20  |D....; mul16c.; |
00001480  6d 75 6c 74 69 70 6c 69  63 61 74 69 6f 6e 20 6f  |multiplication o|
00001490  66 20 61 6e 20 69 6e 74  65 67 65 72 20 78 20 62  |f an integer x b|
000014a0  79 20 61 20 31 36 2d 62  69 74 20 66 69 78 65 64  |y a 16-bit fixed|
000014b0  20 70 6f 69 6e 74 20 6e  75 6d 62 65 72 20 61 2c  | point number a,|
000014c0  20 77 68 65 72 65 20 61  20 69 73 20 61 20 63 6f  | where a is a co|
000014d0  6e 74 72 61 63 74 69 6f  6e 0a 3b 20 69 65 20 63  |ntraction.; ie c|
000014e0  61 6c 63 75 6c 61 74 65  73 20 72 3d 78 2a 61 2f  |alculates r=x*a/|
000014f0  36 35 35 33 36 2c 20 61  73 73 75 6d 69 6e 67 3a  |65536, assuming:|
00001500  20 61 62 73 20 61 20 3c  20 36 35 35 33 36 0a 3b  | abs a < 65536.;|
00001510  20 69 66 20 74 68 65 20  70 6f 73 73 69 62 69 6c  | if the possibil|
00001520  69 74 79 20 65 78 69 73  74 73 20 74 68 61 74 20  |ity exists that |
00001530  61 3e 3d 36 35 35 33 36  2c 20 63 61 6c 6c 65 72  |a>=65536, caller|
00001540  20 73 68 6f 75 6c 64 20  63 68 65 63 6b 20 74 68  | should check th|
00001550  69 73 20 26 20 65 69 74  68 65 72 20 6e 6f 74 20  |is & either not |
00001560  63 61 6c 6c 20 72 6f 75  74 69 6e 65 2c 20 6f 72  |call routine, or|
00001570  20 73 65 74 20 61 3d 36  35 35 33 35 0a 3b 20 49  | set a=65535.; I|
00001580  74 20 74 61 6b 65 73 20  34 20 70 61 72 61 6d 65  |t takes 4 parame|
00001590  74 65 72 73 20 2d 20 61  6c 6c 20 72 65 67 69 73  |ters - all regis|
000015a0  74 65 72 20 6e 61 6d 65  73 2e 0a 3b 0a 3b 20 24  |ter names..;.; $|
000015b0  78 3a 20 20 20 78 0a 3b  20 24 61 3a 20 20 20 61  |x:   x.; $a:   a|
000015c0  20 2d 20 72 65 71 75 69  72 65 20 61 62 73 20 61  | - require abs a|
000015d0  20 3c 36 35 35 33 36 2c  20 61 20 77 69 6c 6c 20  | <65536, a will |
000015e0  62 65 20 63 6f 72 72 75  70 74 65 64 0a 3b 20 24  |be corrupted.; $|
000015f0  72 3a 20 20 20 72 65 73  75 6c 74 20 2d 20 6d 61  |r:   result - ma|
00001600  79 20 62 65 20 74 68 65  20 73 61 6d 65 20 61 73  |y be the same as|
00001610  20 24 78 0a 3b 20 24 77  3a 20 20 20 73 63 72 61  | $x.; $w:   scra|
00001620  74 63 68 0a 3b 0a 20 20  20 20 20 20 20 20 4d 41  |tch.;.        MA|
00001630  43 52 4f 0a 24 6c 61 62  65 6c 20 20 6d 75 6c 31  |CRO.$label  mul1|
00001640  36 63 20 20 24 78 2c 20  24 61 2c 20 24 72 2c 20  |6c  $x, $a, $r, |
00001650  24 77 0a 0a 20 20 20 20  20 20 20 20 41 53 53 45  |$w..        ASSE|
00001660  52 54 20 20 24 72 20 3c  3e 20 24 61 0a 20 20 20  |RT  $r <> $a.   |
00001670  20 20 20 20 20 41 53 53  45 52 54 20 20 24 72 20  |     ASSERT  $r |
00001680  3c 3e 20 24 77 0a 20 20  20 20 20 20 20 20 41 53  |<> $w.        AS|
00001690  53 45 52 54 20 20 24 78  20 3c 3e 20 24 61 0a 20  |SERT  $x <> $a. |
000016a0  20 20 20 20 20 20 20 41  53 53 45 52 54 20 20 24  |       ASSERT  $|
000016b0  78 20 3c 3e 20 24 77 0a  20 20 20 20 20 20 20 20  |x <> $w.        |
000016c0  41 53 53 45 52 54 20 20  24 61 20 3c 3e 20 24 77  |ASSERT  $a <> $w|
000016d0  0a 0a 24 6c 61 62 65 6c  20 20 4d 4f 56 53 20 20  |..$label  MOVS  |
000016e0  20 20 24 77 2c 20 24 61  2c 20 4c 53 4c 20 23 31  |  $w, $a, LSL #1|
000016f0  0a 20 20 20 20 20 20 20  20 52 53 42 43 53 20 20  |.        RSBCS  |
00001700  20 24 61 2c 20 24 61 2c  20 23 30 0a 20 20 20 20  | $a, $a, #0.    |
00001710  20 20 20 20 54 45 51 20  20 20 20 20 24 78 2c 20  |    TEQ     $x, |
00001720  23 30 0a 20 20 20 20 20  20 20 20 52 53 42 4d 49  |#0.        RSBMI|
00001730  20 20 20 24 72 2c 20 24  78 2c 20 23 30 0a 20 20  |   $r, $x, #0.  |
00001740  20 20 20 20 20 20 5b 20  20 20 20 20 20 20 24 72  |      [       $r|
00001750  20 3c 3e 20 24 78 0a 20  20 20 20 20 20 20 20 4d  | <> $x.        M|
00001760  4f 56 50 4c 20 20 20 24  72 2c 20 24 78 0a 20 20  |OVPL   $r, $x.  |
00001770  20 20 20 20 20 20 5d 0a  20 20 20 20 20 20 20 20  |      ].        |
00001780  4d 4f 56 20 20 20 20 20  24 77 2c 20 70 63 2c 20  |MOV     $w, pc, |
00001790  4c 53 52 20 23 33 31 20  3b 73 65 65 20 6d 75 6c  |LSR #31 ;see mul|
000017a0  31 36 20 61 62 6f 76 65  2c 20 66 6f 72 20 63 6f  |16 above, for co|
000017b0  6d 6d 65 6e 74 73 20 72  65 20 74 68 69 73 20 70  |mments re this p|
000017c0  61 72 74 0a 20 20 20 20  20 20 20 20 4d 4f 56 20  |art.        MOV |
000017d0  20 20 20 20 24 77 2c 20  24 77 2c 20 4c 53 4c 20  |    $w, $w, LSL |
000017e0  23 32 38 0a 20 20 20 20  20 20 20 20 54 45 51 50  |#28.        TEQP|
000017f0  20 20 20 20 24 77 2c 20  70 63 2c 20 4c 53 52 20  |    $w, pc, LSR |
00001800  23 31 0a 0a 20 20 20 20  20 20 20 20 54 53 54 20  |#1..        TST |
00001810  20 20 20 20 24 61 2c 20  23 31 3c 3c 31 36 20 20  |    $a, #1<<16  |
00001820  20 20 20 20 3b 62 6f 64  67 65 20 74 6f 20 61 6c  |    ;bodge to al|
00001830  6c 6f 77 20 63 6f 64 65  20 74 6f 20 66 75 6e 63  |low code to func|
00001840  74 69 6f 6e 20 69 66 20  24 61 20 69 73 20 75 70  |tion if $a is up|
00001850  74 6f 20 32 2a 36 35 35  33 36 2d 31 0a 20 20 20  |to 2*65536-1.   |
00001860  20 20 20 20 20 4d 4f 56  4e 45 20 20 20 24 72 2c  |     MOVNE   $r,|
00001870  20 24 72 2c 20 4c 53 4c  20 23 31 20 20 3b 63 61  | $r, LSL #1  ;ca|
00001880  6e 20 6f 63 63 75 72 20  69 6e 20 61 20 63 6f 6e  |n occur in a con|
00001890  74 72 61 63 74 69 76 65  20 66 6e 20 64 75 65 20  |tractive fn due |
000018a0  74 6f 20 63 68 61 6e 67  65 20 6f 66 20 63 6f 6f  |to change of coo|
000018b0  72 64 69 6e 61 74 65 73  20 74 6f 20 68 61 6e 64  |rdinates to hand|
000018c0  6c 65 20 31 78 32 20 70  69 78 65 6c 20 61 73 70  |le 1x2 pixel asp|
000018d0  65 63 74 20 72 61 74 69  6f 0a 20 20 20 20 20 20  |ect ratio.      |
000018e0  20 20 4d 4f 56 4e 45 20  20 20 24 61 2c 20 24 61  |  MOVNE   $a, $a|
000018f0  2c 20 4c 53 52 20 23 31  20 20 3b 63 68 61 6e 67  |, LSR #1  ;chang|
00001900  65 20 6d 61 64 65 20 33  2f 34 2f 39 34 20 2d 20  |e made 3/4/94 - |
00001910  65 73 74 69 6d 61 74 65  20 6f 76 65 72 68 65 61  |estimate overhea|
00001920  64 20 74 6f 20 72 69 61  20 6f 66 20 75 70 74 6f  |d to ria of upto|
00001930  20 33 25 0a 0a 20 20 20  20 20 20 20 20 4d 4f 56  | 3%..        MOV|
00001940  20 20 20 20 20 24 77 2c  20 24 72 2c 20 4c 53 52  |     $w, $r, LSR|
00001950  20 23 31 36 0a 20 20 20  20 20 20 20 20 42 49 43  | #16.        BIC|
00001960  20 20 20 20 20 24 72 2c  20 24 72 2c 20 24 77 2c  |     $r, $r, $w,|
00001970  20 4c 53 4c 20 23 31 36  0a 20 20 20 20 20 20 20  | LSL #16.       |
00001980  20 4d 55 4c 20 20 20 20  20 24 72 2c 20 24 61 2c  | MUL     $r, $a,|
00001990  20 24 72 0a 20 20 20 20  20 20 20 20 54 53 54 20  | $r.        TST |
000019a0  20 20 20 20 24 72 2c 20  23 31 3c 3c 31 35 20 20  |    $r, #1<<15  |
000019b0  20 20 20 20 3b 72 65 6d  65 6d 62 65 72 2c 20 63  |    ;remember, c|
000019c0  61 6e 27 74 20 75 73 65  20 6d 6f 76 73 20 72 2c  |an't use movs r,|
000019d0  72 2c 6c 73 72 20 23 31  36 2c 20 61 73 20 74 68  |r,lsr #16, as th|
000019e0  69 73 20 77 6f 75 6c 64  20 63 6f 72 72 75 70 74  |is would corrupt|
000019f0  20 56 2c 20 77 68 69 63  68 20 69 73 20 73 74 6f  | V, which is sto|
00001a00  72 69 6e 67 20 73 69 67  6e 20 6f 66 20 72 65 73  |ring sign of res|
00001a10  75 6c 74 0a 20 20 20 20  20 20 20 20 4d 4f 56 20  |ult.        MOV |
00001a20  20 20 20 20 24 72 2c 20  24 72 2c 20 4c 53 52 20  |    $r, $r, LSR |
00001a30  23 31 36 0a 20 20 20 20  20 20 20 20 41 44 44 4e  |#16.        ADDN|
00001a40  45 20 20 20 24 72 2c 20  24 72 2c 20 23 31 0a 20  |E   $r, $r, #1. |
00001a50  20 20 20 20 20 20 20 4d  4c 41 20 20 20 20 20 24  |       MLA     $|
00001a60  72 2c 20 24 61 2c 20 24  77 2c 20 24 72 0a 0a 20  |r, $a, $w, $r.. |
00001a70  20 20 20 20 20 20 20 52  53 42 56 53 20 20 20 24  |       RSBVS   $|
00001a80  72 2c 20 24 72 2c 20 23  30 0a 0a 20 20 20 20 20  |r, $r, #0..     |
00001a90  20 20 20 4d 45 4e 44 0a  0a 0a 0a 3b 20 73 71 72  |   MEND....; sqr|
00001aa0  74 31 36 0a 3b 20 69 6e  74 65 67 65 72 20 73 71  |t16.; integer sq|
00001ab0  75 61 72 65 20 72 6f 6f  74 20 72 65 74 75 72 6e  |uare root return|
00001ac0  69 6e 67 20 31 36 2d 62  69 74 20 66 69 78 65 64  |ing 16-bit fixed|
00001ad0  20 70 6f 69 6e 74 20 6e  75 6d 62 65 72 2c 20 61  | point number, a|
00001ae0  73 73 75 6d 69 6e 67 20  78 20 69 73 20 31 36 2d  |ssuming x is 16-|
00001af0  62 69 74 20 66 69 78 65  64 20 70 6f 69 6e 74 0a  |bit fixed point.|
00001b00  3b 20 69 65 20 72 65 74  75 72 6e 73 20 73 71 72  |; ie returns sqr|
00001b10  74 28 78 3c 3c 31 36 29  0a 3b 20 49 74 20 74 61  |t(x<<16).; It ta|
00001b20  6b 65 73 20 36 20 70 61  72 61 6d 65 74 65 72 73  |kes 6 parameters|
00001b30  20 2d 20 61 6c 6c 20 72  65 67 69 73 74 65 72 20  | - all register |
00001b40  6e 61 6d 65 73 0a 3b 0a  3b 20 24 78 3a 20 20 20  |names.;.; $x:   |
00001b50  78 0a 3b 20 24 72 3a 20  20 20 72 65 73 75 6c 74  |x.; $r:   result|
00001b60  20 2d 20 6d 61 79 20 62  65 20 74 68 65 20 73 61  | - may be the sa|
00001b70  6d 65 20 61 73 20 78 0a  3b 20 24 6e 3a 20 20 20  |me as x.; $n:   |
00001b80  63 6f 70 79 20 6f 66 20  78 20 75 73 65 64 20 64  |copy of x used d|
00001b90  75 72 69 6e 67 20 63 61  6c 63 75 6c 61 74 69 6f  |uring calculatio|
00001ba0  6e 0a 3b 20 24 74 3a 20  20 20 74 72 61 6e 73 69  |n.; $t:   transi|
00001bb0  65 6e 74 20 73 63 72 61  74 63 68 0a 3b 20 24 64  |ent scratch.; $d|
00001bc0  3a 20 20 20 72 65 6d 61  69 6e 64 65 72 0a 3b 20  |:   remainder.; |
00001bd0  24 6f 3a 20 20 20 63 6f  6e 73 74 61 6e 74 20 76  |$o:   constant v|
00001be0  61 6c 75 65 20 6f 66 20  31 0a 3b 0a 20 20 20 20  |alue of 1.;.    |
00001bf0  20 20 20 20 4d 41 43 52  4f 0a 24 6c 61 62 65 6c  |    MACRO.$label|
00001c00  20 20 73 71 72 74 31 36  20 20 24 78 2c 20 24 72  |  sqrt16  $x, $r|
00001c10  2c 20 24 6e 2c 20 24 74  2c 20 24 64 2c 20 24 6f  |, $n, $t, $d, $o|
00001c20  0a 0a 20 20 20 20 20 20  20 20 41 53 53 45 52 54  |..        ASSERT|
00001c30  20 20 24 78 20 3c 3e 20  24 6e 0a 20 20 20 20 20  |  $x <> $n.     |
00001c40  20 20 20 41 53 53 45 52  54 20 20 24 78 20 3c 3e  |   ASSERT  $x <>|
00001c50  20 24 74 0a 20 20 20 20  20 20 20 20 41 53 53 45  | $t.        ASSE|
00001c60  52 54 20 20 24 78 20 3c  3e 20 24 64 0a 20 20 20  |RT  $x <> $d.   |
00001c70  20 20 20 20 20 41 53 53  45 52 54 20 20 24 78 20  |     ASSERT  $x |
00001c80  3c 3e 20 24 6f 0a 20 20  20 20 20 20 20 20 41 53  |<> $o.        AS|
00001c90  53 45 52 54 20 20 24 6e  20 3c 3e 20 24 74 0a 20  |SERT  $n <> $t. |
00001ca0  20 20 20 20 20 20 20 41  53 53 45 52 54 20 20 24  |       ASSERT  $|
00001cb0  6e 20 3c 3e 20 24 64 0a  20 20 20 20 20 20 20 20  |n <> $d.        |
00001cc0  41 53 53 45 52 54 20 20  24 6e 20 3c 3e 20 24 6f  |ASSERT  $n <> $o|
00001cd0  0a 20 20 20 20 20 20 20  20 41 53 53 45 52 54 20  |.        ASSERT |
00001ce0  20 24 74 20 3c 3e 20 24  64 0a 20 20 20 20 20 20  | $t <> $d.      |
00001cf0  20 20 41 53 53 45 52 54  20 20 24 74 20 3c 3e 20  |  ASSERT  $t <> |
00001d00  24 6f 0a 20 20 20 20 20  20 20 20 41 53 53 45 52  |$o.        ASSER|
00001d10  54 20 20 24 64 20 3c 3e  20 24 6f 0a 0a 20 20 20  |T  $d <> $o..   |
00001d20  20 20 20 20 20 4c 43 4c  41 20 20 20 20 63 6f 75  |     LCLA    cou|
00001d30  6e 74 65 72 0a 0a 24 6c  61 62 65 6c 20 20 4d 4f  |nter..$label  MO|
00001d40  56 20 20 20 20 20 24 6e  2c 20 24 78 0a 20 20 20  |V     $n, $x.   |
00001d50  20 20 20 20 20 4d 4f 56  20 20 20 20 20 24 6f 2c  |     MOV     $o,|
00001d60  20 23 31 0a 20 20 20 20  20 20 20 20 4d 4f 56 20  | #1.        MOV |
00001d70  20 20 20 20 24 78 2c 20  23 30 0a 20 20 20 20 20  |    $x, #0.     |
00001d80  20 20 20 4d 4f 56 20 20  20 20 20 24 64 2c 20 23  |   MOV     $d, #|
00001d90  30 0a 0a 20 20 20 20 20  20 20 20 41 4e 44 20 20  |0..        AND  |
00001da0  20 20 20 24 74 2c 20 24  6e 2c 20 23 28 33 3c 3c  |   $t, $n, #(3<<|
00001db0  33 30 29 0a 20 20 20 20  20 20 20 20 4d 4f 56 20  |30).        MOV |
00001dc0  20 20 20 20 24 74 2c 20  24 74 2c 20 4c 53 52 20  |    $t, $t, LSR |
00001dd0  23 33 30 0a 20 20 20 20  20 20 20 20 4f 52 52 20  |#30.        ORR |
00001de0  20 20 20 20 24 64 2c 20  24 64 2c 20 24 74 0a 20  |    $d, $d, $t. |
00001df0  20 20 20 20 20 20 20 41  44 44 20 20 20 20 20 24  |       ADD     $|
00001e00  74 2c 20 24 6f 2c 20 24  78 2c 20 4c 53 4c 20 23  |t, $o, $x, LSL #|
00001e10  31 0a 20 20 20 20 20 20  20 20 43 4d 50 20 20 20  |1.        CMP   |
00001e20  20 20 24 64 2c 20 24 74  0a 20 20 20 20 20 20 20  |  $d, $t.       |
00001e30  20 53 55 42 47 45 20 20  20 24 64 2c 20 24 64 2c  | SUBGE   $d, $d,|
00001e40  20 24 74 0a 20 20 20 20  20 20 20 20 41 44 44 47  | $t.        ADDG|
00001e50  45 20 20 20 24 78 2c 20  24 78 2c 20 23 31 0a 0a  |E   $x, $x, #1..|
00001e60  63 6f 75 6e 74 65 72 20  53 45 54 41 20 20 20 20  |counter SETA    |
00001e70  32 38 0a 20 20 20 20 20  20 20 20 57 48 49 4c 45  |28.        WHILE|
00001e80  20 20 20 63 6f 75 6e 74  65 72 20 3c 20 33 32 20  |   counter < 32 |
00001e90  20 20 20 20 20 20 20 20  20 20 20 20 3b 77 61 6e  |            ;wan|
00001ea0  74 20 3e 3d 20 30 2c 20  68 6f 77 65 76 65 72 20  |t >= 0, however |
00001eb0  63 6f 75 6e 74 65 72 20  69 73 20 75 6e 73 69 67  |counter is unsig|
00001ec0  6e 65 64 2c 20 73 6f 20  61 66 74 65 72 20 30 20  |ned, so after 0 |
00001ed0  69 74 20 67 6f 65 73 20  68 69 67 68 2c 20 74 68  |it goes high, th|
00001ee0  75 73 20 3c 20 33 32 20  77 69 6c 6c 20 63 61 74  |us < 32 will cat|
00001ef0  63 68 20 69 74 21 0a 20  20 20 20 20 20 20 20 4d  |ch it!.        M|
00001f00  4f 56 20 20 20 20 20 24  78 2c 20 24 78 2c 20 4c  |OV     $x, $x, L|
00001f10  53 4c 20 23 31 0a 20 20  20 20 20 20 20 20 4d 4f  |SL #1.        MO|
00001f20  56 20 20 20 20 20 24 64  2c 20 24 64 2c 20 4c 53  |V     $d, $d, LS|
00001f30  4c 20 23 32 0a 20 20 20  20 20 20 20 20 41 4e 44  |L #2.        AND|
00001f40  20 20 20 20 20 24 74 2c  20 24 6e 2c 20 23 28 33  |     $t, $n, #(3|
00001f50  3c 3c 63 6f 75 6e 74 65  72 29 0a 20 20 20 20 20  |<<counter).     |
00001f60  20 20 20 5b 20 20 20 20  20 20 20 63 6f 75 6e 74  |   [       count|
00001f70  65 72 20 3c 3e 20 30 0a  20 20 20 20 20 20 20 20  |er <> 0.        |
00001f80  4d 4f 56 20 20 20 20 20  24 74 2c 20 24 74 2c 20  |MOV     $t, $t, |
00001f90  4c 53 52 20 23 63 6f 75  6e 74 65 72 0a 20 20 20  |LSR #counter.   |
00001fa0  20 20 20 20 20 5d 0a 20  20 20 20 20 20 20 20 4f  |     ].        O|
00001fb0  52 52 20 20 20 20 20 24  64 2c 20 24 64 2c 20 24  |RR     $d, $d, $|
00001fc0  74 0a 20 20 20 20 20 20  20 20 41 44 44 20 20 20  |t.        ADD   |
00001fd0  20 20 24 74 2c 20 24 6f  2c 20 24 78 2c 20 4c 53  |  $t, $o, $x, LS|
00001fe0  4c 20 23 31 0a 20 20 20  20 20 20 20 20 43 4d 50  |L #1.        CMP|
00001ff0  20 20 20 20 20 24 64 2c  20 24 74 0a 20 20 20 20  |     $d, $t.    |
00002000  20 20 20 20 53 55 42 47  45 20 20 20 24 64 2c 20  |    SUBGE   $d, |
00002010  24 64 2c 20 24 74 0a 20  20 20 20 20 20 20 20 41  |$d, $t.        A|
00002020  44 44 47 45 20 20 20 24  78 2c 20 24 78 2c 20 23  |DDGE   $x, $x, #|
00002030  31 0a 63 6f 75 6e 74 65  72 20 53 45 54 41 20 20  |1.counter SETA  |
00002040  20 20 63 6f 75 6e 74 65  72 2d 32 0a 20 20 20 20  |  counter-2.    |
00002050  20 20 20 20 57 45 4e 44  0a 0a 63 6f 75 6e 74 65  |    WEND..counte|
00002060  72 20 53 45 54 41 20 20  20 20 31 34 0a 20 20 20  |r SETA    14.   |
00002070  20 20 20 20 20 57 48 49  4c 45 20 20 20 63 6f 75  |     WHILE   cou|
00002080  6e 74 65 72 20 3c 20 33  32 0a 20 20 20 20 20 20  |nter < 32.      |
00002090  20 20 4d 4f 56 20 20 20  20 20 24 78 2c 20 24 78  |  MOV     $x, $x|
000020a0  2c 20 4c 53 4c 20 23 31  0a 20 20 20 20 20 20 20  |, LSL #1.       |
000020b0  20 4d 4f 56 20 20 20 20  20 24 64 2c 20 24 64 2c  | MOV     $d, $d,|
000020c0  20 4c 53 4c 20 23 32 0a  20 20 20 20 20 20 20 20  | LSL #2.        |
000020d0  41 44 44 20 20 20 20 20  24 74 2c 20 24 6f 2c 20  |ADD     $t, $o, |
000020e0  24 78 2c 20 4c 53 4c 20  23 31 0a 20 20 20 20 20  |$x, LSL #1.     |
000020f0  20 20 20 43 4d 50 20 20  20 20 20 24 64 2c 20 24  |   CMP     $d, $|
00002100  74 0a 20 20 20 20 20 20  20 20 53 55 42 47 45 20  |t.        SUBGE |
00002110  20 20 24 64 2c 20 24 64  2c 20 24 74 0a 20 20 20  |  $d, $d, $t.   |
00002120  20 20 20 20 20 41 44 44  47 45 20 20 20 24 78 2c  |     ADDGE   $x,|
00002130  20 24 78 2c 20 23 31 0a  63 6f 75 6e 74 65 72 20  | $x, #1.counter |
00002140  53 45 54 41 20 20 20 20  63 6f 75 6e 74 65 72 2d  |SETA    counter-|
00002150  32 0a 20 20 20 20 20 20  20 20 57 45 4e 44 0a 0a  |2.        WEND..|
00002160  20 20 20 20 20 20 20 20  5b 20 20 20 20 20 20 20  |        [       |
00002170  24 72 20 3c 3e 20 24 78  0a 20 20 20 20 20 20 20  |$r <> $x.       |
00002180  20 4d 4f 56 20 20 20 20  20 24 72 2c 20 24 78 0a  | MOV     $r, $x.|
00002190  20 20 20 20 20 20 20 20  5d 0a 0a 20 20 20 20 20  |        ]..     |
000021a0  20 20 20 4d 45 4e 44 0a  0a 0a 0a 20 20 20 20 20  |   MEND....     |
000021b0  20 20 20 45 4e 44 0a                              |   END.|
000021b7