Listing 1:
A relocation program for use an 8080a systems.
The program takes any existing program and transfers it to any other location desired in memory with a minimum of fuss.
Throughout this program, endless loops are used to signal the end of major operations.
These loops will cause the data LEDs to output a constant light pattern on the front panel (line 0D37 for example).
If desired, the program can be modified so that it jumps to any other desired routine at these points, or returns to your monitor.
All numbers followed by an H are considered to he hexadecimal in this program (eg: 02H in line 0D35).
Interestingly enough, while the program resides at starting location 0D00, it is perfectly capable of relocating itself!
[8080 Listing
und
Z80 Listing]
Hexadecimal
Address Code Label Op Operand Commentary
0D00 31 FF 0D LXI SP,STACK
03 2A DF 0D LHLD SBOT get b;
06 54 MOV D,H move b to DE;
07 5D MOV E,L
08 2A E1 0D LHLD DTOP get c;
0B 44 MOV B,H move c to BC;
0C 4D MOV C,L
0D 2A DD 0D LHLD SSTRT get a;
10 C5 PUSH B save c;
11 CD A9 0D CALL COMPH complement HL;
14 19 DAD D HL := b-a;
15 44 MOV B,H move to BC;
16 4D MOV C,L
17 E1 POP H get c;
18 09 DAD B set HL equal to bottom of
destination area;
19 3A E7 0D LDA FUNK get f;
1C B7 ORA A if f=0, then slip phase 1;
1D CA 3A 0D JZ STEP3
20 1A X LDAX D get byte from source;
21 77 MOV M,A store byte at destination;
22 78 MOV A,B
23 B7 ORA A
24 C2 2C 0D JNZ Y
27 79 MOV A,C
28 B7 ORA A
29 CA 32 0D JZ TEST if move is over, then go to
TEST;
2C 2B Y DCX H else keep a goin';
2D 1B DCX D
0D2E 0B DCX B
2F C3 20 0D JMP X
32 3A E7 0D TEST LDA FUNK move is now over;
35 FE 02 CPI 02H
37 CA 37 0D DONE JZ DONE if move only, then go to
DONE, (this is endless loop);
3A E5 STEP3 PUSH H save c;
3B 62 MOV H,D get a;
3C 6B MOV L,E place a in HL;
3D CD A9 0D CALL COMPH
40 D1 POP D
41 19 DAD D DE := c-a;
42 22 E8 0D SHLD DISP this is the displacement;
45 2A E3 0D LHLD START get d;
48 2B DCX H
49 23 LOOP INX H
4A EB XCHG
4B 2A E5 0D LHLD STOP
4E EB XCHG
4F 7B MOV A,E
50 95 SUB L
51 7A MOV A,D
52 9C SBB H
53 DA 53 0D DONE2 JC DONE2 if reference fixing is com-
pleted, then go to DONE2.
(this is endless loop);
56 06 1A MVI B,1AH get 3 byte op code count;
58 11 B1 0D LXI D,TABLE3 address of 3 byte op table;
0D5B 1A CHEK3 LDAX D
5C BE CMP M
5D CA 7B 0D JZ ACT if next byte in memory is
start of a 3 byte
go to ACT;
60 05 DCR B else try next op;
61 13 INX D
62 C2 5B 0D JNZ CHEK3 if ther are more 3 byte
ops left to check, go
back to CHEK3;
65 06 12 MVI B,12H else perform same comparision
with table of 2 byte ops;
67 11 CB 0D LXI D,TABLE2
6A 1A CHEK2 LDAX D
6B BE CMP M
6C CA 77 0D JZ SKIP
6F 05 DCR B
70 13 INX D
71 C2 6A 0D JNZ CHEK2 if there are more 2 byte
ops left to try, go back
74 C3 49 0D JMP LOOP to CHEK2;
77 23 SKIP INX H else must be 1 byte,
78 C3 49 0D JMP LOOP ignore it, skip the
operand of a 2 byte
instruction;
7B E5 ACT PUSH H a 3 byte operation;
7C 2A DF 0D LHLD SBOT get b;
7F 54 MOV D,H move b to DE;
80 5D MOV E,L
81 2A DD 0D LHLD SSTRT get a;
84 44 MOV B,H move a to BC;
85 4D MOV C,L
86 E1 POP H
87 23 INX H HL points to B2-B3;
88 7B MOV A,E
89 96 SUB M
0D8A 23 INX H
8B 7A MOV A,D
8C 9E SBB M
8D DA 49 0D JC LOOP if operand is > b, ignore it
90 2B DCX H
91 7E MOV A,M
92 91 SUB C
93 23 INX H
94 7E MOV A,M
95 98 SBB B
96 DA 49 0D JC LOOP if operand is < a, ignore it
99 2B DCX H
9A EB XCHG
9B 2A E8 0D LHLD DISP get displacement value;
9E EB XCHG
9F 7E MOV A,M add to B2-B3;
A0 83 ADD E
A1 77 MOV M,A
A2 23 INX H
A3 7E MOV A,M
A4 8A ADC D
A5 77 MOV M,A
A6 C3 49 0D JMP LOOP go look for more 3 byte
operations
A9 7C COMPH MOV A,H complement HL;
AA 2F CMA
AB 67 MOV H,A
0DAC 7D MOV A,L
AD 2F CMA
AE 6F MOV L,A
AF 23 INX H
B0 C9 RET
Hexadecimal
Address Code Label Commentary
0DB1 01 11 21 TABLE3 table of 3 byte op codes;
B4 22 2A 31
B7 32 3A C2
BA C3 C4 CA
BD CC CD D2
C0 D4 DA DC
C3 E2 E4 EA
C6 EC F2 F4
C9 FA FC
CB 06 0E 16 TABLE2 table of 2 byte op codes;
CE 1E 26 2E
D1 36 3E C6
D4 CE D3 D6
D7 DB DE E6
DA EE F6 FE
DD SSTRT source start a;
DF SBOT source bottom b;
E1 DTOP destination c;
E3 START start phase 2 d;
E5 STOP end phase 2 e;
E7 FUNK function select f;
E8 DISP displacement (program defined);
|