PrimeNumbers

Used Exports

BUILTINS: BOOLEAN INC INTEGER
Oberon: Log Par Par.pos Par.text
Texts: Append OpenScanner OpenWriter Scan Scanner Scanner.i WriteInt WriteLn Writer Writer.buf

MODULE PrimeNumbers; (*NW 6.9.07; Tabulate prime numbers; for Oberon-07 NW 25.1.2013*)
.MODULE PrimeNumbers (KEY 091414DD, VERSION 1, SIZE 00000A14)
.IMPORT Texts (KEY 0B9E9984)
.IMPORT Fonts (KEY F4C9F557)
.IMPORT Files (KEY 73F5D686)
.IMPORT Oberon (KEY A89CCEE2)
.IMPORT Display (KEY 4C08D3EA)
.IMPORT Viewers (KEY 25ABF199)
.DATA 6BCH
.POINTER_REFERENCES 4H 8H 28H 1CH
.FIXUP T 0H
IMPORT Texts, Oberon;
VAR n: INTEGER;
W: Texts.Writer;
p: ARRAY 400 OF INTEGER;
v: ARRAY 20 OF INTEGER;
PROCEDURE Primes(n: INTEGER);
VAR i, k, m, x, inc, lim, sqr: INTEGER; prim: BOOLEAN;
BEGINa x := 1;b inc := 4;c lim := 1;d sqr := 4;e m := 0;f
0000a(4EE90028): SUB SP, SP, 28H
0001a(AFE00000): STR LNK, SP, 0H
0002a(A0E00004): STR R0, SP, 4H
0003b(40000001): MOV R0, R0, 1H
0004b(A0E00014): STR R0, SP, 14H
0005c(40000004): MOV R0, R0, 4H
0006c(A0E00018): STR R0, SP, 18H
0007d(40000001): MOV R0, R0, 1H
0008d(A0E0001C): STR R0, SP, 1CH
0009e(40000004): MOV R0, R0, 4H
000Ae(A0E00020): STR R0, SP, 20H
000Bf(40000000): MOV R0, R0, 0H
000Cf(A0E00010): STR R0, SP, 10H
FOR i := 3 TOg n DO
000Dg(40000003): MOV R0, R0, 3H
REPEATh x := x + inc;i inc := 6 - inc;j
000Eh(81E00004): LDR R1, SP, 4H
000Fh(01090001): SUB R1, R0, R1
0010h(EE000081): BGT 129 [0092H]
0011h(A0E00008): STR R0, SP, 8H
0012i(80E00014): LDR R0, SP, 14H
0013i(81E00018): LDR R1, SP, 18H
0014i(00080001): ADD R0, R0, R1
0015i(A0E00014): STR R0, SP, 14H
0016j(40000006): MOV R0, R0, 6H
0017j(81E00018): LDR R1, SP, 18H
0018j(00090001): SUB R0, R0, R1
0019j(A0E00018): STR R0, SP, 18H
IF sqr <= x THENk (*sqr = p[lim]^2*)
001Ak(80E00020): LDR R0, SP, 20H
001Bk(81E00014): LDR R1, SP, 14H
001Ck(00090001): SUB R0, R0, R1
001Dk(EE000019): BGT 25 [0037H]
v[lim]l := sqr;m INC(lim);n sqr := p[lim]o*p[lim]p
001El(80E0001C): LDR R0, SP, 1CH
001Fl(41090014): SUB R1, R0, 14H
0020l(DA01E51C): BLCC MT [trap=1, pos=485]
0021l(40010002): LSL R0, R0, 2H
0022l .FIXUP D
0022l(8D000022): LDR SB, MT, MOD0 [PrimeNumbers]
0023l(00D80000): ADD R0, SB, R0 [global array]
0024m(81E00020): LDR R1, SP, 20H
0025m(A100066C): STR R1, R0, 66CH
0026n(80E0001C): LDR R0, SP, 1CH
0027n(40080001): ADD R0, R0, 1H
0028n(A0E0001C): STR R0, SP, 1CH
0029o(80E0001C): LDR R0, SP, 1CH
002Ao(41090190): SUB R1, R0, 190H
002Bo(DA02051C): BLCC MT [trap=1, pos=517]
002Co(40010002): LSL R0, R0, 2H
002Do(00D80000): ADD R0, SB, R0
002Ep(81E0001C): LDR R1, SP, 1CH
002Fp(42190190): SUB R2, R1, 190H
0030p(DA020C1C): BLCC MT [trap=1, pos=524]
0031p(41110002): LSL R1, R1, 2H
0032p(01D80001): ADD R1, SB, R1
ENDq ;
0033q(8000002C): LDR R0, R0, 2CH
0034q(8110002C): LDR R1, R1, 2CH
0035q(000A0001): MUL R0, R0, R1
0036q(A0E00020): STR R0, SP, 20H
k := 2;r prim := TRUE;s
0037r(40000002): MOV R0, R0, 2H
0038r(A0E0000C): STR R0, SP, CH
0039s(40000001): MOV R0, R0, 1H
003As(B0E00024): STR R0, SP, 24H
WHILE prim & (tk < lim)u DOv
003Bt(90E00024): LDR R0, SP, 24H
003Ct(E1000034): BEQ 52 [0071H]
003Du(80E0000C): LDR R0, SP, CH
003Eu(81E0001C): LDR R1, SP, 1CH
003Fu(00090001): SUB R0, R0, R1
0040v(ED000030): BGE 48 [0071H]
INC(k);w;
0041w(80E0000C): LDR R0, SP, CH
0042w(40080001): ADD R0, R0, 1H
0043w(A0E0000C): STR R0, SP, CH
IF v[k]x < x THENy v[k]z := v[k]a + p[k]b ENDc ;
0044x(80E0000C): LDR R0, SP, CH
0045x(41090014): SUB R1, R0, 14H
0046x(DA027F1C): BLCC MT [trap=1, pos=639]
0047x(40010002): LSL R0, R0, 2H
0048x .FIXUP D
0048x(8D000026): LDR SB, MT, MOD0 [PrimeNumbers]
0049x(00D80000): ADD R0, SB, R0 [global array]
004Ay(8000066C): LDR R0, R0, 66CH
004By(81E00014): LDR R1, SP, 14H
004Cy(00090001): SUB R0, R0, R1
004Dy(ED000014): BGE 20 [0062H]
004Ez(80E0000C): LDR R0, SP, CH
004Fz(41090014): SUB R1, R0, 14H
0050z(DA028D1C): BLCC MT [trap=1, pos=653]
0051z(40010002): LSL R0, R0, 2H
0052z .FIXUP D
0052z(8D00000A): LDR SB, MT, MOD0 [PrimeNumbers]
0053z(00D80000): ADD R0, SB, R0 [global array]
0054a(81E0000C): LDR R1, SP, CH
0055a(42190014): SUB R2, R1, 14H
0056a(DA02951C): BLCC MT [trap=1, pos=661]
0057a(41110002): LSL R1, R1, 2H
0058a(01D80001): ADD R1, SB, R1
0059b(82E0000C): LDR R2, SP, CH
005Ab(43290190): SUB R3, R2, 190H
005Bb(DA029C1C): BLCC MT [trap=1, pos=668]
005Cb(42210002): LSL R2, R2, 2H
005Db(02D80002): ADD R2, SB, R2
005Ec(8110066C): LDR R1, R1, 66CH
005Fc(8220002C): LDR R2, R2, 2CH
0060c(01180002): ADD R1, R1, R2
0061c(A100066C): STR R1, R0, 66CH
prim := x # v[k]d
0062d(80E0000C): LDR R0, SP, CH
0063d(41090014): SUB R1, R0, 14H
0064d(DA02BD1C): BLCC MT [trap=1, pos=701]
0065d(40010002): LSL R0, R0, 2H
0066d .FIXUP D
0066d(8D000014): LDR SB, MT, MOD0 [PrimeNumbers]
0067d(00D80000): ADD R0, SB, R0 [global array]
ENDe
0068e(81E00014): LDR R1, SP, 14H
0069e(8000066C): LDR R0, R0, 66CH
006Ae(01190000): SUB R1, R1, R0
006Be(E1000002): BEQ 2 [006EH]
006Ce(40000001): MOV R0, R0, 1H
006De(E7000001): B 1 [006FH]
006Ee(40000000): MOV R0, R0, 0H
006Fe(B0E00024): STR R0, SP, 24H
0070e(E7FFFFCA): B -54 [003BH]
UNTIL prim;f
0071f(90E00024): LDR R0, SP, 24H
0072f(E1FFFF9F): BEQ -97 [0012H]
p[i]g := x;h Texts.WriteInt(W,i x,j 5)k;l
0073g(80E00008): LDR R0, SP, 8H
0074g(41090190): SUB R1, R0, 190H
0075g(DA02E61C): BLCC MT [trap=1, pos=742]
0076g(40010002): LSL R0, R0, 2H
0077g .FIXUP D
0077g(8D000011): LDR SB, MT, MOD0 [PrimeNumbers]
0078g(00D80000): ADD R0, SB, R0 [global array]
0079h(81E00014): LDR R1, SP, 14H
007Ah(A100002C): STR R1, R0, 2CH
007Bi(40D80004): ADD R0, SB, 4H
007Ci .FIXUP D
007Ci(8D100005): LDR SB, MT, MOD1 [Texts]
007Di(41D80005): ADD R1, SB, VAR5
007Ej(82E00014): LDR R2, SP, 14H
007Fk(43000005): MOV R3, R0, 5H
0080l .FIXUP P
0080l(F711E080): BL MOD1 [Texts] PROC30
IF m = 10 THENm Texts.WriteLn(W)n;o m := 0 ELSEp INCq(m) ENDr
0081m(80E00010): LDR R0, SP, 10H
0082m(4009000A): SUB R0, R0, AH
0083m(E9000008): BNE 8 [008CH]
0084n .FIXUP D
0084n(8D000008): LDR SB, MT, MOD0 [PrimeNumbers]
0085n(40D80004): ADD R0, SB, 4H [data]
0086n .FIXUP D
0086n(8D100002): LDR SB, MT, MOD1 [Texts]
0087n(41D80005): ADD R1, SB, VAR5
0088o .FIXUP P
0088o(F711C008): BL MOD1 [Texts] PROC28
0089p(40000000): MOV R0, R0, 0H
008Ap(A0E00010): STR R0, SP, 10H
008Bq(E7000003): B 3 [008FH]
008Cr(80E00010): LDR R0, SP, 10H
008Dr(40080001): ADD R0, R0, 1H
008Er(A0E00010): STR R0, SP, 10H
END ;s
008Fs(80E00008): LDR R0, SP, 8H
0090s(40080001): ADD R0, R0, 1H
0091s(E7FFFF7C): B -132 [000EH]
IF m > 0 THENt Texts.WriteLn(W)u ENDv
0092t(80E00010): LDR R0, SP, 10H
0093t(40090000): SUB R0, R0, 0H
0094t(E6000005): BLE 5 [009AH]
0095u .FIXUP D
0095u(8D00000F): LDR SB, MT, MOD0 [PrimeNumbers]
0096u(40D80004): ADD R0, SB, 4H [data]
0097u .FIXUP D
0097u(8D100002): LDR SB, MT, MOD1 [Texts]
0098u(41D80005): ADD R1, SB, VAR5
0099v .FIXUP P
0099v(F711C011): BL MOD1 [Texts] PROC28
ENDw Primes;
009Aw(8FE00000): LDR LNK, SP, 0H
009Bw(4EE80028): ADD SP, SP, 28H
009Cw(C700000F): B LNK
PROCEDURE Generate*;
VAR S: Texts.Scanner;
BEGINx Texts.OpenScanner(S,y Oberon.Par.text,z Oberon.Par.pos)a;b Texts.Scan(S)c;d
009Dx .PROC 1
009Dx .COMMAND Generate
009Dx(4EE90078): SUB SP, SP, 78H
009Ex(AFE00000): STR LNK, SP, 0H
009Fy(40E80004): ADD R0, SP, 4H
00A0y .FIXUP D
00A0y(8D100009): LDR SB, MT, MOD1 [Texts]
00A1y(41D80003): ADD R1, SB, VAR3
00A2z .FIXUP D
00A2z(8D400002): LDR SB, MT, MOD4 [Oberon]
00A3z(42D8000E): ADD R2, SB, VAR14
00A4z(82200008): LDR R2, R2, 8H
00A5a .FIXUP D
00A5a(8D400003): LDR SB, MT, MOD4 [Oberon]
00A6a(43D8000E): ADD R3, SB, VAR14
00A7a(8330000C): LDR R3, R3, CH
00A8b .FIXUP P
00A8b(F711500F): BL MOD1 [Texts] PROC21
00A9c(40E80004): ADD R0, SP, 4H
00AAc .FIXUP D
00AAc(8D100005): LDR SB, MT, MOD1 [Texts]
00ABc(41D80003): ADD R1, SB, VAR3
00ACd .FIXUP P
00ACd(F7116004): BL MOD1 [Texts] PROC22
IF S.i < 400 THENe
00ADe(80E00044): LDR R0, SP, 44H
00AEe(40090190): SUB R0, R0, 190H
00AFe(ED000007): BGE 7 [00B7H]
Primes(S.i)f;g Texts.Append(Oberon.Log,h W.buf)i
00B0f(80E00044): LDR R0, SP, 44H
00B1g(F7FFFF4E): BL -178 [0000H]
00B2h .FIXUP D
00B2h(8D400008): LDR SB, MT, MOD4 [Oberon]
00B3h(80D0000D): LDR R0, SB, VAR13
00B4i .FIXUP D
00B4i(8D000002): LDR SB, MT, MOD0 [PrimeNumbers]
00B5i(81D00004): LDR R1, SB, 4H [data]
ENDj
00B6j .FIXUP P
00B6j(F710E00A): BL MOD1 [Texts] PROC14
ENDk Generate;
00B7k(8FE00000): LDR LNK, SP, 0H
00B8k(4EE80078): ADD SP, SP, 78H
00B9k(C700000F): B LNK
BEGINl Texts.OpenWriter(W)m;n
00BAl .PROC 0
00BAl .ENTRYPOINT
00BAl(4EE90004): SUB SP, SP, 4H
00BBl(AFE00000): STR LNK, SP, 0H
00BCm .FIXUP D
00BCm(8D000008): LDR SB, MT, MOD0 [PrimeNumbers]
00BDm(40D80004): ADD R0, SB, 4H [data]
00BEm .FIXUP D
00BEm(8D100002): LDR SB, MT, MOD1 [Texts]
00BFm(41D80005): ADD R1, SB, VAR5
00C0n .FIXUP P
00C0n(F711700A): BL MOD1 [Texts] PROC23
END PrimeNumbers.o
00C1o(8FE00000): LDR LNK, SP, 0H
00C2o(4EE80004): ADD SP, SP, 4H
00C3o(C700000F): B LNK