Z80 Microprocessor Kit Programming Lab Book
Z80 Microprocessor Kit Programming Lab Book
Z80 Microprocessor Kit Programming Lab Book
Student:_________________________ID:____________________
Study program:_________________________________________
PREFACE
This lab book is designed for self-learning how to program the Z80 microprocessor in
machine language with the Z80 Microprocessor Kit. The demonstration programs were
written in assembly program using Z80 instructions. The program listings are provided with
instruction hex code. Students can enter the program by using hex code to the memory and
test it directly. Illustrations of program flow were also provided for easy understanding.
After program testing the exercise will ask questions and program modification only at the
hex code, no need the assembler program.
LAB1 to LAB 6 are focusing on software programming. LAB7 to LAB12 are for hardware
interfacing using the on-board I/O devices.
Z80 MICROPROCESSOR KIT
PROGRAMMING LAB BOOK
CONTENTS
LAB 5 COMPARISON...................................................................................14
LAB 6 STOP-WATCH....................................................................................17
LAB 7 INTERRUPT........................................................................................21
LAB 9 KEYBOARD.......................................................................................30
APPENDIX A
MONITOR SUBROUTINES..........................................................................50
APPENDIX B
Your first program will get you familiar with how to enter the hex code and test run quickly.
The main code is repeat writing accumulator register to GPIO1 with delay.
GPIO1
Delay
0 0 0 0 0 0 1 0 Rotate left A
Procedure
1. Suppose we want new initial value to be loaded into register A, where is the byte to be
modified? Try change it and run the program again.
__________________________________________________________________________
2. Let us make running speed slower. Where is the byte to be modified? Test it.
__________________________________________________________________________
__________________________________________________________________________
The new subroutine called TONE2K is built-in code that produces 2kHz tone with period
set by HL. The delay subroutine is the same as LED running. Students may try enter the hex
code and test run again. You may learn how the code running and modify it.
Summary
The delay subroutine is a useful code for demonstration computer program running and
even for complicated applications as well. Since the microprocessor cycle time is quite short
compare to our response. If students change the load value of HL register to a small number,
and try the LED running. We will see all LED will be lit, why? 5
LAB 2 FILL MEMORY WITH CONSTANT
This lab demonstrates how to fill block of memory using indirect addressing mode.
Before After
B not eq. 0
200FH 9FH 200FH 00H
RST 38H
Procedure
2. Write down the content of memory locations 2000 to 200F before press key GO.
3. Press key PC to set address to 1800 then key GO to run the program.
4. Write down the content of memory locations 2000 to 200F after press key GO. 6
Results
Exercise
1. Now we want to clear 256 bytes from 2000 to 20FF. How to do that? Try and show the
result to TA.
_______________________________________________________________________
2. Instead of clearing the memory, let us fill the block of data with FF, 256 bytes, from 2000
to 20FF. How to do that? Try and show the result to TA.
_______________________________________________________________________________
Summary
We can use register B together with DJNZ instruction to make loop running. The load value
to register B will be loop counter. The body of loop can be any code or subroutine to be
repeated. HL register pair forms a 16-bit pointer. We use it to point the memory address with
indirect addressing mode.
7
LAB 3 ADDING 16-BIT BINARY NUMBER
We will learn how to add two 16-bit binary numbers using indirect addressing mode.
Number1 and number2 are memory address that stores two 16-bit data. The program uses
HL and DE registers as a pointer. Register B is loop counter. The result will be saved to
number1 location. Before After
AE 89+
CY 9A 57
YY XX 8
Procedure
2. Edit the data to be added for number1 and number2 as shown above.
5. Write the result that saved in number1 location and carry flag after adding. Compare the
result with hand calculation. Carry flag can be viewed with key REG, D. The display will
show the low nibble of flag register. Carry flag is the right most bit.
Results
Exercise
1. Let us try with new value of number1 and number2 by editing them in location 2000H to
2003H. Then ask your friend add it by hand calculation. Check the your friend result with
Z80 running, correct or not?
__________________________________________________________________________
__________________________________________________________________________
9
Summary
Adding binary number can be done with 8-bit addition instruction. For multi-byte adding,
we can use ADC instruction with loop running. The number of loop will be the number of
byte to be added. If there is a carry bit from lower significant byte adding, the carry bit will
be added to the next higher significant byte automatically.
Important note: adding instruction is for binary number. The hexadecimal representation are
for shorter written and code entering.
10
LAB 4 ADDING BCD NUMBER
For some applications that use BCD number, Z80 also has instruction DAA used to adjust or
correct the result of addition in accumulator.
Before After
19 89+
CY 90 88
YY XX
11
We see that above program is the same as LAB 3. Only, DAA instruction is followed with
ADC instruction. For now number1 and number2 must be BCD, all digits must be 0-9 only.
As we know that BCD is a decimal representation by 4-bit binary number.
Procedure
2. Edit the data to be added for number1 and number2 as shown above.
5. Write the result that saved in number1 location and carry flag after adding. Compare the
result with hand calculation. Carry flag can be viewed with key REG, D. The display will
show the low nibble of flag register. Carry flag is the right most bit.
Results
Exercise
1. Let us try with new value of number1 and number2 by editing them in location 2000H to
2003H. Then ask your friend add it by hand calculation. Check the your friend result with
Z80 running, correct or not?
Find the unknown values, xx, yy, jj, kk and nn in the program below.
Summary
Z80 provides DAA instruction for correcting the result after using ADD or ADC
instructions. DAA must be placed after ADD or ADC instruction. The values to be added
also must be BCD number, 0-9. DAA is not the instruction that converts binary to decimal
number. It is designed for correcting the result of BCD number adding.
13
LAB 5 COMPARISON
Number comparison can be used to control flow or decision of program running. Z80
provides 8-bit compare instruction. The carry flag and zero flag will be affected according
to the result of comparison.
Suppose we have two 8-bit number to be compared, A and B. The result would be,
Memory
Procedure
2. Edit the data to be compared for number1 and number2 at location 2000 and 2001.
4. Run the program, press key PC and key GO. Write down the result of carry and zero flags
with key REG, C, or REG D.
14
Results table
We may combine the result for A<=B, Zero and carry flags will be set.
For A > = B, Zero flag will be set and carry will be cleared.
We can use instructions conditional jump after carry or zero flags are affected. So the
decision can be made. The example below shows how to use the conditional jump.
Procedure
2. Edit the data to be compared for number1 and number2 at location 2000 and 2001.
4. Run the program, press key PC and key GO. Write down the result of GPIO1 LED for
three cases (1 for LED lit, 0 for LED off)
Summary
Comparison instruction can be used to make decision of program flow. After two numbers
are compared, the zero and carry flags will be affected. Program flow can be controlled with
conditional jump instructions.
16
LAB 6 STOP-WATCH
This lab demonstrates using monitor subroutines to make a simple stop-watch. The timebase
1/100 second is done by display scanning loop period. For more accurate, we will use timer
interrupt for the next lab.
Register pair DE holds SEC and SEC/100. We see that incrementing was done by two bytes
adding with DAA for BCD adjustment. Result of BCD addition will be 00 to 99 for both
register D and E. When user press any key, the carry flag will be cleared, so jump
instruction at line 11 will repeat scanning without incrementing DE. This makes as a STOP
key. When key was released, carry flag will be set, the incrementing will be continued.
17
SCAN DISPLAY
key pressed
No key
pressed
DE=DE+1
Convert DE to
7-segment pattern
Procedure
Suppose we want to clear the count to zero with a given key. How to do that?
Convert DE to
7-segment pattern
Since SCAN1 subroutine also scans the keyboard. It returns hardware wiring position of the
key being pressed. We will learn how to use SCAN1 more in later LAB. Let us try detecting
key CBR having position key of 18H to be a reset counter key. We use compare instruction
to check if key CBR has been pressed or not. It is was pressed, register DE and A are cleared
to zero.
Procedure
4. Try press key CBR, did you see the counter is zero?
Exercise
1. We can try change the control key to a given key. The example uses CBR for resetting the
counter to zero. Try to change another key for stop function.
2. Have the real stop watch for checking time error, with the accumulating time for one
minute, our program is run faster or slower in seconds unit? Why?
3. Can you change the counting from incrementing to decrementing using SUB and SBC
instructions.
Summary
We can use monitor subroutine scan display for displaying counter running. The count is
updated every approx. 1/100 sec. Registers DE was used for four digits BCD counting.
SCAN1 subroutine also returns hardware wiring position of the key. We can have a given
key by detecting its position for the STOP function.
20
LAB 7 INTERRUPT
Hardware interrupt
We will learn a maskable interrupt process and write the code for testing interrupt. The Z80
Kit has two sources of hardware interrupt. One for INTR key and a 10ms tick signal
produced by timer chip, AT89C2051 microcontroller. SW4 is a slide switch. We can select
which one will be the interrupt source.
Z80 CPU
INTR
INT
SW4
Above program demonstrates how the maskable interrupt mode 2 is responding to the
trigger signal by key INTR.
When Z80 was triggered by low level logic at INT pin, it will acknowledge by requesting
the low order byte from device. The memory address that stores service vector is formed by
register I for high byte and low order byte from the device. Z80 will save current program
counter to stack memory, get the vector address then jump to interrupt service routine. When
interrupt process was finished, the program counter that saved in stack memory will be
retrieved and then return to the main program.
Device
INTR (1) Interrupt MODE 2
INT
(4) PC STACK
18FFH 0E
(5) get vector 180E 1900H 18
1901H XX
1902H YY
22
Our Kit has no circuit that supplies the low order byte, however with the pull-up resistor at
the data bus, the CPU will read byte as FF. We then load the register I with 18H, thus the
location that stores interrupt vector will be 18FFH.
Procedure
1. Slide SW4 to select INTR key. The INTR key will be used as the interrupt source.
3. Press RESET key, PC key. Try press INTR key. Did you see any change at GPIO1?
_____________________________________________________________________
4. Now press key RESET, PC then GO. Did you see any change?
_____________________________________________________________________
5. Press key INTR again, what value will be displayed on GPIO1?
6. Change address to 0000, press key INTR again, write down the hex content and draw
GPIO1 LED. Press key + for next address and key INTR to make interrupt..
23
10ms Tick Timer interrupt
Let us do experiment with 10ms tick using timer chip. The 89C2051 microcontroller is used
to produce 10ms tick signal. Slide SW4 to 10ms tick position, we can trigger the Z80 CPU
to jump to interrupt service routine every 10ms. The demonstration program will display
BCD counting at GPIO1 every one second while the monitor program is functioning.
Z80 CPU
INTR
INT
SW4
Main code is the same as hardware interrupt. When Z80 is triggered by logic low signal at
pin INT, it will get the vector at location 18FFH, where we insert the interrupt service
address 180EH. The same as hardware interrupt, but now we use 10ms tick as the interrupt
source.
The code for interrupt service may called timer interrupt, will increment the tick variable, if
it is equal or greater than 100, then increment the counter variable.
Procedure
1. Slide SW4 to select TICK. 10ms Tick will be used as the interrupt source.
3. Press RESET key, PC key. Then key GO. Did you see any change at GPIO1? Explain.
4. Try press key ADDR, + or – to change the address. Can you hear the beep sound that
slightly change in frequency? Explain why?
__________________________________________________________________________
25
LAB 8 7-SEGMENT DISPLAY
The kit has 6-digit 7-segment LED display. We will learn how to use it for displaying hex or
BCD data.
Display buffer
IX+0 BDH
IX+1 30H
IX+2 9BH
IX+3 BAH
IX+4 36H
IX+5 AEH
Display buffer uses 6 bytes of RAM for storing the data to be scanned. We can use IX
register to point to buffer memory. Example above shows the rightmost digit pattern, BDH
for number 0, and the left most digit pattern, AEH for number 5.
Bit pattern for LED display and bit position for each segment is shown below. For example
number 1, segment b and c are logic one , the data will be 30H.
a
f g b dpcb afge
e c 8-bit segment designation, e.g. 30H for '1'
d p
26
Let us try this program for testing the display.
We use IX register for pointing the display buffer memory begin at 2000H. And then call
the subroutine that scans display.
Procedure
2. Press PC and GO, Did you see any display on the 7-segment LED? How it looks like?
3. Edit the memory address 2000 to 2005 with these value, 30, 02, 02, 0F, 1F, A1. Press PC
and GO. Draw the pattern on the segment below. Try also your pattern.
27
Exercise
1. Edit the bit pattern in display buffer, then show TA with the your name on the LED
display.
Now let us try display the 16-bit data and 8-bit data using monitor subroutines.
Subroutine DATADISP will convert the 8-bit data in register A to two digits 7-segment
pattern and save to display buffer memory at DATA field.
Subroutine ADDRDISP will convert the 16-bit data in register DE to four digits 7-segment
pattern and save to display buffer memory at ADDRESS field.
We use memory address 2000H for storing 8-bit data and 2001H-2002H for 16-bit data.
Procedure
2. Edit memory contents at location 2000H to 2002H with 12H, 34H and 56H.
3. Press PC and GO. Did you see the number on the display?
28
Summary
The onboard 6-digit LED can be used to display 8-bit or 16-bit data. Each digit uses one
byte memory which contains the pattern for a given number to be displayed. Z80 kit
provides monitor subroutines for use with applications program by calling them with proper
preset registers.
The example of code for displaying number and A to Z letters. The code is hex number.
29
LAB 9 KEYBOARD
The Z80 kit has 36 keys for hex numbers, function keys and CPU control keys. We can do
experiments that demonstrates the use of keyboard. The monitor subroutine for keyboard
scanning is also provided for program testing.
Each key has its position by hardware wiring. But to use it with applications program, we
may arrange it to provide proper code that suitable for logical programming. For example
after key scanning, we will get key position code 12H for hex key '0'. We then can change it
to binary data 0 for key '0' by table indexing.
Let us do the first experiment to find the position code for each key.
Procedure
2. Press PC and GO, write down the position key in the box or close to the key when the key
was pressed (except CPU control and user keys).
To make the key position useful and proper functioning, we change it to internal code then.
The monitor subroutine SCAN, the upper level subroutine uses KEYTABLE with offset
byte (key position) for pointing to the internal code. The IX register will load start address
of the table.
For example position code is 0. It will be used as the offset byte. The instruction LD A,
(IX+0) will get value of 03 for hex key 3.
KEYTABLE:
2519 077B 03 K0 .BYTE 03H ;HEX_3
2520 077C 07 K1 .BYTE 07H ;HEX_7
2521 077D 0B K2 .BYTE 0BH ;HEX_B
2522 077E 0F K3 .BYTE 0FH ;HEX_F
2523 077F 20 K4 .BYTE 20H ;N/A
2524 0780 21 K5 .BYTE 21H ;N/A
2525 0781 02 K6 .BYTE 02H ;HEX_2
2526 0782 06 K7 .BYTE 06H ;HEX_6
2527 0783 0A K8 .BYTE 0AH ;HEX_A
2528 0784 0E K9 .BYTE 0EH ;HEX_E
2529 0785 22 K0A .BYTE 22H ;N/A
2530 0786 23 K0B .BYTE 23H ;N/A
2531 0787 01 K0C .BYTE 01H ;HEX_1
2532 0788 05 K0D .BYTE 05H ;HEX_5
2533 0789 09 K0E .BYTE 09H ;HEX_9
2534 078A 0D K0F .BYTE 0DH ;HEX_D
2535 078B 13 K10 .BYTE 13H ;STEP
2536 078C 1F K11 .BYTE 1FH ;DOWNLOAD
2537 078D 00 K12 .BYTE 00H ;HEX_0
2538 078E 04 K13 .BYTE 04H ;HEX_4
2539 078F 08 K14 .BYTE 08H ;HEX_8
2540 0790 0C K15 .BYTE 0CH ;HEX_C
2541 0791 12 K16 .BYTE 12H ;GO
2542 0792 1E K17 .BYTE 1EH ;UPLOAD
2543 0793 1A K18 .BYTE 1AH ;CBR
2544 0794 18 K19 .BYTE 18H ;PC
2545 0795 1B K1A .BYTE 1BH ;REG
2546 0796 19 K1B .BYTE 19H ;ADDR
2547 0797 17 K1C .BYTE 17H ;DEL
2548 0798 1D K1D .BYTE 1DH ;RELA
2549 0799 15 K1E .BYTE 15H ;SBR
2550 079A 11 K1F .BYTE 11H ;-
2551 079B 14 K20 .BYTE 14H ;DATA
2552 079C 10 K21 .BYTE 10H ;+
2553 079D 16 K22 .BYTE 16H ;INS
2554 079E 1C K23 .BYTE 1CH ;COPY
Let us try the second experiment to find the internal code for each key.
Procedure
2. Press PC and GO, write down the internal key in the box or close to the key when the key
was pressed (except CPU control and user keys).
Summary
The Z80 kit has keyboard for inputting hex number or set the functions. The monitor
subroutine scans the key switch in sequential manner. When it was pressed, the low level
subroutine, SCAN1 will return hardware wiring position code. The upper level SCAN
subroutine returns the internal code that suitable for logical programming. Students may try
using the keyboard for many applications.
33
LAB 10 DIGITAL TIMER
This lab will use timer interrupt to be timebase for making a digital timer.
Repeat scan
display
SCAN buffer
memory 10ms Interrupt
Convert sec to
7-segment pattern
We use interrupt mode 2 and have the interrupt service routine now with timer function.
Every 10ms, the CPU will jump to interrupt service routine at location 1820H. The tick
variable will be incremented by one and checked if it was equal or larger than 100, i.e.
100x10ms = 1 second, the variable sec will be decremented by one. Again we use DAA to
adjust the result from subtraction to be BCD number. The subroutine DATADISP will
convert the accumulator A and save the LED pattern to the display buffer in data field. Main
code is repeat scan the display. So we will see the counting down every one second. 35
Procedure
4. Press PC and GO, Did you see any display on the 7-segment LED?
_______________________________________________________________________
Exercise
1. The counting is decremented every one second. Can you modify the program to make
counting up every one second.
3. If we want to stop count when time is zero, give the idea how to do that?
________________________________________________________________________
Summary
We see that the main code is only scan the display. It reads the display buffer memory and
writes to the LED. But when the CPU was interrupted by 10ms tick, Z80 stop running the
main code and jump to interrupt service routine. We use variable to count the number of
interrupt, if it is equal to 100 ticks, time has passed for one second. We can use another
variable for counting 60 seconds for one minute as well.
36
LAB 11 LCD MODULE INTERFACE
In the applications that need more details readout, the LCD module is more suitable. One of
the example is LCD text module having HD44780 controller chip. Our kit prepares the 16-
pin header for easy interface. We can learn how to use it without the need of extra
interfacing circuit. The LCD module will need only female 16-pin header for direct
plugging into the on-board 16-pin header. Left hand is pin 1, and right hand is pin 16.
Steps to enable the LCD module and print a letter or text are as follows.
37
Character code for LCD module is the same as ASCII code. For example letter 'A', the code
is 41H, 'B' is 42H. For numeric, letter '1', code is 31H.
For scientific or mathematics symbols, different manufacturers may provide different code.
We may test it by writing the code to the LCD and check it then.
38
Let us try print text “Hello worlds” on the first line and letter 'A' on the second line.
Main code begins with initialize the LCD module, then print text “hello worlds” and print
letter 'A' on LCD screen.
Procedure
1. Turn the kit's power off, then plug the LCD module to the 16-pin header.
2. Turn power on, adjust R18 until the first line becomes black.
39
3. Enter the hex code from 1800 to 1822.
4. Press PC and GO, Did you see any text on LCD screen?
Exercise
1. The message “hello worlds” is called ASCII string. At the end, it has terminator, 0. If you
want to show your name, how to do that?
__________________________________________________________________________
We see that the LCD module has more space for displaying many meaningful values.
Suppose we want to display the memory content 4-byte on the LCD. How to do that?
We use PRINTHEX subroutine for printing one byte in HEX number. The value to be
printed is loaded into register A. For symbol, we use PRINTCHAR subroutine that prints
the symbol from ASCII code directly.
Procedure
2. Press PC and GO, did you see the printout as described above?
Exercise
1. Modify the program to display the 2nd line for the next four bytes. Show the printout
result. Compare the printout with the memory contents by monitor key ADDR and key +.
The LCD driver also provides subroutine that prints unsigned 16-bit integer in decimal
number, PRINTINT. Let us test it.
The HL register is loaded with initial value of 0000 and printed it to LCD in decimal
representation. The actual incrementing by INC HL is binary counting up. Delay provides
approx. 0.5s delay, so we can see the incrementing clearly. To preserve the HL contents,
instruction PUSH HL and POP HL are used to save HL contents to stack memory.
Procedure
2. Press PC and GO, did you see the printout of number counting?
Summary
The LCD module is suitable for applications that need more details readout. The Z80 kit
provides both hardware interface and drivers subroutine for experimenting. The drivers is
composed of hardware level subroutine. To use the LCD we must first initialize it then we
can write the ASCII letter or string to the LCD.
42
LAB 12 SERIAL COMMUNICATION
The Z80 kit has RS232C communication port. We can test sending/receiving data between
two computers using the RS232C. The serial data is asynchronous format. The speed is
2400 bit/s, 8-data bit, no parity and one stop bit. The RS232C is designed for connecting
between two computers or between computer and data communication equipment (DCE)
such as MODEM.
The kit has two keys for upload and download Intel hex file. The Intel hex file is generated
from assembler or compiler program. We will learn how serial data is sent over the serial
port. Since the kit has no UART chip, serial data streams are generated by software control.
The monitor subroutines provide two basic functions, i.e. 1) COUT for sending a byte and
2) CIN for receiving a byte.
VT100 terminal can be built using PC running communication program, like teraterm. The
RS232C cable is cross cable.
Z80 Kit
VT100 Terminal
The kit shares TXD pin with on-board speaker, thus to send data correctly, we must set mark
level before sending the serial data. This can be done with subroutine INIT. Main code
sends NEWLINE and print text using PSTRING.
Procedure
2. Connect the kit to terminal COM port using RS232C cross cable.
3. Run teraterm with 2400 bit/s, 8-data bit, no parity and one stop bit.
4. Run the program with key RESET, PC and GO. We will get the message on terminal
screen.
44
Exercise
Now we will try print the memory contents with OUT2X subroutine.
The program begins with writing ADDRESS, 1800 then prints one space, followed with 16
bytes memory contents in hex number using OUT2X. Register C is inner loop counter for
16 bytes. The outer loop counter is register B at line 0015. The printout on terminal screen
would look like this.
Procedure
2. Run the program with key RESET, PC and GO. Did you get similar screen like above?46
Exercise
The kit can receive serial data as well. We will see how to type message on VT10 terminal
and display it on Z80 Kit's LCD.
RS232C
Main code reads a character received from terminal and check if it is CR or ESC. For CR it
will set the new line, for ESC, it will clear the LCD display. The message that typed on the
terminal will be displayed on LCD concurrently.
Procedure
1. We will need 16x2 LCD, 2400 bit/s VT100 terminal and RS232C cable for this
experiment.
3. Press PC and GO, then type a message on VT100 terminal. The message will show on the
Kit's LCD.
4. To enter newline, press key Enter or clear LCD screen with key ESC.
Summary
Sending or receiving digital data between computers mostly uses serial communication. The
Z80 kit has software control UART for asynchronous communication. Signal level of the
serial port is RS232C. The low level driver subroutines for serial port are COUT and CIN.
COUT is for sending 8-bit data in register A and CIN for receiving data to register A. Upper
level subroutines e.g., PSTRING will print ASCII string, OUT2X will print register in HEX
number.
We can use PC running terminal program to emulate VT100 terminal. The terminal uses
ASCII code for data exchange. Printable ASCII letters are from 20H to 7FH. Control codes
are from 00 to 1FH. The example of control codes are CR and LF for entering the new line.
The kit also has text file downloading key. The Intel hex file generated from assembler or c
compile programs is ASCII text file. For binary file transaction, the upper level software
will provide the protocol for byte sequence, acknowledgment, and error checking. The
popular are XMODEM, YMODEM.
48
49
APPENDIX A
MONITOR SUBROUTINES
50
APPENDIX B
Examples:
51
REDUCED Z80 INSTRUCTION SET REDUCED Z80 INSTRUCTION SET
Edited by Phil Townshend 2003 FLAG * = affected Edited by Phil Townshend 2003 FLAG * = affected
DEF's ? = unknown DEF's ? = unknown
Conditional jumps show 2 values: e.g. "RET Z = 1/3" (cycles if condition not met)/(cycles if condition met) x = no change Conditional jumps show 2 values: e.g. "RET Z = 1/3" (cycles if condition not met)/(cycles if condition met) x = no change
INSTR. HEX CODE CYC FREG - Flags register INSTR. HEX CODE CYC FREG - Flags register INSTR. HEX CODE CYC FREG - Flags register INSTR. HEX CODE CYC FREG - Flags register
b7 b6 b5 b4 b3 b2 b1 b0 b7 b6 b5 b4 b3 b2 b1 b0 b7 b6 b5 b4 b3 b2 b1 b0 b7 b6 b5 b4 b3 b2 b1 b0
S Z - H - - N C S Z - H - - N C S Z - H - - N C S Z - H - - N C
ADC A,C 89 1 * * * 0 * HALT 76 1 x x x x x ADC A,C 89 1 * * * 0 * HALT 76 1 x x x x x
ADC A,n CE nn 2 * * * 0 * IN A,(nn) DB nn 3 x x x x x ADC A,n CE nn 2 * * * 0 * IN A,(nn) DB nn 3 x x x x x
ADD A,(HL) 86 2 * * * 0 * INC (HL) 34 3 * * * 0 x ADD A,(HL) 86 2 * * * 0 * INC (HL) 34 3 * * * 0 x
ADD A,A 87 1 * * * 0 * INC A 3C 1 * * * 0 x ADD A,A 87 1 * * * 0 * INC A 3C 1 * * * 0 x
ADD A,B 80 1 * * * 0 * INC B 04 1 * * * 0 x ADD A,B 80 1 * * * 0 * INC B 04 1 * * * 0 x
ADD A,C 81 1 * * * 0 * INC BC 03 1 x x x x x ADD A,C 81 1 * * * 0 * INC BC 03 1 x x x x x
ADD A,D 82 1 * * * 0 * INC C 0C 1 * * * 0 x ADD A,D 82 1 * * * 0 * INC C 0C 1 * * * 0 x
ADD A,E 83 1 * * * 0 * INC D 14 1 * * * 0 x ADD A,E 83 1 * * * 0 * INC D 14 1 * * * 0 x
ADD A,H 84 1 * * * 0 * INC DE 13 1 x x x x x ADD A,H 84 1 * * * 0 * INC DE 13 1 x x x x x
ADD A,L 85 1 * * * 0 * INC E 1C 1 * * * 0 x ADD A,L 85 1 * * * 0 * INC E 1C 1 * * * 0 x
ADD A,n C6 nn 2 * * * 0 * INC H 24 1 * * * 0 x ADD A,n C6 nn 2 * * * 0 * INC H 24 1 * * * 0 x
ADD HL,BC 09 3 x x x 0 * INC HL 23 1 x x x x x ADD HL,BC 09 3 x x x 0 * INC HL 23 1 x x x x x
ADD HL,DE 19 3 x x x 0 * INC L 2C 1 * * * 0 x ADD HL,DE 19 3 x x x 0 * INC L 2C 1 * * * 0 x
ADD HL,HL 29 3 x x x 0 * INC SP 33 1 x x x x x ADD HL,HL 29 3 x x x 0 * INC SP 33 1 x x x x x
AND (HL) A6 2 * * 1 0 0 JP (HL) E9 1 x x x x x AND (HL) A6 2 * * 1 0 0 JP (HL) E9 1 x x x x x
AND A A7 1 * * 1 0 0 JP C,mn DA nn mm 3 x x x x x AND A A7 1 * * 1 0 0 JP C,mn DA nn mm 3 x x x x x
AND B A0 1 * * 1 0 0 JP mn C3 nn mm 3 x x x x x AND B A0 1 * * 1 0 0 JP mn C3 nn mm 3 x x x x x
AND C A1 1 * * 1 0 0 JP N,mn FA nn mm 3 x x x x x AND C A1 1 * * 1 0 0 JP N,mn FA nn mm 3 x x x x x
AND D A2 1 * * 1 0 0 JP NC,mn D2 nn mm 3 x x x x x AND D A2 1 * * 1 0 0 JP NC,mn D2 nn mm 3 x x x x x
AND E A3 1 * * 1 0 0 JP NZ mn C2 nn mm 3 x x x x x AND E A3 1 * * 1 0 0 JP NZ mn C2 nn mm 3 x x x x x
AND H A4 1 * * 1 0 0 JP Z,mn CA nn mm 3 x x x x x AND H A4 1 * * 1 0 0 JP Z,mn CA nn mm 3 x x x x x
AND L A5 1 * * 1 0 0 JR C d 38 dd 2/3 x x x x x AND L A5 1 * * 1 0 0 JR C d 38 dd 2/3 x x x x x
AND n E6 nn 2 * * 1 0 0 JR dd 18 dd 3 x x x x x AND n E6 nn 2 * * 1 0 0 JR dd 18 dd 3 x x x x x
CALL C,mn DC nn mm 3/5 x x x x x JR NC,d 30 dd 2/3 x x x x x CALL C,mn DC nn mm 3/5 x x x x x JR NC,d 30 dd 2/3 x x x x x
CALL mn CD nn mm 5 x x x x x JR NZ,d 20 dd 2/3 x x x x x CALL mn CD nn mm 5 x x x x x JR NZ,d 20 dd 2/3 x x x x x
CALL NC,mn D4 nn mm 3/5 x x x x x JR Z d 28 dd 2/3 x x x x x CALL NC,mn D4 nn mm 3/5 x x x x x JR Z d 28 dd 2/3 x x x x x
CALL NZ,mn C4 nn mm 3/5 x x x x x LD (BC),A 02 2 x x x x x CALL NZ,mn C4 nn mm 3/5 x x x x x LD (BC),A 02 2 x x x x x
CALL Z,nn CC nn mm 3/5 x x x x x LD (DE),A 12 2 x x x x x CALL Z,nn CC nn mm 3/5 x x x x x LD (DE),A 12 2 x x x x x
CCF 3F 1 x x x 0 * LD (HL),A 77 2 x x x x x CCF 3F 1 x x x 0 * LD (HL),A 77 2 x x x x x
CP (HL) BE 2 * * * 1 * LD (HL),B 70 2 x x x x x CP (HL) BE 2 * * * 1 * LD (HL),B 70 2 x x x x x
CP A BF 1 * * * 1 * LD (HL),C 71 2 x x x x x CP A BF 1 * * * 1 * LD (HL),C 71 2 x x x x x
CP B B8 1 * * * 1 * LD (HL),D 72 2 x x x x x CP B B8 1 * * * 1 * LD (HL),D 72 2 x x x x x
CP C B9 1 * * * 1 * LD (HL),E 73 2 x x x x x CP C B9 1 * * * 1 * LD (HL),E 73 2 x x x x x
CP D BA 1 * * * 1 * LD (HL),H 74 2 x x x x x CP D BA 1 * * * 1 * LD (HL),H 74 2 x x x x x
CP E BB 1 * * * 1 * LD (HL),L 75 2 x x x x x CP E BB 1 * * * 1 * LD (HL),L 75 2 x x x x x
CP H BC 1 * * * 1 * LD (HL),n 36 nn 3 x x x x x CP H BC 1 * * * 1 * LD (HL),n 36 nn 3 x x x x x
CP L BD 1 * * * 1 * LD (mn),A 32 nn mm 4 x x x x x CP L BD 1 * * * 1 * LD (mn),A 32 nn mm 4 x x x x x
CP n FE nn 2 * * * 1 * LD (mn),HL 22 nn mm 5 x x x x x CP n FE nn 2 * * * 1 * LD (mn),HL 22 nn mm 5 x x x x x
CPL 2F 1 x x 1 1 x LD A,(BC) 0A 2 x x x x x CPL 2F 1 x x 1 1 x LD A,(BC) 0A 2 x x x x x
DEC (HL) 35 3 * * * 1 x LD A,(DE) 1A 2 x x x x x DEC (HL) 35 3 * * * 1 x LD A,(DE) 1A 2 x x x x x
DEC A 3D 1 * * * 1 x LD A,(HL) 7E 2 x x x x x DEC A 3D 1 * * * 1 x LD A,(HL) 7E 2 x x x x x
DEC B 05 1 * * * 1 x LD A,(mn) 3A nn mm 4 x x x x x DEC B 05 1 * * * 1 x LD A,(mn) 3A nn mm 4 x x x x x
DEC BC 0B 1 x x x x x LD A,A 7F 1 x x x x x DEC BC 0B 1 x x x x x LD A,A 7F 1 x x x x x
DEC C 0D 1 * * * 1 x LD A,B 78 1 x x x x x DEC C 0D 1 * * * 1 x LD A,B 78 1 x x x x x
DEC D 15 1 * * * 1 x LD A,C 79 1 x x x x x DEC D 15 1 * * * 1 x LD A,C 79 1 x x x x x
DEC DE 1B 1 x x x x x LD A,D 7A 1 x x x x x DEC DE 1B 1 x x x x x LD A,D 7A 1 x x x x x
DEC E 1D 1 * * * 1 x LD A,E 7B 1 x x x x x DEC E 1D 1 * * * 1 x LD A,E 7B 1 x x x x x
DEC H 25 1 * * * 1 x LD A,H 7C 1 x x x x x DEC H 25 1 * * * 1 x LD A,H 7C 1 x x x x x
DEC HL 2B 1 x x x x x LD A,L 7D 1 x x x x x DEC HL 2B 1 x x x x x LD A,L 7D 1 x x x x x
DEC L 2D 1 * * * 1 x LD A,n 3E nn 2 x x x x x DEC L 2D 1 * * * 1 x LD A,n 3E nn 2 x x x x x
DEC SP 3B 1 x x x x x LD B,(HL) 46 2 x x x x x DEC SP 3B 1 x x x x x LD B,(HL) 46 2 x x x x x
DJNZ,d 10 dd 2/3 x x x x x LD B,A 47 1 x x x x x DJNZ,d 10 dd 2/3 x x x x x LD B,A 47 1 x x x x x
EX AF,AF' 08 1 x x x x x LD B,B 40 1 x x x x x EX AF,AF' 08 1 x x x x x LD B,B 40 1 x x x x x
EX DE,HL EB 1 x x x x x LD B,C 41 1 x x x x x EX DE,HL EB 1 x x x x x LD B,C 41 1 x x x x x
EXX D9 1 - (2) x x x x x LD B,D 42 1 x x x x x EXX D9 1 - (2) x x x x x LD B,D 42 1 x x x x x
REDUCED Z80 INSTRUCTION SET REDUCED Z80 INSTRUCTION SET
INSTR. HEX CODE CYC FREG - Flags register INSTR. HEX CODE CYC FREG - Flags register INSTR. HEX CODE CYC FREG - Flags register INSTR. HEX CODE CYC FREG - Flags register
b7 b6 b5 b4 b3 b2 b1 b0 b7 b6 b5 b4 b3 b2 b1 b0 b7 b6 b5 b4 b3 b2 b1 b0 b7 b6 b5 b4 b3 b2 b1 b0
S Z - H - - N C S Z - H - - N C S Z - H - - N C S Z - H - - N C
LD B,E 43 1 x x x x x NEG ED 44 2 * * * 1 * LD B,E 43 1 x x x x x NEG ED 44 2 * * * 1 *
LD B,H 44 1 x x x x x OR (HL) B6 2 * * 0 0 0 LD B,H 44 1 x x x x x OR (HL) B6 2 * * 0 0 0
LD B,L 45 1 x x x x x OR A B7 1 * * 0 0 0 LD B,L 45 1 x x x x x OR A B7 1 * * 0 0 0
LD B,n 06 nn 2 x x x x x OR B B0 1 * * 0 0 0 LD B,n 06 nn 2 x x x x x OR B B0 1 * * 0 0 0
LD BC.mn 01 nn mm 3 x x x x x OR C B1 1 * * 0 0 0 LD BC.mn 01 nn mm 3 x x x x x OR C B1 1 * * 0 0 0
LD C,(HL) 4E 2 x x x x x OR D B2 1 * * 0 0 0 LD C,(HL) 4E 2 x x x x x OR D B2 1 * * 0 0 0
LD C,A 4F 1 x x x x x OR E B3 1 * * 0 0 0 LD C,A 4F 1 x x x x x OR E B3 1 * * 0 0 0
LD C,B 48 1 x x x x x OR H B4 1 * * 0 0 0 LD C,B 48 1 x x x x x OR H B4 1 * * 0 0 0
LD C,C 49 1 x x x x x OR L B5 1 * * 0 0 0 LD C,C 49 1 x x x x x OR L B5 1 * * 0 0 0
LD C,D 4A 1 x x x x x OR n F6 nn 2 * * 0 0 0 LD C,D 4A 1 x x x x x OR n F6 nn 2 * * 0 0 0
LD C,E 4B 1 x x x x x OUT (n),A D3 nn 3 x x x x x LD C,E 4B 1 x x x x x OUT (n),A D3 nn 3 x x x x x
LD C,H 4C 1 x x x x x POP AF F1 3 x x x x x LD C,H 4C 1 x x x x x POP AF F1 3 x x x x x
LD C,L 4D 1 x x x x x POP BC C1 3 x x x x x LD C,L 4D 1 x x x x x POP BC C1 3 x x x x x
LD C,n 0E nn 2 x x x x x POP DE D1 3 x x x x x LD C,n 0E nn 2 x x x x x POP DE D1 3 x x x x x
LD D,(HL) 56 2 x x x x x POP HL E1 3 x x x x x LD D,(HL) 56 2 x x x x x POP HL E1 3 x x x x x
LD D,A 57 1 x x x x x PUSH AF F5 3 x x x x x LD D,A 57 1 x x x x x PUSH AF F5 3 x x x x x
LD D,B 50 1 x x x x x PUSH BC C5 3 x x x x x LD D,B 50 1 x x x x x PUSH BC C5 3 x x x x x
LD D,C 51 1 x x x x x PUSH DE D5 3 x x x x x LD D,C 51 1 x x x x x PUSH DE D5 3 x x x x x
LD D,D 52 1 x x x x x PUSH HL E5 3 x x x x x LD D,D 52 1 x x x x x PUSH HL E5 3 x x x x x
LD D,E 53 1 x x x x x RET C9 3 x x x x x LD D,E 53 1 x x x x x RET C9 3 x x x x x
LD D,H 54 1 x x x x x RET C D8 1/3 x x x x x LD D,H 54 1 x x x x x RET C D8 1/3 x x x x x
LD D,L 55 1 x x x x x RET NC D0 1/3 x x x x x LD D,L 55 1 x x x x x RET NC D0 1/3 x x x x x
LD D,n 16 nn 2 x x x x x RET NZ C0 1/3 x x x x x LD D,n 16 nn 2 x x x x x RET NZ C0 1/3 x x x x x
LD DE,mn 11 nn mm 3 x x x x x RET Z C8 1/3 x x x x x LD DE,mn 11 nn mm 3 x x x x x RET Z C8 1/3 x x x x x
LD E,(HL) 5E 2 x x x x x RLA 17 1 x x 0 0 * LD E,(HL) 5E 2 x x x x x RLA 17 1 x x 0 0 *
LD E,A 5F 1 x x x x x RLCA 07 1 x x 0 0 * LD E,A 5F 1 x x x x x RLCA 07 1 x x 0 0 *
LD E,B 58 1 x x x x x RRA 1F 1 x x 0 0 * LD E,B 58 1 x x x x x RRA 1F 1 x x 0 0 *
LD E,C 59 1 x x x x x RRCA 0F 1 x x 0 0 * LD E,C 59 1 x x x x x RRCA 0F 1 x x 0 0 *
LD E,D 5A 1 x x x x x SBC A,C 99 1 * * * 1 * LD E,D 5A 1 x x x x x SBC A,C 99 1 * * * 1 *
LD E,E 5B 1 x x x x x SBC A,n DE nn 2 * * * 1 * LD E,E 5B 1 x x x x x SBC A,n DE nn 2 * * * 1 *
LD E,H 5C 1 x x x x x SCF 37 1 x x 0 0 1 LD E,H 5C 1 x x x x x SCF 37 1 x x 0 0 *
LD E,L 5D 1 x x x x x SUB A,(HL) 96 2 * * * 1 * LD E,L 5D 1 x x x x x SUB A,(HL) 96 2 * * * 1 *
LD E,n 1E nn 2 x x x x x SUB A,B 90 1 * * * 1 * LD E,n 1E nn 2 x x x x x SUB A,B 90 1 * * * 1 *
LD H,(HL) 66 2 x x x x x SUB A,C 91 1 * * * 1 * LD H,(HL) 66 2 x x x x x SUB A,C 91 1 * * * 1 *
LD H,A 67 1 x x x x x SUB A,D 92 1 * * * 1 * LD H,A 67 1 x x x x x SUB A,D 92 1 * * * 1 *
LD H,B 60 1 x x x x x SUB A,E 93 1 * * * 1 * LD H,B 60 1 x x x x x SUB A,E 93 1 * * * 1 *
LD H,C 61 1 x x x x x SUB A,H 94 1 * * * 1 * LD H,C 61 1 x x x x x SUB A,H 94 1 * * * 1 *
LD H,D 62 1 x x x x x SUB A,L 95 1 * * * 1 * LD H,D 62 1 x x x x x SUB A,L 95 1 * * * 1 *
LD H,E 63 1 x x x x x SUB n D6 nn 2 * * * 1 * LD H,E 63 1 x x x x x SUB n D6 nn 2 * * * 1 *
LD H,H 64 1 x x x x x XOR (HL) AE 2 * * 0 0 0 LD H,H 64 1 x x x x x XOR (HL) AE 2 * * 0 0 0
LD H,L 65 1 x x x x x XOR B A8 1 * * 0 0 0 LD H,L 65 1 x x x x x XOR B A8 1 * * 0 0 0
LD H,n 26 nn 2 x x x x x XOR C A9 1 * * 0 0 0 LD H,n 26 nn 2 x x x x x XOR C A9 1 * * 0 0 0
LD HL,(mn) 2A nn mm 5 x x x x x XOR D AA 1 * * 0 0 0 LD HL,(mn) 2A nn mm 5 x x x x x XOR D AA 1 * * 0 0 0
LD HL,mn 21 nn mm 3 x x x x x XOR E AB 1 * * 0 0 0 LD HL,mn 21 nn mm 3 x x x x x XOR E AB 1 * * 0 0 0
LD L,(HL) 6E 2 x x x x x XOR H AC 1 * * 0 0 0 LD L,(HL) 6E 2 x x x x x XOR H AC 1 * * 0 0 0
LD L,A 6F 1 x x x x x XOR L AD 1 * * 0 0 0 LD L,A 6F 1 x x x x x XOR L AD 1 * * 0 0 0
LD L,B 68 1 x x x x x XOR n EE nn 2 * * 0 0 0 LD L,B 68 1 x x x x x XOR n EE nn 2 * * 0 0 0
LD L,C 69 1 x x x x x LD L,C 69 1 x x x x x
LD L,D 6A 1 x x x x x LD L,D 6A 1 x x x x x
LD L,E 6B 1 x x x x x LD L,E 6B 1 x x x x x
LD L,H 6C 1 x x x x x LD L,H 6C 1 x x x x x
LD L,L 6D 1 x x x x x LD L,L 6D 1 x x x x x
LD L,n 2E nn 2 x x x x x LD L,n 2E nn 2 x x x x x
NOP 00 1 x x x x x Reproduced by P. Townshend 2003 NOP 00 1 x x x x x Reproduced by P. Townshend 2003
NOTE
NOTE
53
NOTE