MagicSquares

Used Exports

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

MODULE MagicSquares; (*NW 11.8.97*)
.MODULE MagicSquares (KEY 0D0115D7, VERSION 1, SIZE 000002E0)
.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
.POINTER_REFERENCES 0H 4H 24H 18H
.FIXUP T 0H
IMPORT Texts, Oberon;
VAR W: Texts.Writer;
PROCEDURE Generate*; (*magic square of order 3, 5, 7, ... *)
VAR i, j, x, nx, nsq, n: INTEGER;
M: ARRAY 13, 13 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(4EE90334): SUB SP, SP, 334H
0001a(AFE00000): STR LNK, SP, 0H
0002b(40E802C0): ADD R0, SP, 2C0H
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(40E802C0): ADD R0, SP, 2C0H
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 THENh
0010h(80E002FC): LDR R0, SP, 2FCH
0011h(40090003): SUB R0, R0, 3H
0012h(E900007C): BNE 124 [008FH]
n := S.i;i nsq := n*n;j x := 0;k
0013i(80E00300): LDR R0, SP, 300H
0014i(A0E00018): STR R0, SP, 18H
0015j(80E00018): LDR R0, SP, 18H
0016j(81E00018): LDR R1, SP, 18H
0017j(000A0001): MUL R0, R0, R1
0018j(A0E00014): STR R0, SP, 14H
0019k(40000000): MOV R0, R0, 0H
001Ak(A0E0000C): STR R0, SP, CH
i := n DIV 2;l j := n-1;m
001Bl(80E00018): LDR R0, SP, 18H
001Cl(40020001): ASR R0, R0, 1H
001Dl(A0E00004): STR R0, SP, 4H
001Em(80E00018): LDR R0, SP, 18H
001Fm(40090001): SUB R0, R0, 1H
0020m(A0E00008): STR R0, SP, 8H
WHILE x < nsq DOn
0021n(80E0000C): LDR R0, SP, CH
0022n(81E00014): LDR R1, SP, 14H
0023n(00090001): SUB R0, R0, R1
0024n(ED00003D): BGE 61 [0062H]
nx := n + x;o j := (j-1)p MOD n;q INC(x);r M[i,s j]t := x;u
0025o(80E00018): LDR R0, SP, 18H
0026o(81E0000C): LDR R1, SP, CH
0027o(00080001): ADD R0, R0, R1
0028o(A0E00010): STR R0, SP, 10H
0029p(80E00008): LDR R0, SP, 8H
002Ap(40090001): SUB R0, R0, 1H
002Bq(81E00018): LDR R1, SP, 18H
002Cq(D601E46C): BLLE MT [trap=6, pos=484]
002Dq(000B0001): DIV R0, R0, R1
002Eq(20000000): MOV' R0, R0, R0
002Fq(A0E00008): STR R0, SP, 8H
0030r(80E0000C): LDR R0, SP, CH
0031r(40080001): ADD R0, R0, 1H
0032r(A0E0000C): STR R0, SP, CH
0033s(80E00004): LDR R0, SP, 4H
0034s(4109000D): SUB R1, R0, DH
0035s(DA01F11C): BLCC MT [trap=1, pos=497]
0036s(400A0034): MUL R0, R0, 34H
0037s(00E80000): ADD R0, SP, R0
0038t(81E00008): LDR R1, SP, 8H
0039t(4219000D): SUB R2, R1, DH
003At(DA01F41C): BLCC MT [trap=1, pos=500]
003Bt(41110002): LSL R1, R1, 2H
003Ct(00080001): ADD R0, R0, R1
003Du(81E0000C): LDR R1, SP, CH
003Eu(A100001C): STR R1, R0, 1CH
WHILE x < nx DOv
003Fv(80E0000C): LDR R0, SP, CH
0040v(81E00010): LDR R1, SP, 10H
0041v(00090001): SUB R0, R0, R1
0042v(ED00001E): BGE 30 [0061H]
i := (i+1)w MOD n;x j := (j+1)y MOD n;z
0043w(80E00004): LDR R0, SP, 4H
0044w(40080001): ADD R0, R0, 1H
0045x(81E00018): LDR R1, SP, 18H
0046x(D6022E6C): BLLE MT [trap=6, pos=558]
0047x(000B0001): DIV R0, R0, R1
0048x(20000000): MOV' R0, R0, R0
0049x(A0E00004): STR R0, SP, 4H
004Ay(80E00008): LDR R0, SP, 8H
004By(40080001): ADD R0, R0, 1H
004Cz(81E00018): LDR R1, SP, 18H
004Dz(D602406C): BLLE MT [trap=6, pos=576]
004Ez(000B0001): DIV R0, R0, R1
004Fz(20000000): MOV' R0, R0, R0
0050z(A0E00008): STR R0, SP, 8H
INC(x);a M[i,b j]c := x
0051a(80E0000C): LDR R0, SP, CH
0052a(40080001): ADD R0, R0, 1H
0053a(A0E0000C): STR R0, SP, CH
0054b(80E00004): LDR R0, SP, 4H
0055b(4109000D): SUB R1, R0, DH
0056b(DA02571C): BLCC MT [trap=1, pos=599]
0057b(400A0034): MUL R0, R0, 34H
0058b(00E80000): ADD R0, SP, R0
0059c(81E00008): LDR R1, SP, 8H
005Ac(4219000D): SUB R2, R1, DH
005Bc(DA025A1C): BLCC MT [trap=1, pos=602]
005Cc(41110002): LSL R1, R1, 2H
005Dc(00080001): ADD R0, R0, R1
ENDd
005Ed(81E0000C): LDR R1, SP, CH
005Fd(A100001C): STR R1, R0, 1CH
0060d(E7FFFFDE): B -34 [003FH]
ENDe ;
0061e(E7FFFFBF): B -65 [0021H]
FOR i := 0 TOf n-1 DOg
0062f(40000000): MOV R0, R0, 0H
0063g(81E00018): LDR R1, SP, 18H
0064g(41190001): SUB R1, R1, 1H
FORh j := 0 TOi n-1 DOj Textsk.WriteInt(W,l M[i,m j]n,o 6)p ENDq ;r
0065h(01090001): SUB R1, R0, R1
0066h(EE000023): BGT 35 [008AH]
0067h(A0E00004): STR R0, SP, 4H
0068i(40000000): MOV R0, R0, 0H
0069j(81E00018): LDR R1, SP, 18H
006Aj(41190001): SUB R1, R1, 1H
006Bk(01090001): SUB R1, R0, R1
006Ck(EE000015): BGT 21 [0082H]
006Dk(A0E00008): STR R0, SP, 8H
006El .FIXUP D
006El(8D000061): LDR SB, MT, MOD0 [MagicSquares]
006Fl(40D80000): ADD R0, SB, 0H [data]
0070l .FIXUP D
0070l(8D100002): LDR SB, MT, MOD1 [Texts]
0071l(41D80005): ADD R1, SB, VAR5
0072m(82E00004): LDR R2, SP, 4H
0073m(4329000D): SUB R3, R2, DH
0074m(DA02C61C): BLCC MT [trap=1, pos=710]
0075m(422A0034): MUL R2, R2, 34H
0076m(02E80002): ADD R2, SP, R2
0077n(83E00008): LDR R3, SP, 8H
0078n(4439000D): SUB R4, R3, DH
0079n(DA02C91C): BLCC MT [trap=1, pos=713]
007An(43310002): LSL R3, R3, 2H
007Bn(02280003): ADD R2, R2, R3
007Co(8220001C): LDR R2, R2, 1CH
007Dp(43000006): MOV R3, R0, 6H
007Eq .FIXUP P
007Eq(F711E06F): BL MOD1 [Texts] PROC30
007Fr(80E00008): LDR R0, SP, 8H
0080r(40080001): ADD R0, R0, 1H
0081r(E7FFFFE7): B -25 [0069H]
Texts.WriteLn(W)s
0082s .FIXUP D
0082s(8D000012): LDR SB, MT, MOD0 [MagicSquares]
0083s(40D80000): ADD R0, SB, 0H [data]
0084s .FIXUP D
0084s(8D100002): LDR SB, MT, MOD1 [Texts]
0085s(41D80005): ADD R1, SB, VAR5
ENDt ;u
0086t .FIXUP P
0086t(F711C008): BL MOD1 [Texts] PROC28
0087u(80E00004): LDR R0, SP, 4H
0088u(40080001): ADD R0, R0, 1H
0089u(E7FFFFD9): B -39 [0063H]
Texts.Append(Oberon.Log,v W.buf)w
008Av .FIXUP D
008Av(8D400006): LDR SB, MT, MOD4 [Oberon]
008Bv(80D0000D): LDR R0, SB, VAR13
008Cw .FIXUP D
008Cw(8D000002): LDR SB, MT, MOD0 [MagicSquares]
008Dw(81D00000): LDR R1, SB, 0H [data]
ENDx
008Ex .FIXUP P
008Ex(F710E008): BL MOD1 [Texts] PROC14
ENDy Generate;
008Fy(8FE00000): LDR LNK, SP, 0H
0090y(4EE80334): ADD SP, SP, 334H
0091y(C700000F): B LNK
BEGINz Texts.OpenWriter(W)a
0092z .PROC 0
0092z .ENTRYPOINT
0092z(4EE90004): SUB SP, SP, 4H
0093z(AFE00000): STR LNK, SP, 0H
0094a .FIXUP D
0094a(8D000008): LDR SB, MT, MOD0 [MagicSquares]
0095a(40D80000): ADD R0, SB, 0H [data]
0096a .FIXUP D
0096a(8D100002): LDR SB, MT, MOD1 [Texts]
0097a(41D80005): ADD R1, SB, VAR5
ENDb MagicSquares.c
0098b .FIXUP P
0098b(F711700A): BL MOD1 [Texts] PROC23
0099c(8FE00000): LDR LNK, SP, 0H
009Ac(4EE80004): ADD SP, SP, 4H
009Bc(C700000F): B LNK