| MODULE Powers; (*NW 10.10.07; Tabulate positive and negative powers of 2*) |
| .MODULE Powers (KEY 543E9D84, VERSION 1, SIZE 00000404) |
| .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 28H |
| .STRING 28H " 0." |
| .POINTER_REFERENCES 0H 4H 24H 18H |
| .FIXUP T 0H |
| IMPORT Texts, Oberon; |
| |
| CONST N = 32; M = 11; (*M ~ N*log2*) |
| VAR W: Texts.Writer; |
| |
| PROCEDURE Generate*; |
| VAR i, k, n, exp: INTEGER; |
| c, r, t: INTEGER; |
| d: ARRAY M OF INTEGER; |
| f: ARRAY N OF INTEGER; |
| S: Texts.Scanner; |
| BEGINa Texts.OpenScanner(S,b Oberon.Par.text,c Oberon.Par.pos)d;e Texts.Scan(S)f;g |
0000 | a .PROC 1 |
0000 | a .COMMAND Generate |
0000 | a(4EE90140): SUB SP, SP, 140H |
0001 | a(AFE00000): STR LNK, SP, 0H |
0002 | b(40E800CC): ADD R0, SP, CCH |
0003 | b .FIXUP D |
0003 | b(8D100003): LDR SB, MT, MOD1 [Texts] |
0004 | b(41D80003): ADD R1, SB, VAR3 |
0005 | c .FIXUP D |
0005 | c(8D400002): LDR SB, MT, MOD4 [Oberon] |
0006 | c(42D8000E): ADD R2, SB, VAR14 |
0007 | c(82200008): LDR R2, R2, 8H |
0008 | d .FIXUP D |
0008 | d(8D400003): LDR SB, MT, MOD4 [Oberon] |
0009 | d(43D8000E): ADD R3, SB, VAR14 |
000A | d(8330000C): LDR R3, R3, CH |
000B | e .FIXUP P |
000B | e(F711500B): BL MOD1 [Texts] PROC21 |
000C | f(40E800CC): ADD R0, SP, CCH |
000D | f .FIXUP D |
000D | f(8D100005): LDR SB, MT, MOD1 [Texts] |
000E | f(41D80003): ADD R1, SB, VAR3 |
000F | g .FIXUP P |
000F | g(F7116004): BL MOD1 [Texts] PROC22 |
| IF (S.class = Texts.Int)h & (iS.i <= N)j THENk |
0010 | h(80E00108): LDR R0, SP, 108H |
0011 | h(40090003): SUB R0, R0, 3H |
0012 | i(E90000C3): BNE 195 [00D6H] |
0013 | j(80E0010C): LDR R0, SP, 10CH |
0014 | j(40090020): SUB R0, R0, 20H |
0015 | k(EE0000C0): BGT 192 [00D6H] |
| n := S.i;l d[0] := 1;m k := 1;n exp := 1;o |
0016 | l(80E0010C): LDR R0, SP, 10CH |
0017 | l(A0E0000C): STR R0, SP, CH |
0018 | m(40000001): MOV R0, R0, 1H |
0019 | m(A0E00020): STR R0, SP, 20H |
001A | n(40000001): MOV R0, R0, 1H |
001B | n(A0E00008): STR R0, SP, 8H |
001C | o(40000001): MOV R0, R0, 1H |
001D | o(A0E00010): STR R0, SP, 10H |
| WHILE exp < n DOp |
001E | p(80E00010): LDR R0, SP, 10H |
001F | p(81E0000C): LDR R1, SP, CH |
0020 | p(00090001): SUB R0, R0, R1 |
0021 | p(ED0000AF): BGE 175 [00D1H] |
| (*compute d = 2^exp*) |
| c := 0;q (*carry*) i := 0;r |
0022 | q(40000000): MOV R0, R0, 0H |
0023 | q(A0E00014): STR R0, SP, 14H |
0024 | r(40000000): MOV R0, R0, 0H |
0025 | r(A0E00004): STR R0, SP, 4H |
| WHILE i < k DOs |
0026 | s(80E00004): LDR R0, SP, 4H |
0027 | s(81E00008): LDR R1, SP, 8H |
0028 | s(00090001): SUB R0, R0, R1 |
0029 | s(ED000025): BGE 37 [004FH] |
| t := 2*d[i]t +u c;v |
002A | t(80E00004): LDR R0, SP, 4H |
002B | t(4109000B): SUB R1, R0, BH |
002C | t(DA02761C): BLCC MT [trap=1, pos=630] |
002D | t(40010002): LSL R0, R0, 2H |
002E | t(00E80000): ADD R0, SP, R0 |
002F | u(80000020): LDR R0, R0, 20H |
0030 | u(40010001): LSL R0, R0, 1H |
0031 | v(81E00014): LDR R1, SP, 14H |
0032 | v(00080001): ADD R0, R0, R1 |
0033 | v(A0E0001C): STR R0, SP, 1CH |
| IF t < 10 THENw d[i]x := t;y c := 0 ELSEz da[i]b := t - 10;c c := 1 ENDd ; |
0034 | w(80E0001C): LDR R0, SP, 1CH |
0035 | w(4009000A): SUB R0, R0, AH |
0036 | w(ED00000A): BGE 10 [0041H] |
0037 | x(80E00004): LDR R0, SP, 4H |
0038 | x(4109000B): SUB R1, R0, BH |
0039 | x(DA02991C): BLCC MT [trap=1, pos=665] |
003A | x(40010002): LSL R0, R0, 2H |
003B | x(00E80000): ADD R0, SP, R0 |
003C | y(81E0001C): LDR R1, SP, 1CH |
003D | y(A1000020): STR R1, R0, 20H |
003E | z(40000000): MOV R0, R0, 0H |
003F | z(A0E00014): STR R0, SP, 14H |
0040 | a(E700000A): B 10 [004BH] |
0041 | b(80E00004): LDR R0, SP, 4H |
0042 | b(4109000B): SUB R1, R0, BH |
0043 | b(DA02B01C): BLCC MT [trap=1, pos=688] |
0044 | b(40010002): LSL R0, R0, 2H |
0045 | b(00E80000): ADD R0, SP, R0 |
0046 | c(81E0001C): LDR R1, SP, 1CH |
0047 | c(4119000A): SUB R1, R1, AH |
0048 | c(A1000020): STR R1, R0, 20H |
0049 | d(40000001): MOV R0, R0, 1H |
004A | d(A0E00014): STR R0, SP, 14H |
| i := i+1 |
| ENDe ; |
004B | e(80E00004): LDR R0, SP, 4H |
004C | e(40080001): ADD R0, R0, 1H |
004D | e(A0E00004): STR R0, SP, 4H |
004E | e(E7FFFFD7): B -41 [0026H] |
| IF c = 1 THENf d[k]g := 1;h k := k+1 ENDi ; |
004F | f(80E00014): LDR R0, SP, 14H |
0050 | f(40090001): SUB R0, R0, 1H |
0051 | f(E900000A): BNE 10 [005CH] |
0052 | g(80E00008): LDR R0, SP, 8H |
0053 | g(4109000B): SUB R1, R0, BH |
0054 | g(DA03041C): BLCC MT [trap=1, pos=772] |
0055 | g(40010002): LSL R0, R0, 2H |
0056 | g(00E80000): ADD R0, SP, R0 |
0057 | h(41000001): MOV R1, R0, 1H |
0058 | h(A1000020): STR R1, R0, 20H |
0059 | i(80E00008): LDR R0, SP, 8H |
005A | i(40080001): ADD R0, R0, 1H |
005B | i(A0E00008): STR R0, SP, 8H |
| (*write d*) i := M;j |
005C | j(4000000B): MOV R0, R0, BH |
005D | j(A0E00004): STR R0, SP, 4H |
| WHILE i > k DOk i := i-1;l Texts.Write(W,m " ")n ENDo ; |
005E | k(80E00004): LDR R0, SP, 4H |
005F | k(81E00008): LDR R1, SP, 8H |
0060 | k(00090001): SUB R0, R0, R1 |
0061 | k(E600000A): BLE 10 [006CH] |
0062 | l(80E00004): LDR R0, SP, 4H |
0063 | l(40090001): SUB R0, R0, 1H |
0064 | l(A0E00004): STR R0, SP, 4H |
0065 | m .FIXUP D |
0065 | m(8D000058): LDR SB, MT, MOD0 [Powers] |
0066 | m(40D80000): ADD R0, SB, 0H [data] |
0067 | m .FIXUP D |
0067 | m(8D100002): LDR SB, MT, MOD1 [Texts] |
0068 | m(41D80005): ADD R1, SB, VAR5 |
0069 | n(42000020): MOV R2, R0, 20H |
006A | o .FIXUP P |
006A | o(F711B05B): BL MOD1 [Texts] PROC27 |
006B | o(E7FFFFF2): B -14 [005EH] |
| WHILE i > 0 DOp i := i-1;q Texts.Write(W,r CHR(d[i]s + 30H)t) ENDu ; |
006C | p(80E00004): LDR R0, SP, 4H |
006D | p(40090000): SUB R0, R0, 0H |
006E | p(E6000010): BLE 16 [007FH] |
006F | q(80E00004): LDR R0, SP, 4H |
0070 | q(40090001): SUB R0, R0, 1H |
0071 | q(A0E00004): STR R0, SP, 4H |
0072 | r .FIXUP D |
0072 | r(8D00000B): LDR SB, MT, MOD0 [Powers] |
0073 | r(40D80000): ADD R0, SB, 0H [data] |
0074 | r .FIXUP D |
0074 | r(8D100002): LDR SB, MT, MOD1 [Texts] |
0075 | r(41D80005): ADD R1, SB, VAR5 |
0076 | s(82E00004): LDR R2, SP, 4H |
0077 | s(4329000B): SUB R3, R2, BH |
0078 | s(DA03A91C): BLCC MT [trap=1, pos=937] |
0079 | s(42210002): LSL R2, R2, 2H |
007A | s(02E80002): ADD R2, SP, R2 |
007B | t(82200020): LDR R2, R2, 20H |
007C | t(42280030): ADD R2, R2, 30H |
007D | u .FIXUP P |
007D | u(F711B013): BL MOD1 [Texts] PROC27 |
007E | u(E7FFFFED): B -19 [006CH] |
| Texts.WriteInt(W,v exp,w M)x;y |
007F | v .FIXUP D |
007F | v(8D00000B): LDR SB, MT, MOD0 [Powers] |
0080 | v(40D80000): ADD R0, SB, 0H [data] |
0081 | v .FIXUP D |
0081 | v(8D100002): LDR SB, MT, MOD1 [Texts] |
0082 | v(41D80005): ADD R1, SB, VAR5 |
0083 | w(82E00010): LDR R2, SP, 10H |
0084 | x(4300000B): MOV R3, R0, BH |
0085 | y .FIXUP P |
0085 | y(F711E008): BL MOD1 [Texts] PROC30 |
| (*compute f = 2^-exp*) |
| Texts.WriteString(W,z " 0.")a;b r := 0;c i := 1;d |
0086 | z .FIXUP D |
0086 | z(8D000005): LDR SB, MT, MOD0 [Powers] |
0087 | z(40D80000): ADD R0, SB, 0H [data] |
0088 | z .FIXUP D |
0088 | z(8D100002): LDR SB, MT, MOD1 [Texts] |
0089 | z(41D80005): ADD R1, SB, VAR5 |
008A | a .FIXUP D |
008A | a(8D000002): LDR SB, MT, MOD0 [Powers] |
008B | a(42D80028): ADD R2, SB, 28H [" 0."] |
008C | a(43000005): MOV R3, R0, 5H |
008D | b .FIXUP P |
008D | b(F711D008): BL MOD1 [Texts] PROC29 |
008E | c(40000000): MOV R0, R0, 0H |
008F | c(A0E00018): STR R0, SP, 18H |
0090 | d(40000001): MOV R0, R0, 1H |
0091 | d(A0E00004): STR R0, SP, 4H |
| WHILE i < exp DOe |
0092 | e(80E00004): LDR R0, SP, 4H |
0093 | e(81E00010): LDR R1, SP, 10H |
0094 | e(00090001): SUB R0, R0, R1 |
0095 | e(ED000025): BGE 37 [00BBH] |
| r := 10*r +f f[i]g;h f[i]i := r DIV 2;j r := r MOD 2;k |
0096 | f(80E00018): LDR R0, SP, 18H |
0097 | f(400A000A): MUL R0, R0, AH |
0098 | g(81E00004): LDR R1, SP, 4H |
0099 | g(42190020): SUB R2, R1, 20H |
009A | g(DA04641C): BLCC MT [trap=1, pos=1124] |
009B | g(41110002): LSL R1, R1, 2H |
009C | g(01E80001): ADD R1, SP, R1 |
009D | h(8110004C): LDR R1, R1, 4CH |
009E | h(00080001): ADD R0, R0, R1 |
009F | h(A0E00018): STR R0, SP, 18H |
00A0 | i(80E00004): LDR R0, SP, 4H |
00A1 | i(41090020): SUB R1, R0, 20H |
00A2 | i(DA046A1C): BLCC MT [trap=1, pos=1130] |
00A3 | i(40010002): LSL R0, R0, 2H |
00A4 | i(00E80000): ADD R0, SP, R0 |
00A5 | j(81E00018): LDR R1, SP, 18H |
00A6 | j(41120001): ASR R1, R1, 1H |
00A7 | j(A100004C): STR R1, R0, 4CH |
00A8 | k(80E00018): LDR R0, SP, 18H |
00A9 | k(40040001): AND R0, R0, 1H |
00AA | k(A0E00018): STR R0, SP, 18H |
| Texts.Write(W,l CHR(f[i]m + 30H)n);o i := i+1 |
00AB | l .FIXUP D |
00AB | l(8D000021): LDR SB, MT, MOD0 [Powers] |
00AC | l(40D80000): ADD R0, SB, 0H [data] |
00AD | l .FIXUP D |
00AD | l(8D100002): LDR SB, MT, MOD1 [Texts] |
00AE | l(41D80005): ADD R1, SB, VAR5 |
00AF | m(82E00004): LDR R2, SP, 4H |
00B0 | m(43290020): SUB R3, R2, 20H |
00B1 | m(DA04A61C): BLCC MT [trap=1, pos=1190] |
00B2 | m(42210002): LSL R2, R2, 2H |
00B3 | m(02E80002): ADD R2, SP, R2 |
00B4 | n(8220004C): LDR R2, R2, 4CH |
00B5 | n(42280030): ADD R2, R2, 30H |
00B6 | o .FIXUP P |
00B6 | o(F711B029): BL MOD1 [Texts] PROC27 |
| ENDp ; |
00B7 | p(80E00004): LDR R0, SP, 4H |
00B8 | p(40080001): ADD R0, R0, 1H |
00B9 | p(A0E00004): STR R0, SP, 4H |
00BA | p(E7FFFFD7): B -41 [0092H] |
| f[exp]q := 5;r Texts.Write(W,s "5")t;u Texts.WriteLn(W)v;w exp := exp + 1 |
00BB | q(80E00010): LDR R0, SP, 10H |
00BC | q(41090020): SUB R1, R0, 20H |
00BD | q(DA04D51C): BLCC MT [trap=1, pos=1237] |
00BE | q(40010002): LSL R0, R0, 2H |
00BF | q(00E80000): ADD R0, SP, R0 |
00C0 | r(41000005): MOV R1, R0, 5H |
00C1 | r(A100004C): STR R1, R0, 4CH |
00C2 | s .FIXUP D |
00C2 | s(8D000015): LDR SB, MT, MOD0 [Powers] |
00C3 | s(40D80000): ADD R0, SB, 0H [data] |
00C4 | s .FIXUP D |
00C4 | s(8D100002): LDR SB, MT, MOD1 [Texts] |
00C5 | s(41D80005): ADD R1, SB, VAR5 |
00C6 | t(42000035): MOV R2, R0, 35H |
00C7 | u .FIXUP P |
00C7 | u(F711B011): BL MOD1 [Texts] PROC27 |
00C8 | v .FIXUP D |
00C8 | v(8D000004): LDR SB, MT, MOD0 [Powers] |
00C9 | v(40D80000): ADD R0, SB, 0H [data] |
00CA | v .FIXUP D |
00CA | v(8D100002): LDR SB, MT, MOD1 [Texts] |
00CB | v(41D80005): ADD R1, SB, VAR5 |
00CC | w .FIXUP P |
00CC | w(F711C005): BL MOD1 [Texts] PROC28 |
| ENDx ; |
00CD | x(80E00010): LDR R0, SP, 10H |
00CE | x(40080001): ADD R0, R0, 1H |
00CF | x(A0E00010): STR R0, SP, 10H |
00D0 | x(E7FFFF4D): B -179 [001EH] |
| Texts.Append(Oberon.Log,y W.buf)z |
00D1 | y .FIXUP D |
00D1 | y(8D400007): LDR SB, MT, MOD4 [Oberon] |
00D2 | y(80D0000D): LDR R0, SB, VAR13 |
00D3 | z .FIXUP D |
00D3 | z(8D000002): LDR SB, MT, MOD0 [Powers] |
00D4 | z(81D00000): LDR R1, SB, 0H [data] |
| ENDa |
00D5 | a .FIXUP P |
00D5 | a(F710E009): BL MOD1 [Texts] PROC14 |
| ENDb Generate; |
00D6 | b(8FE00000): LDR LNK, SP, 0H |
00D7 | b(4EE80140): ADD SP, SP, 140H |
00D8 | b(C700000F): B LNK |
| |
| BEGINc Texts.OpenWriter(W)d |
00D9 | c .PROC 0 |
00D9 | c .ENTRYPOINT |
00D9 | c(4EE90004): SUB SP, SP, 4H |
00DA | c(AFE00000): STR LNK, SP, 0H |
00DB | d .FIXUP D |
00DB | d(8D000008): LDR SB, MT, MOD0 [Powers] |
00DC | d(40D80000): ADD R0, SB, 0H [data] |
00DD | d .FIXUP D |
00DD | d(8D100002): LDR SB, MT, MOD1 [Texts] |
00DE | d(41D80005): ADD R1, SB, VAR5 |
| ENDe Powers.f |
00DF | e .FIXUP P |
00DF | e(F711700A): BL MOD1 [Texts] PROC23 |
00E0 | f(8FE00000): LDR LNK, SP, 0H |
00E1 | f(4EE80004): ADD SP, SP, 4H |
00E2 | f(C700000F): B LNK |