Now the locations of each instruction can be filled in, using the
length to adjust each location. The location always specifies the first
byte of the instruction.
Location Length Instruction
0100H 1 XOR A
0101H 2 LD B,10
0103H 1 LOOP ADD A,B
0104H 1 DEC B
0105H 3 JP NZ,LOOP
0108H I HALT
0109H
As a double check on the accuracy of this step, the total length of
the program from the location column (0109H-0100H = 9 bytes)
can be compared with the total number of bytes from the length
column, nine. Now the instruction formats can be filled in, as shown
in Fig. 9-2. The only difficult instruction is the JP NZ,LOOP. This
is a three-byte instruction with the last two bytes specifying the con-
ditional jump address. Since the jump is to LOOP, which is at loca-
tion 0103H, this address must go into bytes two and three in reverse
order 03H, 01H, as is the format from time immemorial (or at least
since the 8008).
LOCATION
LENGTH
MACHINE CODE INSTRUCTION FORM AT
INSTRUCTION
0100H
1
AF
10101
111
XOR A
0101H
2
060A
OD 000 110 00001010
LD B, 10
0103H
1
80
10000 000
LOOP
ADD A,B
010414
1
05
00 000 101
DEC B
0105H
3
C20301
11 000
010,
00000011 00000001
JP NZ, LOOP
0108H
1
76
0111 0110
HALT
0109H
Fig. 9-2 . Manual assembly process program 2.
Although it is feasible to assemble long programs by manual
methods., it is extremely uneconomical. There is too much of a
chance for error in calculating locations, filling in instruction fields,
and formatting addresses. In addition to the certainty of rote errors,
there are several other factors that make machine-language opera-
tions unworkable . The most important of these is relocatability.
Program two could execute only at location 0100H. To execute at
another location, the address in the JP instruction would have to be
changed. In larger programs, many addresses would have to be re-
figured and manually assembled. A second factor is ease of editing.
Few programs run the first time and most require several iterations
before the program performs the way that was expected. Each itera-
tion involves adding, deleting, or modifying instructions of the pro-
136
Need help?
Do you have a question about the Z80 and is the answer not in the manual?