Home » Archimedes archive » Archimedes World » AW-1996-02-Disc2.adf » !AcornAns_Trans1d » !Trans1d/s/subrouts1

!Trans1d/s/subrouts1

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 » Archimedes archive » Archimedes World » AW-1996-02-Disc2.adf » !AcornAns_Trans1d
Filename: !Trans1d/s/subrouts1
Read OK:
File size: 1270 bytes
Load address: 0000
Exec address: 0000
File contents
; rbbcinc
; a leaf APCS function
;
; C prototype:
; int rbbcinc(int r, int k)
;
; given limits 0 <= r < 2^k, return (r � 1) where � denotes a reversed bit ordering increment,
; subject to the stated limits.
; NB in this case, for the function f: n -> {for (k=c=0; c<n; c++, k=rbbcinc(k, l); return k;},
; we have f(f(n))=n.
; NB2 algo requires 2 <= k <= 32, but doesn't check for this - BEWARE!
; (for k=1 get no action taken, while for any other bad k get code executed at unintended address,
;  hence unpredictable & likely system fatal).
;

        EXPORT  rbbcinc

rbnsta  DCB     "rbbcinc", 0
        ALIGN
rbnend  DCD     &ff000000 + rbnend - rbnsta

rbbcinc

        rbbc    a1, a2, a3
        MOVS    pc, lr



; gauss16
; a leaf APCS function
;
; C prototype:
; int gauss16(void)
;
; returns 65536 * ( pseudo randon variable with approximate distribution N(0,1) )
; note, the approximate gaussian distribution is achieved via the sum of n pseudo U[0,65535]
;       random variables & application of the central limit theorem
;       here we use n=8, giving an actual range of �(sqrt24) (*65536).
;
;       for general n, recall we need to return:
;       (sum n U[0,65535] random variables) * 2sqrt(3n)*65536/(65535n)  -  sqrt(3n)*65536
;

	EXPORT	gauss16

gansta  DCB     "gauss16", 0
        ALIGN
ganend  DCD     &ff000000 + ganend - gansta

gauss16

	ADR	a1, gaussseed1
	LDMIA	a1, {a2, a3}

	MOVS    a3, a3, LSR #1
        MOVS    a4, a2, RRX
        ADC     a3, a3, a3
        EOR     a4, a4, a2, LSL #12
        EOR     a2, a4, a4, LSR #20
	MOV	ip, a2, LSR #16
	MOV	a4, a2, LSL #16
	ADD	ip, ip, a4, LSR #16

	MOVS    a3, a3, LSR #1
        MOVS    a4, a2, RRX
        ADC     a3, a3, a3
        EOR     a4, a4, a2, LSL #12
        EOR     a2, a4, a4, LSR #20
	ADD	ip, ip, a2, LSR #16
	MOV	a4, a2, LSL #16
	ADD	ip, ip, a4, LSR #16

	MOVS    a3, a3, LSR #1
        MOVS    a4, a2, RRX
        ADC     a3, a3, a3
        EOR     a4, a4, a2, LSL #12
        EOR     a2, a4, a4, LSR #20
	ADD	ip, ip, a2, LSR #16
	MOV	a4, a2, LSL #16
	ADD	ip, ip, a4, LSR #16

	MOVS    a3, a3, LSR #1
        MOVS    a4, a2, RRX
        ADC     a3, a3, a3
        EOR     a4, a4, a2, LSL #12
        EOR     a2, a4, a4, LSR #20
	ADD	ip, ip, a2, LSR #16
	MOV	a4, a2, LSL #16
	ADD	ip, ip, a4, LSR #16		;sum now in ip

	STMIA	a1, {a2, a3}

	RSB	a1, ip, ip, ASL #3
	RSB	a2, ip, ip, ASL #2
	ADD	a1, a2, a1, ASL #4
	ADD	a1, a1, ip, ASL #9
	ADD	a2, ip, ip, ASL #4
	ADD	a2, a2, ip, ASL #6
	ADD	a1, a1, a2, LSR #10
	MOV	a1, a1, LSR #9
	SUB	a1, a1, #&4E000
	SUB	a1, a1, #&00620
	SUB	a1, a1, #&00004

        MOVS    pc, lr

gaussseed1	DCD	-1		;bits b0-b31 of seed
		DCD	-1		;bit  b32 of seed (in lsb of word)

; sgauss16
; a leaf APCS function
;
; C prototype:
; void sgauss16(int seed)
;
; sets the seed for gauss16
;

	EXPORT	sgauss16

sgnsta  DCB     "sgauss16", 0
        ALIGN
sgnend  DCD     &ff000000 + sgnend - sgnsta

sgauss16

	ADR	a2, gaussseed1
	MOV	a3, #1
	STMIA	a2, {a1, a3}
        MOVS    pc, lr



; div_frac16
; a leaf APCS function
;
; C prototype:
; int div_frac16(int number, int divisor)
;
; returns integer part of 65536*number/divisor
; assumes abs number < 65536 * abs divisor
; if this needs checking, must be done by caller
;

        EXPORT  div_frac16

dfnsta  DCB     "div_frac16", 0
        ALIGN
dfnend  DCD     &ff000000 + dfnend - dfnsta

div_frac16

        div16   a1, a2, a1, a3, a4
        MOVS    pc, lr



; mul_frac16
; a leaf APCS function
;
; C prototype:
; int mul_frac16(int x, int a)
;
; returns 32-bit signed integer x*a/65536
; assumes result fits into 32-bit signed representation
; note, no other restrictions on a - if can guarantee abs a < 65536, use mul_frac16c instead as is quicker
;

        EXPORT  mul_frac16

mfnsta  DCB     "mul_frac16", 0
        ALIGN
mfnend  DCD     &ff000000 + mfnend - mfnsta

mul_frac16

        mul16   a1, a2, a1, a3, a4, ip
        MOVS    pc, lr



; mul_frac16c
; a leaf APCS function
;
; C prototype:
; int mul_frac16c(int x, int a)
;
; returns 32-bit signed integer x*a/65536
; assumes abs a <=65536
; if it is possible that abs a > 65536, caller must check range & either not call fn or round down to 65536
;

        EXPORT  mul_frac16c

mfcnsta DCB     "mul_frac16c", 0
        ALIGN
mfcnend DCD     &ff000000 + mfcnend - mfcnsta

mul_frac16c

        mul16c  a1, a2, a1, a3
        MOVS    pc, lr



; sqrt_frac28
; a leaf APCS function
;
; C prototype:
; int sqrt_frac28(unsigned int x)
;
; returns 32-bit integer sqrt(x<<28)
;

        EXPORT  sqrt_frac28

sqfnsta DCB     "sqrt_frac28", 0
        ALIGN
sqfnend DCD     &ff000000 + sqfnend - sqfnsta

sqrt_frac28

        sqrt28  a1, a1, a2, a3, a4, ip
        MOVS    pc, lr



        END
00000000  0a 3b 20 72 62 62 63 69  6e 63 0a 3b 20 61 20 6c  |.; rbbcinc.; a l|
00000010  65 61 66 20 41 50 43 53  20 66 75 6e 63 74 69 6f  |eaf APCS functio|
00000020  6e 0a 3b 0a 3b 20 43 20  70 72 6f 74 6f 74 79 70  |n.;.; C prototyp|
00000030  65 3a 0a 3b 20 69 6e 74  20 72 62 62 63 69 6e 63  |e:.; int rbbcinc|
00000040  28 69 6e 74 20 72 2c 20  69 6e 74 20 6b 29 0a 3b  |(int r, int k).;|
00000050  0a 3b 20 67 69 76 65 6e  20 6c 69 6d 69 74 73 20  |.; given limits |
00000060  30 20 3c 3d 20 72 20 3c  20 32 5e 6b 2c 20 72 65  |0 <= r < 2^k, re|
00000070  74 75 72 6e 20 28 72 20  a4 20 31 29 20 77 68 65  |turn (r . 1) whe|
00000080  72 65 20 a4 20 64 65 6e  6f 74 65 73 20 61 20 72  |re . denotes a r|
00000090  65 76 65 72 73 65 64 20  62 69 74 20 6f 72 64 65  |eversed bit orde|
000000a0  72 69 6e 67 20 69 6e 63  72 65 6d 65 6e 74 2c 0a  |ring increment,.|
000000b0  3b 20 73 75 62 6a 65 63  74 20 74 6f 20 74 68 65  |; subject to the|
000000c0  20 73 74 61 74 65 64 20  6c 69 6d 69 74 73 2e 0a  | stated limits..|
000000d0  3b 20 4e 42 20 69 6e 20  74 68 69 73 20 63 61 73  |; NB in this cas|
000000e0  65 2c 20 66 6f 72 20 74  68 65 20 66 75 6e 63 74  |e, for the funct|
000000f0  69 6f 6e 20 66 3a 20 6e  20 2d 3e 20 7b 66 6f 72  |ion f: n -> {for|
00000100  20 28 6b 3d 63 3d 30 3b  20 63 3c 6e 3b 20 63 2b  | (k=c=0; c<n; c+|
00000110  2b 2c 20 6b 3d 72 62 62  63 69 6e 63 28 6b 2c 20  |+, k=rbbcinc(k, |
00000120  6c 29 3b 20 72 65 74 75  72 6e 20 6b 3b 7d 2c 0a  |l); return k;},.|
00000130  3b 20 77 65 20 68 61 76  65 20 66 28 66 28 6e 29  |; we have f(f(n)|
00000140  29 3d 6e 2e 0a 3b 20 4e  42 32 20 61 6c 67 6f 20  |)=n..; NB2 algo |
00000150  72 65 71 75 69 72 65 73  20 32 20 3c 3d 20 6b 20  |requires 2 <= k |
00000160  3c 3d 20 33 32 2c 20 62  75 74 20 64 6f 65 73 6e  |<= 32, but doesn|
00000170  27 74 20 63 68 65 63 6b  20 66 6f 72 20 74 68 69  |'t check for thi|
00000180  73 20 2d 20 42 45 57 41  52 45 21 0a 3b 20 28 66  |s - BEWARE!.; (f|
00000190  6f 72 20 6b 3d 31 20 67  65 74 20 6e 6f 20 61 63  |or k=1 get no ac|
000001a0  74 69 6f 6e 20 74 61 6b  65 6e 2c 20 77 68 69 6c  |tion taken, whil|
000001b0  65 20 66 6f 72 20 61 6e  79 20 6f 74 68 65 72 20  |e for any other |
000001c0  62 61 64 20 6b 20 67 65  74 20 63 6f 64 65 20 65  |bad k get code e|
000001d0  78 65 63 75 74 65 64 20  61 74 20 75 6e 69 6e 74  |xecuted at unint|
000001e0  65 6e 64 65 64 20 61 64  64 72 65 73 73 2c 0a 3b  |ended address,.;|
000001f0  20 20 68 65 6e 63 65 20  75 6e 70 72 65 64 69 63  |  hence unpredic|
00000200  74 61 62 6c 65 20 26 20  6c 69 6b 65 6c 79 20 73  |table & likely s|
00000210  79 73 74 65 6d 20 66 61  74 61 6c 29 2e 0a 3b 0a  |ystem fatal)..;.|
00000220  0a 20 20 20 20 20 20 20  20 45 58 50 4f 52 54 20  |.        EXPORT |
00000230  20 72 62 62 63 69 6e 63  0a 0a 72 62 6e 73 74 61  | rbbcinc..rbnsta|
00000240  20 20 44 43 42 20 20 20  20 20 22 72 62 62 63 69  |  DCB     "rbbci|
00000250  6e 63 22 2c 20 30 0a 20  20 20 20 20 20 20 20 41  |nc", 0.        A|
00000260  4c 49 47 4e 0a 72 62 6e  65 6e 64 20 20 44 43 44  |LIGN.rbnend  DCD|
00000270  20 20 20 20 20 26 66 66  30 30 30 30 30 30 20 2b  |     &ff000000 +|
00000280  20 72 62 6e 65 6e 64 20  2d 20 72 62 6e 73 74 61  | rbnend - rbnsta|
00000290  0a 0a 72 62 62 63 69 6e  63 0a 0a 20 20 20 20 20  |..rbbcinc..     |
000002a0  20 20 20 72 62 62 63 20  20 20 20 61 31 2c 20 61  |   rbbc    a1, a|
000002b0  32 2c 20 61 33 0a 20 20  20 20 20 20 20 20 4d 4f  |2, a3.        MO|
000002c0  56 53 20 20 20 20 70 63  2c 20 6c 72 0a 0a 0a 0a  |VS    pc, lr....|
000002d0  3b 20 67 61 75 73 73 31  36 0a 3b 20 61 20 6c 65  |; gauss16.; a le|
000002e0  61 66 20 41 50 43 53 20  66 75 6e 63 74 69 6f 6e  |af APCS function|
000002f0  0a 3b 0a 3b 20 43 20 70  72 6f 74 6f 74 79 70 65  |.;.; C prototype|
00000300  3a 0a 3b 20 69 6e 74 20  67 61 75 73 73 31 36 28  |:.; int gauss16(|
00000310  76 6f 69 64 29 0a 3b 0a  3b 20 72 65 74 75 72 6e  |void).;.; return|
00000320  73 20 36 35 35 33 36 20  2a 20 28 20 70 73 65 75  |s 65536 * ( pseu|
00000330  64 6f 20 72 61 6e 64 6f  6e 20 76 61 72 69 61 62  |do randon variab|
00000340  6c 65 20 77 69 74 68 20  61 70 70 72 6f 78 69 6d  |le with approxim|
00000350  61 74 65 20 64 69 73 74  72 69 62 75 74 69 6f 6e  |ate distribution|
00000360  20 4e 28 30 2c 31 29 20  29 0a 3b 20 6e 6f 74 65  | N(0,1) ).; note|
00000370  2c 20 74 68 65 20 61 70  70 72 6f 78 69 6d 61 74  |, the approximat|
00000380  65 20 67 61 75 73 73 69  61 6e 20 64 69 73 74 72  |e gaussian distr|
00000390  69 62 75 74 69 6f 6e 20  69 73 20 61 63 68 69 65  |ibution is achie|
000003a0  76 65 64 20 76 69 61 20  74 68 65 20 73 75 6d 20  |ved via the sum |
000003b0  6f 66 20 6e 20 70 73 65  75 64 6f 20 55 5b 30 2c  |of n pseudo U[0,|
000003c0  36 35 35 33 35 5d 0a 3b  20 20 20 20 20 20 20 72  |65535].;       r|
000003d0  61 6e 64 6f 6d 20 76 61  72 69 61 62 6c 65 73 20  |andom variables |
000003e0  26 20 61 70 70 6c 69 63  61 74 69 6f 6e 20 6f 66  |& application of|
000003f0  20 74 68 65 20 63 65 6e  74 72 61 6c 20 6c 69 6d  | the central lim|
00000400  69 74 20 74 68 65 6f 72  65 6d 0a 3b 20 20 20 20  |it theorem.;    |
00000410  20 20 20 68 65 72 65 20  77 65 20 75 73 65 20 6e  |   here we use n|
00000420  3d 38 2c 20 67 69 76 69  6e 67 20 61 6e 20 61 63  |=8, giving an ac|
00000430  74 75 61 6c 20 72 61 6e  67 65 20 6f 66 20 b1 28  |tual range of .(|
00000440  73 71 72 74 32 34 29 20  28 2a 36 35 35 33 36 29  |sqrt24) (*65536)|
00000450  2e 0a 3b 0a 3b 20 20 20  20 20 20 20 66 6f 72 20  |..;.;       for |
00000460  67 65 6e 65 72 61 6c 20  6e 2c 20 72 65 63 61 6c  |general n, recal|
00000470  6c 20 77 65 20 6e 65 65  64 20 74 6f 20 72 65 74  |l we need to ret|
00000480  75 72 6e 3a 0a 3b 20 20  20 20 20 20 20 28 73 75  |urn:.;       (su|
00000490  6d 20 6e 20 55 5b 30 2c  36 35 35 33 35 5d 20 72  |m n U[0,65535] r|
000004a0  61 6e 64 6f 6d 20 76 61  72 69 61 62 6c 65 73 29  |andom variables)|
000004b0  20 2a 20 32 73 71 72 74  28 33 6e 29 2a 36 35 35  | * 2sqrt(3n)*655|
000004c0  33 36 2f 28 36 35 35 33  35 6e 29 20 20 2d 20 20  |36/(65535n)  -  |
000004d0  73 71 72 74 28 33 6e 29  2a 36 35 35 33 36 0a 3b  |sqrt(3n)*65536.;|
000004e0  0a 0a 09 45 58 50 4f 52  54 09 67 61 75 73 73 31  |...EXPORT.gauss1|
000004f0  36 0a 0a 67 61 6e 73 74  61 20 20 44 43 42 20 20  |6..gansta  DCB  |
00000500  20 20 20 22 67 61 75 73  73 31 36 22 2c 20 30 0a  |   "gauss16", 0.|
00000510  20 20 20 20 20 20 20 20  41 4c 49 47 4e 0a 67 61  |        ALIGN.ga|
00000520  6e 65 6e 64 20 20 44 43  44 20 20 20 20 20 26 66  |nend  DCD     &f|
00000530  66 30 30 30 30 30 30 20  2b 20 67 61 6e 65 6e 64  |f000000 + ganend|
00000540  20 2d 20 67 61 6e 73 74  61 0a 0a 67 61 75 73 73  | - gansta..gauss|
00000550  31 36 0a 0a 09 41 44 52  09 61 31 2c 20 67 61 75  |16...ADR.a1, gau|
00000560  73 73 73 65 65 64 31 0a  09 4c 44 4d 49 41 09 61  |ssseed1..LDMIA.a|
00000570  31 2c 20 7b 61 32 2c 20  61 33 7d 0a 0a 09 4d 4f  |1, {a2, a3}...MO|
00000580  56 53 20 20 20 20 61 33  2c 20 61 33 2c 20 4c 53  |VS    a3, a3, LS|
00000590  52 20 23 31 0a 20 20 20  20 20 20 20 20 4d 4f 56  |R #1.        MOV|
000005a0  53 20 20 20 20 61 34 2c  20 61 32 2c 20 52 52 58  |S    a4, a2, RRX|
000005b0  0a 20 20 20 20 20 20 20  20 41 44 43 20 20 20 20  |.        ADC    |
000005c0  20 61 33 2c 20 61 33 2c  20 61 33 0a 20 20 20 20  | a3, a3, a3.    |
000005d0  20 20 20 20 45 4f 52 20  20 20 20 20 61 34 2c 20  |    EOR     a4, |
000005e0  61 34 2c 20 61 32 2c 20  4c 53 4c 20 23 31 32 0a  |a4, a2, LSL #12.|
000005f0  20 20 20 20 20 20 20 20  45 4f 52 20 20 20 20 20  |        EOR     |
00000600  61 32 2c 20 61 34 2c 20  61 34 2c 20 4c 53 52 20  |a2, a4, a4, LSR |
00000610  23 32 30 0a 09 4d 4f 56  09 69 70 2c 20 61 32 2c  |#20..MOV.ip, a2,|
00000620  20 4c 53 52 20 23 31 36  0a 09 4d 4f 56 09 61 34  | LSR #16..MOV.a4|
00000630  2c 20 61 32 2c 20 4c 53  4c 20 23 31 36 0a 09 41  |, a2, LSL #16..A|
00000640  44 44 09 69 70 2c 20 69  70 2c 20 61 34 2c 20 4c  |DD.ip, ip, a4, L|
00000650  53 52 20 23 31 36 0a 0a  09 4d 4f 56 53 20 20 20  |SR #16...MOVS   |
00000660  20 61 33 2c 20 61 33 2c  20 4c 53 52 20 23 31 0a  | a3, a3, LSR #1.|
00000670  20 20 20 20 20 20 20 20  4d 4f 56 53 20 20 20 20  |        MOVS    |
00000680  61 34 2c 20 61 32 2c 20  52 52 58 0a 20 20 20 20  |a4, a2, RRX.    |
00000690  20 20 20 20 41 44 43 20  20 20 20 20 61 33 2c 20  |    ADC     a3, |
000006a0  61 33 2c 20 61 33 0a 20  20 20 20 20 20 20 20 45  |a3, a3.        E|
000006b0  4f 52 20 20 20 20 20 61  34 2c 20 61 34 2c 20 61  |OR     a4, a4, a|
000006c0  32 2c 20 4c 53 4c 20 23  31 32 0a 20 20 20 20 20  |2, LSL #12.     |
000006d0  20 20 20 45 4f 52 20 20  20 20 20 61 32 2c 20 61  |   EOR     a2, a|
000006e0  34 2c 20 61 34 2c 20 4c  53 52 20 23 32 30 0a 09  |4, a4, LSR #20..|
000006f0  41 44 44 09 69 70 2c 20  69 70 2c 20 61 32 2c 20  |ADD.ip, ip, a2, |
00000700  4c 53 52 20 23 31 36 0a  09 4d 4f 56 09 61 34 2c  |LSR #16..MOV.a4,|
00000710  20 61 32 2c 20 4c 53 4c  20 23 31 36 0a 09 41 44  | a2, LSL #16..AD|
00000720  44 09 69 70 2c 20 69 70  2c 20 61 34 2c 20 4c 53  |D.ip, ip, a4, LS|
00000730  52 20 23 31 36 0a 0a 09  4d 4f 56 53 20 20 20 20  |R #16...MOVS    |
00000740  61 33 2c 20 61 33 2c 20  4c 53 52 20 23 31 0a 20  |a3, a3, LSR #1. |
00000750  20 20 20 20 20 20 20 4d  4f 56 53 20 20 20 20 61  |       MOVS    a|
00000760  34 2c 20 61 32 2c 20 52  52 58 0a 20 20 20 20 20  |4, a2, RRX.     |
00000770  20 20 20 41 44 43 20 20  20 20 20 61 33 2c 20 61  |   ADC     a3, a|
00000780  33 2c 20 61 33 0a 20 20  20 20 20 20 20 20 45 4f  |3, a3.        EO|
00000790  52 20 20 20 20 20 61 34  2c 20 61 34 2c 20 61 32  |R     a4, a4, a2|
000007a0  2c 20 4c 53 4c 20 23 31  32 0a 20 20 20 20 20 20  |, LSL #12.      |
000007b0  20 20 45 4f 52 20 20 20  20 20 61 32 2c 20 61 34  |  EOR     a2, a4|
000007c0  2c 20 61 34 2c 20 4c 53  52 20 23 32 30 0a 09 41  |, a4, LSR #20..A|
000007d0  44 44 09 69 70 2c 20 69  70 2c 20 61 32 2c 20 4c  |DD.ip, ip, a2, L|
000007e0  53 52 20 23 31 36 0a 09  4d 4f 56 09 61 34 2c 20  |SR #16..MOV.a4, |
000007f0  61 32 2c 20 4c 53 4c 20  23 31 36 0a 09 41 44 44  |a2, LSL #16..ADD|
00000800  09 69 70 2c 20 69 70 2c  20 61 34 2c 20 4c 53 52  |.ip, ip, a4, LSR|
00000810  20 23 31 36 0a 0a 09 4d  4f 56 53 20 20 20 20 61  | #16...MOVS    a|
00000820  33 2c 20 61 33 2c 20 4c  53 52 20 23 31 0a 20 20  |3, a3, LSR #1.  |
00000830  20 20 20 20 20 20 4d 4f  56 53 20 20 20 20 61 34  |      MOVS    a4|
00000840  2c 20 61 32 2c 20 52 52  58 0a 20 20 20 20 20 20  |, a2, RRX.      |
00000850  20 20 41 44 43 20 20 20  20 20 61 33 2c 20 61 33  |  ADC     a3, a3|
00000860  2c 20 61 33 0a 20 20 20  20 20 20 20 20 45 4f 52  |, a3.        EOR|
00000870  20 20 20 20 20 61 34 2c  20 61 34 2c 20 61 32 2c  |     a4, a4, a2,|
00000880  20 4c 53 4c 20 23 31 32  0a 20 20 20 20 20 20 20  | LSL #12.       |
00000890  20 45 4f 52 20 20 20 20  20 61 32 2c 20 61 34 2c  | EOR     a2, a4,|
000008a0  20 61 34 2c 20 4c 53 52  20 23 32 30 0a 09 41 44  | a4, LSR #20..AD|
000008b0  44 09 69 70 2c 20 69 70  2c 20 61 32 2c 20 4c 53  |D.ip, ip, a2, LS|
000008c0  52 20 23 31 36 0a 09 4d  4f 56 09 61 34 2c 20 61  |R #16..MOV.a4, a|
000008d0  32 2c 20 4c 53 4c 20 23  31 36 0a 09 41 44 44 09  |2, LSL #16..ADD.|
000008e0  69 70 2c 20 69 70 2c 20  61 34 2c 20 4c 53 52 20  |ip, ip, a4, LSR |
000008f0  23 31 36 09 09 3b 73 75  6d 20 6e 6f 77 20 69 6e  |#16..;sum now in|
00000900  20 69 70 0a 0a 09 53 54  4d 49 41 09 61 31 2c 20  | ip...STMIA.a1, |
00000910  7b 61 32 2c 20 61 33 7d  0a 0a 09 52 53 42 09 61  |{a2, a3}...RSB.a|
00000920  31 2c 20 69 70 2c 20 69  70 2c 20 41 53 4c 20 23  |1, ip, ip, ASL #|
00000930  33 0a 09 52 53 42 09 61  32 2c 20 69 70 2c 20 69  |3..RSB.a2, ip, i|
00000940  70 2c 20 41 53 4c 20 23  32 0a 09 41 44 44 09 61  |p, ASL #2..ADD.a|
00000950  31 2c 20 61 32 2c 20 61  31 2c 20 41 53 4c 20 23  |1, a2, a1, ASL #|
00000960  34 0a 09 41 44 44 09 61  31 2c 20 61 31 2c 20 69  |4..ADD.a1, a1, i|
00000970  70 2c 20 41 53 4c 20 23  39 0a 09 41 44 44 09 61  |p, ASL #9..ADD.a|
00000980  32 2c 20 69 70 2c 20 69  70 2c 20 41 53 4c 20 23  |2, ip, ip, ASL #|
00000990  34 0a 09 41 44 44 09 61  32 2c 20 61 32 2c 20 69  |4..ADD.a2, a2, i|
000009a0  70 2c 20 41 53 4c 20 23  36 0a 09 41 44 44 09 61  |p, ASL #6..ADD.a|
000009b0  31 2c 20 61 31 2c 20 61  32 2c 20 4c 53 52 20 23  |1, a1, a2, LSR #|
000009c0  31 30 0a 09 4d 4f 56 09  61 31 2c 20 61 31 2c 20  |10..MOV.a1, a1, |
000009d0  4c 53 52 20 23 39 0a 09  53 55 42 09 61 31 2c 20  |LSR #9..SUB.a1, |
000009e0  61 31 2c 20 23 26 34 45  30 30 30 0a 09 53 55 42  |a1, #&4E000..SUB|
000009f0  09 61 31 2c 20 61 31 2c  20 23 26 30 30 36 32 30  |.a1, a1, #&00620|
00000a00  0a 09 53 55 42 09 61 31  2c 20 61 31 2c 20 23 26  |..SUB.a1, a1, #&|
00000a10  30 30 30 30 34 0a 0a 20  20 20 20 20 20 20 20 4d  |00004..        M|
00000a20  4f 56 53 20 20 20 20 70  63 2c 20 6c 72 0a 0a 67  |OVS    pc, lr..g|
00000a30  61 75 73 73 73 65 65 64  31 09 44 43 44 09 2d 31  |aussseed1.DCD.-1|
00000a40  09 09 3b 62 69 74 73 20  62 30 2d 62 33 31 20 6f  |..;bits b0-b31 o|
00000a50  66 20 73 65 65 64 0a 09  09 44 43 44 09 2d 31 09  |f seed...DCD.-1.|
00000a60  09 3b 62 69 74 20 20 62  33 32 20 6f 66 20 73 65  |.;bit  b32 of se|
00000a70  65 64 20 28 69 6e 20 6c  73 62 20 6f 66 20 77 6f  |ed (in lsb of wo|
00000a80  72 64 29 0a 0a 3b 20 73  67 61 75 73 73 31 36 0a  |rd)..; sgauss16.|
00000a90  3b 20 61 20 6c 65 61 66  20 41 50 43 53 20 66 75  |; a leaf APCS fu|
00000aa0  6e 63 74 69 6f 6e 0a 3b  0a 3b 20 43 20 70 72 6f  |nction.;.; C pro|
00000ab0  74 6f 74 79 70 65 3a 0a  3b 20 76 6f 69 64 20 73  |totype:.; void s|
00000ac0  67 61 75 73 73 31 36 28  69 6e 74 20 73 65 65 64  |gauss16(int seed|
00000ad0  29 0a 3b 0a 3b 20 73 65  74 73 20 74 68 65 20 73  |).;.; sets the s|
00000ae0  65 65 64 20 66 6f 72 20  67 61 75 73 73 31 36 0a  |eed for gauss16.|
00000af0  3b 0a 0a 09 45 58 50 4f  52 54 09 73 67 61 75 73  |;...EXPORT.sgaus|
00000b00  73 31 36 0a 0a 73 67 6e  73 74 61 20 20 44 43 42  |s16..sgnsta  DCB|
00000b10  20 20 20 20 20 22 73 67  61 75 73 73 31 36 22 2c  |     "sgauss16",|
00000b20  20 30 0a 20 20 20 20 20  20 20 20 41 4c 49 47 4e  | 0.        ALIGN|
00000b30  0a 73 67 6e 65 6e 64 20  20 44 43 44 20 20 20 20  |.sgnend  DCD    |
00000b40  20 26 66 66 30 30 30 30  30 30 20 2b 20 73 67 6e  | &ff000000 + sgn|
00000b50  65 6e 64 20 2d 20 73 67  6e 73 74 61 0a 0a 73 67  |end - sgnsta..sg|
00000b60  61 75 73 73 31 36 0a 0a  09 41 44 52 09 61 32 2c  |auss16...ADR.a2,|
00000b70  20 67 61 75 73 73 73 65  65 64 31 0a 09 4d 4f 56  | gaussseed1..MOV|
00000b80  09 61 33 2c 20 23 31 0a  09 53 54 4d 49 41 09 61  |.a3, #1..STMIA.a|
00000b90  32 2c 20 7b 61 31 2c 20  61 33 7d 0a 20 20 20 20  |2, {a1, a3}.    |
00000ba0  20 20 20 20 4d 4f 56 53  20 20 20 20 70 63 2c 20  |    MOVS    pc, |
00000bb0  6c 72 0a 0a 0a 0a 3b 20  64 69 76 5f 66 72 61 63  |lr....; div_frac|
00000bc0  31 36 0a 3b 20 61 20 6c  65 61 66 20 41 50 43 53  |16.; a leaf APCS|
00000bd0  20 66 75 6e 63 74 69 6f  6e 0a 3b 0a 3b 20 43 20  | function.;.; C |
00000be0  70 72 6f 74 6f 74 79 70  65 3a 0a 3b 20 69 6e 74  |prototype:.; int|
00000bf0  20 64 69 76 5f 66 72 61  63 31 36 28 69 6e 74 20  | div_frac16(int |
00000c00  6e 75 6d 62 65 72 2c 20  69 6e 74 20 64 69 76 69  |number, int divi|
00000c10  73 6f 72 29 0a 3b 0a 3b  20 72 65 74 75 72 6e 73  |sor).;.; returns|
00000c20  20 69 6e 74 65 67 65 72  20 70 61 72 74 20 6f 66  | integer part of|
00000c30  20 36 35 35 33 36 2a 6e  75 6d 62 65 72 2f 64 69  | 65536*number/di|
00000c40  76 69 73 6f 72 0a 3b 20  61 73 73 75 6d 65 73 20  |visor.; assumes |
00000c50  61 62 73 20 6e 75 6d 62  65 72 20 3c 20 36 35 35  |abs number < 655|
00000c60  33 36 20 2a 20 61 62 73  20 64 69 76 69 73 6f 72  |36 * abs divisor|
00000c70  0a 3b 20 69 66 20 74 68  69 73 20 6e 65 65 64 73  |.; if this needs|
00000c80  20 63 68 65 63 6b 69 6e  67 2c 20 6d 75 73 74 20  | checking, must |
00000c90  62 65 20 64 6f 6e 65 20  62 79 20 63 61 6c 6c 65  |be done by calle|
00000ca0  72 0a 3b 0a 0a 20 20 20  20 20 20 20 20 45 58 50  |r.;..        EXP|
00000cb0  4f 52 54 20 20 64 69 76  5f 66 72 61 63 31 36 0a  |ORT  div_frac16.|
00000cc0  0a 64 66 6e 73 74 61 20  20 44 43 42 20 20 20 20  |.dfnsta  DCB    |
00000cd0  20 22 64 69 76 5f 66 72  61 63 31 36 22 2c 20 30  | "div_frac16", 0|
00000ce0  0a 20 20 20 20 20 20 20  20 41 4c 49 47 4e 0a 64  |.        ALIGN.d|
00000cf0  66 6e 65 6e 64 20 20 44  43 44 20 20 20 20 20 26  |fnend  DCD     &|
00000d00  66 66 30 30 30 30 30 30  20 2b 20 64 66 6e 65 6e  |ff000000 + dfnen|
00000d10  64 20 2d 20 64 66 6e 73  74 61 0a 0a 64 69 76 5f  |d - dfnsta..div_|
00000d20  66 72 61 63 31 36 0a 0a  20 20 20 20 20 20 20 20  |frac16..        |
00000d30  64 69 76 31 36 20 20 20  61 31 2c 20 61 32 2c 20  |div16   a1, a2, |
00000d40  61 31 2c 20 61 33 2c 20  61 34 0a 20 20 20 20 20  |a1, a3, a4.     |
00000d50  20 20 20 4d 4f 56 53 20  20 20 20 70 63 2c 20 6c  |   MOVS    pc, l|
00000d60  72 0a 0a 0a 0a 3b 20 6d  75 6c 5f 66 72 61 63 31  |r....; mul_frac1|
00000d70  36 0a 3b 20 61 20 6c 65  61 66 20 41 50 43 53 20  |6.; a leaf APCS |
00000d80  66 75 6e 63 74 69 6f 6e  0a 3b 0a 3b 20 43 20 70  |function.;.; C p|
00000d90  72 6f 74 6f 74 79 70 65  3a 0a 3b 20 69 6e 74 20  |rototype:.; int |
00000da0  6d 75 6c 5f 66 72 61 63  31 36 28 69 6e 74 20 78  |mul_frac16(int x|
00000db0  2c 20 69 6e 74 20 61 29  0a 3b 0a 3b 20 72 65 74  |, int a).;.; ret|
00000dc0  75 72 6e 73 20 33 32 2d  62 69 74 20 73 69 67 6e  |urns 32-bit sign|
00000dd0  65 64 20 69 6e 74 65 67  65 72 20 78 2a 61 2f 36  |ed integer x*a/6|
00000de0  35 35 33 36 0a 3b 20 61  73 73 75 6d 65 73 20 72  |5536.; assumes r|
00000df0  65 73 75 6c 74 20 66 69  74 73 20 69 6e 74 6f 20  |esult fits into |
00000e00  33 32 2d 62 69 74 20 73  69 67 6e 65 64 20 72 65  |32-bit signed re|
00000e10  70 72 65 73 65 6e 74 61  74 69 6f 6e 0a 3b 20 6e  |presentation.; n|
00000e20  6f 74 65 2c 20 6e 6f 20  6f 74 68 65 72 20 72 65  |ote, no other re|
00000e30  73 74 72 69 63 74 69 6f  6e 73 20 6f 6e 20 61 20  |strictions on a |
00000e40  2d 20 69 66 20 63 61 6e  20 67 75 61 72 61 6e 74  |- if can guarant|
00000e50  65 65 20 61 62 73 20 61  20 3c 20 36 35 35 33 36  |ee abs a < 65536|
00000e60  2c 20 75 73 65 20 6d 75  6c 5f 66 72 61 63 31 36  |, use mul_frac16|
00000e70  63 20 69 6e 73 74 65 61  64 20 61 73 20 69 73 20  |c instead as is |
00000e80  71 75 69 63 6b 65 72 0a  3b 0a 0a 20 20 20 20 20  |quicker.;..     |
00000e90  20 20 20 45 58 50 4f 52  54 20 20 6d 75 6c 5f 66  |   EXPORT  mul_f|
00000ea0  72 61 63 31 36 0a 0a 6d  66 6e 73 74 61 20 20 44  |rac16..mfnsta  D|
00000eb0  43 42 20 20 20 20 20 22  6d 75 6c 5f 66 72 61 63  |CB     "mul_frac|
00000ec0  31 36 22 2c 20 30 0a 20  20 20 20 20 20 20 20 41  |16", 0.        A|
00000ed0  4c 49 47 4e 0a 6d 66 6e  65 6e 64 20 20 44 43 44  |LIGN.mfnend  DCD|
00000ee0  20 20 20 20 20 26 66 66  30 30 30 30 30 30 20 2b  |     &ff000000 +|
00000ef0  20 6d 66 6e 65 6e 64 20  2d 20 6d 66 6e 73 74 61  | mfnend - mfnsta|
00000f00  0a 0a 6d 75 6c 5f 66 72  61 63 31 36 0a 0a 20 20  |..mul_frac16..  |
00000f10  20 20 20 20 20 20 6d 75  6c 31 36 20 20 20 61 31  |      mul16   a1|
00000f20  2c 20 61 32 2c 20 61 31  2c 20 61 33 2c 20 61 34  |, a2, a1, a3, a4|
00000f30  2c 20 69 70 0a 20 20 20  20 20 20 20 20 4d 4f 56  |, ip.        MOV|
00000f40  53 20 20 20 20 70 63 2c  20 6c 72 0a 0a 0a 0a 3b  |S    pc, lr....;|
00000f50  20 6d 75 6c 5f 66 72 61  63 31 36 63 0a 3b 20 61  | mul_frac16c.; a|
00000f60  20 6c 65 61 66 20 41 50  43 53 20 66 75 6e 63 74  | leaf APCS funct|
00000f70  69 6f 6e 0a 3b 0a 3b 20  43 20 70 72 6f 74 6f 74  |ion.;.; C protot|
00000f80  79 70 65 3a 0a 3b 20 69  6e 74 20 6d 75 6c 5f 66  |ype:.; int mul_f|
00000f90  72 61 63 31 36 63 28 69  6e 74 20 78 2c 20 69 6e  |rac16c(int x, in|
00000fa0  74 20 61 29 0a 3b 0a 3b  20 72 65 74 75 72 6e 73  |t a).;.; returns|
00000fb0  20 33 32 2d 62 69 74 20  73 69 67 6e 65 64 20 69  | 32-bit signed i|
00000fc0  6e 74 65 67 65 72 20 78  2a 61 2f 36 35 35 33 36  |nteger x*a/65536|
00000fd0  0a 3b 20 61 73 73 75 6d  65 73 20 61 62 73 20 61  |.; assumes abs a|
00000fe0  20 3c 3d 36 35 35 33 36  0a 3b 20 69 66 20 69 74  | <=65536.; if it|
00000ff0  20 69 73 20 70 6f 73 73  69 62 6c 65 20 74 68 61  | is possible tha|
00001000  74 20 61 62 73 20 61 20  3e 20 36 35 35 33 36 2c  |t abs a > 65536,|
00001010  20 63 61 6c 6c 65 72 20  6d 75 73 74 20 63 68 65  | caller must che|
00001020  63 6b 20 72 61 6e 67 65  20 26 20 65 69 74 68 65  |ck range & eithe|
00001030  72 20 6e 6f 74 20 63 61  6c 6c 20 66 6e 20 6f 72  |r not call fn or|
00001040  20 72 6f 75 6e 64 20 64  6f 77 6e 20 74 6f 20 36  | round down to 6|
00001050  35 35 33 36 0a 3b 0a 0a  20 20 20 20 20 20 20 20  |5536.;..        |
00001060  45 58 50 4f 52 54 20 20  6d 75 6c 5f 66 72 61 63  |EXPORT  mul_frac|
00001070  31 36 63 0a 0a 6d 66 63  6e 73 74 61 20 44 43 42  |16c..mfcnsta DCB|
00001080  20 20 20 20 20 22 6d 75  6c 5f 66 72 61 63 31 36  |     "mul_frac16|
00001090  63 22 2c 20 30 0a 20 20  20 20 20 20 20 20 41 4c  |c", 0.        AL|
000010a0  49 47 4e 0a 6d 66 63 6e  65 6e 64 20 44 43 44 20  |IGN.mfcnend DCD |
000010b0  20 20 20 20 26 66 66 30  30 30 30 30 30 20 2b 20  |    &ff000000 + |
000010c0  6d 66 63 6e 65 6e 64 20  2d 20 6d 66 63 6e 73 74  |mfcnend - mfcnst|
000010d0  61 0a 0a 6d 75 6c 5f 66  72 61 63 31 36 63 0a 0a  |a..mul_frac16c..|
000010e0  20 20 20 20 20 20 20 20  6d 75 6c 31 36 63 20 20  |        mul16c  |
000010f0  61 31 2c 20 61 32 2c 20  61 31 2c 20 61 33 0a 20  |a1, a2, a1, a3. |
00001100  20 20 20 20 20 20 20 4d  4f 56 53 20 20 20 20 70  |       MOVS    p|
00001110  63 2c 20 6c 72 0a 0a 0a  0a 3b 20 73 71 72 74 5f  |c, lr....; sqrt_|
00001120  66 72 61 63 32 38 0a 3b  20 61 20 6c 65 61 66 20  |frac28.; a leaf |
00001130  41 50 43 53 20 66 75 6e  63 74 69 6f 6e 0a 3b 0a  |APCS function.;.|
00001140  3b 20 43 20 70 72 6f 74  6f 74 79 70 65 3a 0a 3b  |; C prototype:.;|
00001150  20 69 6e 74 20 73 71 72  74 5f 66 72 61 63 32 38  | int sqrt_frac28|
00001160  28 75 6e 73 69 67 6e 65  64 20 69 6e 74 20 78 29  |(unsigned int x)|
00001170  0a 3b 0a 3b 20 72 65 74  75 72 6e 73 20 33 32 2d  |.;.; returns 32-|
00001180  62 69 74 20 69 6e 74 65  67 65 72 20 73 71 72 74  |bit integer sqrt|
00001190  28 78 3c 3c 32 38 29 0a  3b 0a 0a 20 20 20 20 20  |(x<<28).;..     |
000011a0  20 20 20 45 58 50 4f 52  54 20 20 73 71 72 74 5f  |   EXPORT  sqrt_|
000011b0  66 72 61 63 32 38 0a 0a  73 71 66 6e 73 74 61 20  |frac28..sqfnsta |
000011c0  44 43 42 20 20 20 20 20  22 73 71 72 74 5f 66 72  |DCB     "sqrt_fr|
000011d0  61 63 32 38 22 2c 20 30  0a 20 20 20 20 20 20 20  |ac28", 0.       |
000011e0  20 41 4c 49 47 4e 0a 73  71 66 6e 65 6e 64 20 44  | ALIGN.sqfnend D|
000011f0  43 44 20 20 20 20 20 26  66 66 30 30 30 30 30 30  |CD     &ff000000|
00001200  20 2b 20 73 71 66 6e 65  6e 64 20 2d 20 73 71 66  | + sqfnend - sqf|
00001210  6e 73 74 61 0a 0a 73 71  72 74 5f 66 72 61 63 32  |nsta..sqrt_frac2|
00001220  38 0a 0a 20 20 20 20 20  20 20 20 73 71 72 74 32  |8..        sqrt2|
00001230  38 20 20 61 31 2c 20 61  31 2c 20 61 32 2c 20 61  |8  a1, a1, a2, a|
00001240  33 2c 20 61 34 2c 20 69  70 0a 20 20 20 20 20 20  |3, a4, ip.      |
00001250  20 20 4d 4f 56 53 20 20  20 20 70 63 2c 20 6c 72  |  MOVS    pc, lr|
00001260  0a 0a 0a 0a 20 20 20 20  20 20 20 20 45 4e 44 0a  |....        END.|
00001270