Powers

Used Exports

BUILTINS: CHR INTEGER
Oberon: Log Par Par.pos Par.text
Texts: Append Int OpenScanner OpenWriter Scan Scanner Scanner.class Scanner.i Write WriteInt WriteLn WriteString Writer Writer.buf

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
0000a .PROC 1
0000a .COMMAND Generate
0000a(4EE90140): SUB SP, SP, 140H
0001a(AFE00000): STR LNK, SP, 0H
0002b(40E800CC): ADD R0, SP, CCH
0003b .FIXUP D
0003b(8D100003): LDR SB, MT, MOD1 [Texts]
0004b(41D80003): ADD R1, SB, VAR3
0005c .FIXUP D
0005c(8D400002): LDR SB, MT, MOD4 [Oberon]
0006c(42D8000E): ADD R2, SB, VAR14
0007c(82200008): LDR R2, R2, 8H
0008d .FIXUP D
0008d(8D400003): LDR SB, MT, MOD4 [Oberon]
0009d(43D8000E): ADD R3, SB, VAR14
000Ad(8330000C): LDR R3, R3, CH
000Be .FIXUP P
000Be(F711500B): BL MOD1 [Texts] PROC21
000Cf(40E800CC): ADD R0, SP, CCH
000Df .FIXUP D
000Df(8D100005): LDR SB, MT, MOD1 [Texts]
000Ef(41D80003): ADD R1, SB, VAR3
000Fg .FIXUP P
000Fg(F7116004): BL MOD1 [Texts] PROC22
IF (S.class = Texts.Int)h & (iS.i <= N)j THENk
0010h(80E00108): LDR R0, SP, 108H
0011h(40090003): SUB R0, R0, 3H
0012i(E90000C3): BNE 195 [00D6H]
0013j(80E0010C): LDR R0, SP, 10CH
0014j(40090020): SUB R0, R0, 20H
0015k(EE0000C0): BGT 192 [00D6H]
n := S.i;l d[0] := 1;m k := 1;n exp := 1;o
0016l(80E0010C): LDR R0, SP, 10CH
0017l(A0E0000C): STR R0, SP, CH
0018m(40000001): MOV R0, R0, 1H
0019m(A0E00020): STR R0, SP, 20H
001An(40000001): MOV R0, R0, 1H
001Bn(A0E00008): STR R0, SP, 8H
001Co(40000001): MOV R0, R0, 1H
001Do(A0E00010): STR R0, SP, 10H
WHILE exp < n DOp
001Ep(80E00010): LDR R0, SP, 10H
001Fp(81E0000C): LDR R1, SP, CH
0020p(00090001): SUB R0, R0, R1
0021p(ED0000AF): BGE 175 [00D1H]
(*compute d = 2^exp*)
c := 0;q (*carry*) i := 0;r
0022q(40000000): MOV R0, R0, 0H
0023q(A0E00014): STR R0, SP, 14H
0024r(40000000): MOV R0, R0, 0H
0025r(A0E00004): STR R0, SP, 4H
WHILE i < k DOs
0026s(80E00004): LDR R0, SP, 4H
0027s(81E00008): LDR R1, SP, 8H
0028s(00090001): SUB R0, R0, R1
0029s(ED000025): BGE 37 [004FH]
t := 2*d[i]t +u c;v
002At(80E00004): LDR R0, SP, 4H
002Bt(4109000B): SUB R1, R0, BH
002Ct(DA02761C): BLCC MT [trap=1, pos=630]
002Dt(40010002): LSL R0, R0, 2H
002Et(00E80000): ADD R0, SP, R0
002Fu(80000020): LDR R0, R0, 20H
0030u(40010001): LSL R0, R0, 1H
0031v(81E00014): LDR R1, SP, 14H
0032v(00080001): ADD R0, R0, R1
0033v(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 ;
0034w(80E0001C): LDR R0, SP, 1CH
0035w(4009000A): SUB R0, R0, AH
0036w(ED00000A): BGE 10 [0041H]
0037x(80E00004): LDR R0, SP, 4H
0038x(4109000B): SUB R1, R0, BH
0039x(DA02991C): BLCC MT [trap=1, pos=665]
003Ax(40010002): LSL R0, R0, 2H
003Bx(00E80000): ADD R0, SP, R0
003Cy(81E0001C): LDR R1, SP, 1CH
003Dy(A1000020): STR R1, R0, 20H
003Ez(40000000): MOV R0, R0, 0H
003Fz(A0E00014): STR R0, SP, 14H
0040a(E700000A): B 10 [004BH]
0041b(80E00004): LDR R0, SP, 4H
0042b(4109000B): SUB R1, R0, BH
0043b(DA02B01C): BLCC MT [trap=1, pos=688]
0044b(40010002): LSL R0, R0, 2H
0045b(00E80000): ADD R0, SP, R0
0046c(81E0001C): LDR R1, SP, 1CH
0047c(4119000A): SUB R1, R1, AH
0048c(A1000020): STR R1, R0, 20H
0049d(40000001): MOV R0, R0, 1H
004Ad(A0E00014): STR R0, SP, 14H
i := i+1
ENDe ;
004Be(80E00004): LDR R0, SP, 4H
004Ce(40080001): ADD R0, R0, 1H
004De(A0E00004): STR R0, SP, 4H
004Ee(E7FFFFD7): B -41 [0026H]
IF c = 1 THENf d[k]g := 1;h k := k+1 ENDi ;
004Ff(80E00014): LDR R0, SP, 14H
0050f(40090001): SUB R0, R0, 1H
0051f(E900000A): BNE 10 [005CH]
0052g(80E00008): LDR R0, SP, 8H
0053g(4109000B): SUB R1, R0, BH
0054g(DA03041C): BLCC MT [trap=1, pos=772]
0055g(40010002): LSL R0, R0, 2H
0056g(00E80000): ADD R0, SP, R0
0057h(41000001): MOV R1, R0, 1H
0058h(A1000020): STR R1, R0, 20H
0059i(80E00008): LDR R0, SP, 8H
005Ai(40080001): ADD R0, R0, 1H
005Bi(A0E00008): STR R0, SP, 8H
(*write d*) i := M;j
005Cj(4000000B): MOV R0, R0, BH
005Dj(A0E00004): STR R0, SP, 4H
WHILE i > k DOk i := i-1;l Texts.Write(W,m " ")n ENDo ;
005Ek(80E00004): LDR R0, SP, 4H
005Fk(81E00008): LDR R1, SP, 8H
0060k(00090001): SUB R0, R0, R1
0061k(E600000A): BLE 10 [006CH]
0062l(80E00004): LDR R0, SP, 4H
0063l(40090001): SUB R0, R0, 1H
0064l(A0E00004): STR R0, SP, 4H
0065m .FIXUP D
0065m(8D000058): LDR SB, MT, MOD0 [Powers]
0066m(40D80000): ADD R0, SB, 0H [data]
0067m .FIXUP D
0067m(8D100002): LDR SB, MT, MOD1 [Texts]
0068m(41D80005): ADD R1, SB, VAR5
0069n(42000020): MOV R2, R0, 20H
006Ao .FIXUP P
006Ao(F711B05B): BL MOD1 [Texts] PROC27
006Bo(E7FFFFF2): B -14 [005EH]
WHILE i > 0 DOp i := i-1;q Texts.Write(W,r CHR(d[i]s + 30H)t) ENDu ;
006Cp(80E00004): LDR R0, SP, 4H
006Dp(40090000): SUB R0, R0, 0H
006Ep(E6000010): BLE 16 [007FH]
006Fq(80E00004): LDR R0, SP, 4H
0070q(40090001): SUB R0, R0, 1H
0071q(A0E00004): STR R0, SP, 4H
0072r .FIXUP D
0072r(8D00000B): LDR SB, MT, MOD0 [Powers]
0073r(40D80000): ADD R0, SB, 0H [data]
0074r .FIXUP D
0074r(8D100002): LDR SB, MT, MOD1 [Texts]
0075r(41D80005): ADD R1, SB, VAR5
0076s(82E00004): LDR R2, SP, 4H
0077s(4329000B): SUB R3, R2, BH
0078s(DA03A91C): BLCC MT [trap=1, pos=937]
0079s(42210002): LSL R2, R2, 2H
007As(02E80002): ADD R2, SP, R2
007Bt(82200020): LDR R2, R2, 20H
007Ct(42280030): ADD R2, R2, 30H
007Du .FIXUP P
007Du(F711B013): BL MOD1 [Texts] PROC27
007Eu(E7FFFFED): B -19 [006CH]
Texts.WriteInt(W,v exp,w M)x;y
007Fv .FIXUP D
007Fv(8D00000B): LDR SB, MT, MOD0 [Powers]
0080v(40D80000): ADD R0, SB, 0H [data]
0081v .FIXUP D
0081v(8D100002): LDR SB, MT, MOD1 [Texts]
0082v(41D80005): ADD R1, SB, VAR5
0083w(82E00010): LDR R2, SP, 10H
0084x(4300000B): MOV R3, R0, BH
0085y .FIXUP P
0085y(F711E008): BL MOD1 [Texts] PROC30
(*compute f = 2^-exp*)
Texts.WriteString(W,z " 0.")a;b r := 0;c i := 1;d
0086z .FIXUP D
0086z(8D000005): LDR SB, MT, MOD0 [Powers]
0087z(40D80000): ADD R0, SB, 0H [data]
0088z .FIXUP D
0088z(8D100002): LDR SB, MT, MOD1 [Texts]
0089z(41D80005): ADD R1, SB, VAR5
008Aa .FIXUP D
008Aa(8D000002): LDR SB, MT, MOD0 [Powers]
008Ba(42D80028): ADD R2, SB, 28H [" 0."]
008Ca(43000005): MOV R3, R0, 5H
008Db .FIXUP P
008Db(F711D008): BL MOD1 [Texts] PROC29
008Ec(40000000): MOV R0, R0, 0H
008Fc(A0E00018): STR R0, SP, 18H
0090d(40000001): MOV R0, R0, 1H
0091d(A0E00004): STR R0, SP, 4H
WHILE i < exp DOe
0092e(80E00004): LDR R0, SP, 4H
0093e(81E00010): LDR R1, SP, 10H
0094e(00090001): SUB R0, R0, R1
0095e(ED000025): BGE 37 [00BBH]
r := 10*r +f f[i]g;h f[i]i := r DIV 2;j r := r MOD 2;k
0096f(80E00018): LDR R0, SP, 18H
0097f(400A000A): MUL R0, R0, AH
0098g(81E00004): LDR R1, SP, 4H
0099g(42190020): SUB R2, R1, 20H
009Ag(DA04641C): BLCC MT [trap=1, pos=1124]
009Bg(41110002): LSL R1, R1, 2H
009Cg(01E80001): ADD R1, SP, R1
009Dh(8110004C): LDR R1, R1, 4CH
009Eh(00080001): ADD R0, R0, R1
009Fh(A0E00018): STR R0, SP, 18H
00A0i(80E00004): LDR R0, SP, 4H
00A1i(41090020): SUB R1, R0, 20H
00A2i(DA046A1C): BLCC MT [trap=1, pos=1130]
00A3i(40010002): LSL R0, R0, 2H
00A4i(00E80000): ADD R0, SP, R0
00A5j(81E00018): LDR R1, SP, 18H
00A6j(41120001): ASR R1, R1, 1H
00A7j(A100004C): STR R1, R0, 4CH
00A8k(80E00018): LDR R0, SP, 18H
00A9k(40040001): AND R0, R0, 1H
00AAk(A0E00018): STR R0, SP, 18H
Texts.Write(W,l CHR(f[i]m + 30H)n);o i := i+1
00ABl .FIXUP D
00ABl(8D000021): LDR SB, MT, MOD0 [Powers]
00ACl(40D80000): ADD R0, SB, 0H [data]
00ADl .FIXUP D
00ADl(8D100002): LDR SB, MT, MOD1 [Texts]
00AEl(41D80005): ADD R1, SB, VAR5
00AFm(82E00004): LDR R2, SP, 4H
00B0m(43290020): SUB R3, R2, 20H
00B1m(DA04A61C): BLCC MT [trap=1, pos=1190]
00B2m(42210002): LSL R2, R2, 2H
00B3m(02E80002): ADD R2, SP, R2
00B4n(8220004C): LDR R2, R2, 4CH
00B5n(42280030): ADD R2, R2, 30H
00B6o .FIXUP P
00B6o(F711B029): BL MOD1 [Texts] PROC27
ENDp ;
00B7p(80E00004): LDR R0, SP, 4H
00B8p(40080001): ADD R0, R0, 1H
00B9p(A0E00004): STR R0, SP, 4H
00BAp(E7FFFFD7): B -41 [0092H]
f[exp]q := 5;r Texts.Write(W,s "5")t;u Texts.WriteLn(W)v;w exp := exp + 1
00BBq(80E00010): LDR R0, SP, 10H
00BCq(41090020): SUB R1, R0, 20H
00BDq(DA04D51C): BLCC MT [trap=1, pos=1237]
00BEq(40010002): LSL R0, R0, 2H
00BFq(00E80000): ADD R0, SP, R0
00C0r(41000005): MOV R1, R0, 5H
00C1r(A100004C): STR R1, R0, 4CH
00C2s .FIXUP D
00C2s(8D000015): LDR SB, MT, MOD0 [Powers]
00C3s(40D80000): ADD R0, SB, 0H [data]
00C4s .FIXUP D
00C4s(8D100002): LDR SB, MT, MOD1 [Texts]
00C5s(41D80005): ADD R1, SB, VAR5
00C6t(42000035): MOV R2, R0, 35H
00C7u .FIXUP P
00C7u(F711B011): BL MOD1 [Texts] PROC27
00C8v .FIXUP D
00C8v(8D000004): LDR SB, MT, MOD0 [Powers]
00C9v(40D80000): ADD R0, SB, 0H [data]
00CAv .FIXUP D
00CAv(8D100002): LDR SB, MT, MOD1 [Texts]
00CBv(41D80005): ADD R1, SB, VAR5
00CCw .FIXUP P
00CCw(F711C005): BL MOD1 [Texts] PROC28
ENDx ;
00CDx(80E00010): LDR R0, SP, 10H
00CEx(40080001): ADD R0, R0, 1H
00CFx(A0E00010): STR R0, SP, 10H
00D0x(E7FFFF4D): B -179 [001EH]
Texts.Append(Oberon.Log,y W.buf)z
00D1y .FIXUP D
00D1y(8D400007): LDR SB, MT, MOD4 [Oberon]
00D2y(80D0000D): LDR R0, SB, VAR13
00D3z .FIXUP D
00D3z(8D000002): LDR SB, MT, MOD0 [Powers]
00D4z(81D00000): LDR R1, SB, 0H [data]
ENDa
00D5a .FIXUP P
00D5a(F710E009): BL MOD1 [Texts] PROC14
ENDb Generate;
00D6b(8FE00000): LDR LNK, SP, 0H
00D7b(4EE80140): ADD SP, SP, 140H
00D8b(C700000F): B LNK
BEGINc Texts.OpenWriter(W)d
00D9c .PROC 0
00D9c .ENTRYPOINT
00D9c(4EE90004): SUB SP, SP, 4H
00DAc(AFE00000): STR LNK, SP, 0H
00DBd .FIXUP D
00DBd(8D000008): LDR SB, MT, MOD0 [Powers]
00DCd(40D80000): ADD R0, SB, 0H [data]
00DDd .FIXUP D
00DDd(8D100002): LDR SB, MT, MOD1 [Texts]
00DEd(41D80005): ADD R1, SB, VAR5
ENDe Powers.f
00DFe .FIXUP P
00DFe(F711700A): BL MOD1 [Texts] PROC23
00E0f(8FE00000): LDR LNK, SP, 0H
00E1f(4EE80004): ADD SP, SP, 4H
00E2f(C700000F): B LNK