Z80 CPU Instruction Description: - 158 Different Instruction Types - Instruction Groups
Z80 CPU Instruction Description: - 158 Different Instruction Types - Instruction Groups
Description
Addressing
Modes
Immediate
Addressing LD A,5
Immediate Extended
LD HL,7FC6H
Modified Page Zero Addressing RST 8
Relative Addressing
JR label
Jump Relative (2 byte)
One Byte Op Code
8-Bit Twos Complement Displacement (A+2)
Extended Addressing
JP label
Absolute jump
One byte opcode
2 byte address
Indexed Addressing
INC (IX+2)
Addressing Modes
Register
Addressing
(cont.)
LD C,B
Implied Addressing
Op Code implies other operand(s)
SUB E
; A is implied (A = A - E)
Register Indirect Addressing
16-bit CPU register pair as pointer (such as HL)
ADD A,(HL)
Bit Addressing
set, reset, and test instructions.
SET 3,A
RES 7,B
START:
label field
LD A, (VAL1)
opcode or
operand or address field
mnemonic field
LABELS:
Label field (may be blank) is the first field in an assembly language instruction.
Address of the first program byte for that instruction is associated with the
label
You may use the label as data or as an address in another instruction's operand
field.
Machine Code
Instruction Format
MachineCodeInstructionOpcode+Operands
Z80instruction ranges from one byte to four bytes
Opcode varies from 1 to 2 bytes
Operands varies from 1 to 2 bytes
Operands could be memory locations , registers, I/O
addresses , or memory addresses
10
11
examples: LD A,2AH
LD L,80H
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
LD A,(address)
==> 3 bytes
example: LD A,(084AH)
address memory
084A
4F
A<== 4FH
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
example: LD A,(BC)
assume BC contains 084AH
address memory
084A
4F
A<== 4FH
rp: BC,DE,HL
Load the contents of the memory location
address to the register pair or index registers.
* 2 bytes of data move from memory to registers
address memory
49FF
B8
==> E
4A00
33
==> D
DE <== 33B8H
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
14
==> 3 bytes
example:
LD A,4FH
A <==
4FH
LD (084AH),A
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
LD (address),HL
LD (address),rp
LD (address),IX
LD (address),IY
==> 3 bytes
==> 4 bytes
rp: BC,DE,HL
Load the contents of the register pair or index
registers to the memory location address.
* 2 bytes of data move from registers to memory
example:
LD BC,3C2AH
LD (084AH),BC
address memory
084AH
2A <== C
084BH
3C
<== B
address memory
4F00H 3F
<== C
example:
LD BC,084AH
LD A,3FH
LD (BC),A
rp: BC,DE,HL
Load the contents of the memory location
pointed by the given register pair to the
accumulator.
* indirect addressing
address memory
084A
3F
<== A
ADC A,data8 ==> 2 bytes Add the immediate 8-bit data to the accumulator
with carry bit. A=A+data8+carry
example : LD A,3AH
00111010 B
58 (decimal)
ADC A,7CH 01111100 B 124 (decimal) result = 182 >127
+
0 <== carry
0 10110110 = B6H ==> A (-74 signed decimal)
CY=0
Z=0 (result is nonzero) S=1 (MSB of result)
N=0 (addition)
P/V= carry XOR carry out of 6th bit = 0 XOR 1 = 1 (overflow) : result is wrong!
ADC A,(HL)
==> 1 bytes
ADC A,(IX+d) ==> 3 bytes
ADC A,(IX+d)
ADC A,r
rp: BC,DE,HL,SP
HL=HL+rp+carry
Assume that HL=A536H, BC=1044H and carry=1
HL=HL+rp
IX=IX+rp
A=A.(HL)
A=A.(IY+d)
OR (logical OR)
XOR (logical XOR)
LD C,EFH
; 11101111
BIT 4,C ; 4th bit is zero, so Z=1 after the execution
example:
.
.
JP NEXT ; ADD instruction will be executed after the JP instruction.
AND 7FH
.
.
NEXT ADD A,(HL)
Conditional Jump:
Identical to JP instruction except
that the jump will be performed
only if the condition is satisfied,
otherwise the instruction
sequentially following the JP
condition instruction will be
executed.
condition
NZ
NonZero
Z
Zero
NC
No Carry
C
Carry
PO
Parity Odd
PE
Parity Even
P
Sign Positive
M
Sign Negative
related flag
Z (if Z=0)
Z (if Z=1)
C (if C=0)
C (if C=1)
P/O (if P/O =0)
P/O (if P/O =1)
S (if S=0)
S (if S=1)
example:
.
.
JP NC, FORWARD ; if carry=0, OR instruction is executed
AND 7FH
; next, otherwise AND instruction
FORWARD
OR B
; is executed
.
.
18H
disp
LABEL
NEXT
.
.
JR NEXT
AND 7FH
.
.
ADD A,(HL)
.
.
example:
.
.
ADD A,0
; A=A+0
JR Z,FORWARD ; if zero flag=1 (zero result) OR instruction is
AND 7FH
; executed next, otherwise AND instruction is
.
; executed
.
FORWARD
OR B
.
example :
LD A,E3H
CP A0H
11100011 B
10100000 B
_
borrow for 7th bit (MSB) copied into the carry flag 0 01000011
CY=0 (no borrow)
Z=0 (result is nonzero)
S=0 (MSB of result)
H=0 (no borrow)
N=1 (subtraction)
P/V= carry XOR borrow for 6th bit = 0 XOR 0 = 0 (no overflow)
When signed numbers are manipulated: ==> result is correct
example :
LD A,93H
LD B,C0H
CP B
borrow for 7th bit (MSB) copied into the carry flag 1
10010011 B
11000000 B
_
11010011
CY=1 (borrow)
Z=0 (result is nonzero)
S=1 (MSB of result)
H=0 (no borrow)
N=1 (subtraction)
P/V= carry XOR borrow for 6th bit = 1 XOR 1 = 0 (no overflow)
When signed numbers are manipulated: ==> result is correct
LD A,E3H
11100011 B
LD (HL),A0
10100000 B
CP (HL)
_
borrow for 7th bit (MSB) copied into the carry flag 0 01000011
CY=0 (no borrow)
Z=0 (result is nonzero)
S=0 (MSB of result)
H=0 (no borrow)
N=1 (subtraction)
P/V= carry XOR borrow for 6th bit = 0 XOR 0 = 0 (no overflow)
When signed numbers are manipulated: ==> result is correct
CPL==> 1 byte
example:
LD A,3AH
CPL
NEG==> 2 byte
A <== 00111010
A <== 11000101
example:
LD A,5AH
NEG
A <== 01011010
A <== 10100110 (2's complement of 5AH )
S,Z,H,P/V are
(machine
control instr.)
NOP==> 1 byte
(no operation)
opcode: 00H
- PC is incremented but Z80 performs no operation during the instruction cycle.
- Used to increase time delays and delete and insert instructions during
troubleshooting.
LD B,100
; 7T
LOOP NOP
; 4T
NOP ; 4T
NOP ; 4T
DEC B
; 4T
JR NZ,LOOP
;12T
HALT==> 1 byte
- Suspends (halts) all operationstop the program execution.
- Z80 requires an interrupt or a reset to restart execution.
- During the halt PC is not incremented and Z80 continues to execute NOP
instruction to maintain memory refresh cycles.
Simple Programs
Simple Programs
Simple Programs
Simple Programs
Simple Programs