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