| 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 |
0000 | a(4EE90028): SUB SP, SP, 28H |
0001 | a(AFE00000): STR LNK, SP, 0H |
0002 | a(A0E00004): STR R0, SP, 4H |
0003 | b(40000001): MOV R0, R0, 1H |
0004 | b(A0E00014): STR R0, SP, 14H |
0005 | c(40000004): MOV R0, R0, 4H |
0006 | c(A0E00018): STR R0, SP, 18H |
0007 | d(40000001): MOV R0, R0, 1H |
0008 | d(A0E0001C): STR R0, SP, 1CH |
0009 | e(40000004): MOV R0, R0, 4H |
000A | e(A0E00020): STR R0, SP, 20H |
000B | f(40000000): MOV R0, R0, 0H |
000C | f(A0E00010): STR R0, SP, 10H |
| FOR i := 3 TOg n DO |
000D | g(40000003): MOV R0, R0, 3H |
| REPEATh x := x + inc;i inc := 6 - inc;j |
000E | h(81E00004): LDR R1, SP, 4H |
000F | h(01090001): SUB R1, R0, R1 |
0010 | h(EE000081): BGT 129 [0092H] |
0011 | h(A0E00008): STR R0, SP, 8H |
0012 | i(80E00014): LDR R0, SP, 14H |
0013 | i(81E00018): LDR R1, SP, 18H |
0014 | i(00080001): ADD R0, R0, R1 |
0015 | i(A0E00014): STR R0, SP, 14H |
0016 | j(40000006): MOV R0, R0, 6H |
0017 | j(81E00018): LDR R1, SP, 18H |
0018 | j(00090001): SUB R0, R0, R1 |
0019 | j(A0E00018): STR R0, SP, 18H |
| IF sqr <= x THENk (*sqr = p[lim]^2*) |
001A | k(80E00020): LDR R0, SP, 20H |
001B | k(81E00014): LDR R1, SP, 14H |
001C | k(00090001): SUB R0, R0, R1 |
001D | k(EE000019): BGT 25 [0037H] |
| v[lim]l := sqr;m INC(lim);n sqr := p[lim]o*p[lim]p |
001E | l(80E0001C): LDR R0, SP, 1CH |
001F | l(41090014): SUB R1, R0, 14H |
0020 | l(DA01E51C): BLCC MT [trap=1, pos=485] |
0021 | l(40010002): LSL R0, R0, 2H |
0022 | l .FIXUP D |
0022 | l(8D000022): LDR SB, MT, MOD0 [PrimeNumbers] |
0023 | l(00D80000): ADD R0, SB, R0 [global array] |
0024 | m(81E00020): LDR R1, SP, 20H |
0025 | m(A100066C): STR R1, R0, 66CH |
0026 | n(80E0001C): LDR R0, SP, 1CH |
0027 | n(40080001): ADD R0, R0, 1H |
0028 | n(A0E0001C): STR R0, SP, 1CH |
0029 | o(80E0001C): LDR R0, SP, 1CH |
002A | o(41090190): SUB R1, R0, 190H |
002B | o(DA02051C): BLCC MT [trap=1, pos=517] |
002C | o(40010002): LSL R0, R0, 2H |
002D | o(00D80000): ADD R0, SB, R0 |
002E | p(81E0001C): LDR R1, SP, 1CH |
002F | p(42190190): SUB R2, R1, 190H |
0030 | p(DA020C1C): BLCC MT [trap=1, pos=524] |
0031 | p(41110002): LSL R1, R1, 2H |
0032 | p(01D80001): ADD R1, SB, R1 |
| ENDq ; |
0033 | q(8000002C): LDR R0, R0, 2CH |
0034 | q(8110002C): LDR R1, R1, 2CH |
0035 | q(000A0001): MUL R0, R0, R1 |
0036 | q(A0E00020): STR R0, SP, 20H |
| k := 2;r prim := TRUE;s |
0037 | r(40000002): MOV R0, R0, 2H |
0038 | r(A0E0000C): STR R0, SP, CH |
0039 | s(40000001): MOV R0, R0, 1H |
003A | s(B0E00024): STR R0, SP, 24H |
| WHILE prim & (tk < lim)u DOv |
003B | t(90E00024): LDR R0, SP, 24H |
003C | t(E1000034): BEQ 52 [0071H] |
003D | u(80E0000C): LDR R0, SP, CH |
003E | u(81E0001C): LDR R1, SP, 1CH |
003F | u(00090001): SUB R0, R0, R1 |
0040 | v(ED000030): BGE 48 [0071H] |
| INC(k);w; |
0041 | w(80E0000C): LDR R0, SP, CH |
0042 | w(40080001): ADD R0, R0, 1H |
0043 | w(A0E0000C): STR R0, SP, CH |
| IF v[k]x < x THENy v[k]z := v[k]a + p[k]b ENDc ; |
0044 | x(80E0000C): LDR R0, SP, CH |
0045 | x(41090014): SUB R1, R0, 14H |
0046 | x(DA027F1C): BLCC MT [trap=1, pos=639] |
0047 | x(40010002): LSL R0, R0, 2H |
0048 | x .FIXUP D |
0048 | x(8D000026): LDR SB, MT, MOD0 [PrimeNumbers] |
0049 | x(00D80000): ADD R0, SB, R0 [global array] |
004A | y(8000066C): LDR R0, R0, 66CH |
004B | y(81E00014): LDR R1, SP, 14H |
004C | y(00090001): SUB R0, R0, R1 |
004D | y(ED000014): BGE 20 [0062H] |
004E | z(80E0000C): LDR R0, SP, CH |
004F | z(41090014): SUB R1, R0, 14H |
0050 | z(DA028D1C): BLCC MT [trap=1, pos=653] |
0051 | z(40010002): LSL R0, R0, 2H |
0052 | z .FIXUP D |
0052 | z(8D00000A): LDR SB, MT, MOD0 [PrimeNumbers] |
0053 | z(00D80000): ADD R0, SB, R0 [global array] |
0054 | a(81E0000C): LDR R1, SP, CH |
0055 | a(42190014): SUB R2, R1, 14H |
0056 | a(DA02951C): BLCC MT [trap=1, pos=661] |
0057 | a(41110002): LSL R1, R1, 2H |
0058 | a(01D80001): ADD R1, SB, R1 |
0059 | b(82E0000C): LDR R2, SP, CH |
005A | b(43290190): SUB R3, R2, 190H |
005B | b(DA029C1C): BLCC MT [trap=1, pos=668] |
005C | b(42210002): LSL R2, R2, 2H |
005D | b(02D80002): ADD R2, SB, R2 |
005E | c(8110066C): LDR R1, R1, 66CH |
005F | c(8220002C): LDR R2, R2, 2CH |
0060 | c(01180002): ADD R1, R1, R2 |
0061 | c(A100066C): STR R1, R0, 66CH |
| prim := x # v[k]d |
0062 | d(80E0000C): LDR R0, SP, CH |
0063 | d(41090014): SUB R1, R0, 14H |
0064 | d(DA02BD1C): BLCC MT [trap=1, pos=701] |
0065 | d(40010002): LSL R0, R0, 2H |
0066 | d .FIXUP D |
0066 | d(8D000014): LDR SB, MT, MOD0 [PrimeNumbers] |
0067 | d(00D80000): ADD R0, SB, R0 [global array] |
| ENDe |
0068 | e(81E00014): LDR R1, SP, 14H |
0069 | e(8000066C): LDR R0, R0, 66CH |
006A | e(01190000): SUB R1, R1, R0 |
006B | e(E1000002): BEQ 2 [006EH] |
006C | e(40000001): MOV R0, R0, 1H |
006D | e(E7000001): B 1 [006FH] |
006E | e(40000000): MOV R0, R0, 0H |
006F | e(B0E00024): STR R0, SP, 24H |
0070 | e(E7FFFFCA): B -54 [003BH] |
| UNTIL prim;f |
0071 | f(90E00024): LDR R0, SP, 24H |
0072 | f(E1FFFF9F): BEQ -97 [0012H] |
| p[i]g := x;h Texts.WriteInt(W,i x,j 5)k;l |
0073 | g(80E00008): LDR R0, SP, 8H |
0074 | g(41090190): SUB R1, R0, 190H |
0075 | g(DA02E61C): BLCC MT [trap=1, pos=742] |
0076 | g(40010002): LSL R0, R0, 2H |
0077 | g .FIXUP D |
0077 | g(8D000011): LDR SB, MT, MOD0 [PrimeNumbers] |
0078 | g(00D80000): ADD R0, SB, R0 [global array] |
0079 | h(81E00014): LDR R1, SP, 14H |
007A | h(A100002C): STR R1, R0, 2CH |
007B | i(40D80004): ADD R0, SB, 4H |
007C | i .FIXUP D |
007C | i(8D100005): LDR SB, MT, MOD1 [Texts] |
007D | i(41D80005): ADD R1, SB, VAR5 |
007E | j(82E00014): LDR R2, SP, 14H |
007F | k(43000005): MOV R3, R0, 5H |
0080 | l .FIXUP P |
0080 | l(F711E080): BL MOD1 [Texts] PROC30 |
| IF m = 10 THENm Texts.WriteLn(W)n;o m := 0 ELSEp INCq(m) ENDr |
0081 | m(80E00010): LDR R0, SP, 10H |
0082 | m(4009000A): SUB R0, R0, AH |
0083 | m(E9000008): BNE 8 [008CH] |
0084 | n .FIXUP D |
0084 | n(8D000008): LDR SB, MT, MOD0 [PrimeNumbers] |
0085 | n(40D80004): ADD R0, SB, 4H [data] |
0086 | n .FIXUP D |
0086 | n(8D100002): LDR SB, MT, MOD1 [Texts] |
0087 | n(41D80005): ADD R1, SB, VAR5 |
0088 | o .FIXUP P |
0088 | o(F711C008): BL MOD1 [Texts] PROC28 |
0089 | p(40000000): MOV R0, R0, 0H |
008A | p(A0E00010): STR R0, SP, 10H |
008B | q(E7000003): B 3 [008FH] |
008C | r(80E00010): LDR R0, SP, 10H |
008D | r(40080001): ADD R0, R0, 1H |
008E | r(A0E00010): STR R0, SP, 10H |
| END ;s |
008F | s(80E00008): LDR R0, SP, 8H |
0090 | s(40080001): ADD R0, R0, 1H |
0091 | s(E7FFFF7C): B -132 [000EH] |
| IF m > 0 THENt Texts.WriteLn(W)u ENDv |
0092 | t(80E00010): LDR R0, SP, 10H |
0093 | t(40090000): SUB R0, R0, 0H |
0094 | t(E6000005): BLE 5 [009AH] |
0095 | u .FIXUP D |
0095 | u(8D00000F): LDR SB, MT, MOD0 [PrimeNumbers] |
0096 | u(40D80004): ADD R0, SB, 4H [data] |
0097 | u .FIXUP D |
0097 | u(8D100002): LDR SB, MT, MOD1 [Texts] |
0098 | u(41D80005): ADD R1, SB, VAR5 |
0099 | v .FIXUP P |
0099 | v(F711C011): BL MOD1 [Texts] PROC28 |
| ENDw Primes; |
009A | w(8FE00000): LDR LNK, SP, 0H |
009B | w(4EE80028): ADD SP, SP, 28H |
009C | w(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 |
009D | x .PROC 1 |
009D | x .COMMAND Generate |
009D | x(4EE90078): SUB SP, SP, 78H |
009E | x(AFE00000): STR LNK, SP, 0H |
009F | y(40E80004): ADD R0, SP, 4H |
00A0 | y .FIXUP D |
00A0 | y(8D100009): LDR SB, MT, MOD1 [Texts] |
00A1 | y(41D80003): ADD R1, SB, VAR3 |
00A2 | z .FIXUP D |
00A2 | z(8D400002): LDR SB, MT, MOD4 [Oberon] |
00A3 | z(42D8000E): ADD R2, SB, VAR14 |
00A4 | z(82200008): LDR R2, R2, 8H |
00A5 | a .FIXUP D |
00A5 | a(8D400003): LDR SB, MT, MOD4 [Oberon] |
00A6 | a(43D8000E): ADD R3, SB, VAR14 |
00A7 | a(8330000C): LDR R3, R3, CH |
00A8 | b .FIXUP P |
00A8 | b(F711500F): BL MOD1 [Texts] PROC21 |
00A9 | c(40E80004): ADD R0, SP, 4H |
00AA | c .FIXUP D |
00AA | c(8D100005): LDR SB, MT, MOD1 [Texts] |
00AB | c(41D80003): ADD R1, SB, VAR3 |
00AC | d .FIXUP P |
00AC | d(F7116004): BL MOD1 [Texts] PROC22 |
| IF S.i < 400 THENe |
00AD | e(80E00044): LDR R0, SP, 44H |
00AE | e(40090190): SUB R0, R0, 190H |
00AF | e(ED000007): BGE 7 [00B7H] |
| Primes(S.i)f;g Texts.Append(Oberon.Log,h W.buf)i |
00B0 | f(80E00044): LDR R0, SP, 44H |
00B1 | g(F7FFFF4E): BL -178 [0000H] |
00B2 | h .FIXUP D |
00B2 | h(8D400008): LDR SB, MT, MOD4 [Oberon] |
00B3 | h(80D0000D): LDR R0, SB, VAR13 |
00B4 | i .FIXUP D |
00B4 | i(8D000002): LDR SB, MT, MOD0 [PrimeNumbers] |
00B5 | i(81D00004): LDR R1, SB, 4H [data] |
| ENDj |
00B6 | j .FIXUP P |
00B6 | j(F710E00A): BL MOD1 [Texts] PROC14 |
| ENDk Generate; |
00B7 | k(8FE00000): LDR LNK, SP, 0H |
00B8 | k(4EE80078): ADD SP, SP, 78H |
00B9 | k(C700000F): B LNK |
| |
| BEGINl Texts.OpenWriter(W)m;n |
00BA | l .PROC 0 |
00BA | l .ENTRYPOINT |
00BA | l(4EE90004): SUB SP, SP, 4H |
00BB | l(AFE00000): STR LNK, SP, 0H |
00BC | m .FIXUP D |
00BC | m(8D000008): LDR SB, MT, MOD0 [PrimeNumbers] |
00BD | m(40D80004): ADD R0, SB, 4H [data] |
00BE | m .FIXUP D |
00BE | m(8D100002): LDR SB, MT, MOD1 [Texts] |
00BF | m(41D80005): ADD R1, SB, VAR5 |
00C0 | n .FIXUP P |
00C0 | n(F711700A): BL MOD1 [Texts] PROC23 |
| END PrimeNumbers.o |
00C1 | o(8FE00000): LDR LNK, SP, 0H |
00C2 | o(4EE80004): ADD SP, SP, 4H |
00C3 | o(C700000F): B LNK |