15 1 Architectural Overview 16 2 CPU Register 17 3 Two Index Registers (IX and IY). The two independent index registers hold a 16-bit base 18 4 isters are used for a wide range of applications. They also simplify programing, specifi- 19 5 27 30 A0 20 6 RD, and WR have entered their high-impedance states. The external circuitry can now 21 7 RFSH. Refresh (output, active Low). RFSH, together with MREQ, indicates that the lower 22 8 WAIT state is entered during the following cycle. Using this technique, the read can be 23 9 M1 Cycle 24 10 Memory Read Cycle Memory Write Cycle 25 11 T1 T2 TW* T3 T1 26 12 large blocks of data are transferred under DMA control. During a bus request cycle, the 27 13 Last M Cycle of Instruction M1 28 14 Last M Cycle M1 29 15 M1 M1 30 16 Power-Down Release Cycle 31 17 T1 T2 T3 T4 T1 T2 TWA TWA 32 18 The state of IFF1 is used to inhibit interrupts while IFF2 is used as a temporary storage 33 19 Table 1. Interrupt Enable/Disable, Flip-Flops (Continued) 34 20 In Mode 2, the programmer maintains a table of 16-bit starting addresses for every inter- 35 21 Hardware and Software Implementation 36 22 Because the Z80 CPU requires only a single 5 V power supply, most small systems can be 37 23 Address: 38 24 WAIT 39 25 Interfacing Dynamic Memories 40 26 Software Implementation Examples 41 27 Specific Z80 Instruction Examples 42 28 LD HL, DATA ;ADDRESS OF FIRST BYTE 43 29 SBC A, (HL) ;SUBTRACT (HL) FROM ACC 44 30 Table 2. Bubble Listing (Continued) 45 31 The program outlined in Table 3 multiplies two unsigned 16-bit integers, leaving the result 46 32 Z80 CPU Instructions 47 33 An example of an arithmetic operation is adding the Accumulator to the contents of an 48 34 Addressing Modes 49 35 Modified Page Zero Addressing 50 36 Extended Addressing 51 37 complement number. Indexed addressing greatly simplifies programs using tables of data 52 38 parentheses around the name of the register that is to be used as the pointer. For example, 53 39 Instruction Notation Summary 54 40 Instruction Op Codes 55 41 Load and Exchange 56 42 Table 6. 8-Bit Load Group LD 57 43 Note: Descriptions of the 8-Bit Load Group instructions begin on page 70. 58 44 Address A 3A Op Code 59 45 In this figure, note that with any indexed addressing, the displacement always follows 60 46 Note: Descriptions of the 16-Bit Load Group instructions begin on page 98. 61 47 Address A E6 Op Code 62 48 Table 9. Block Transfer Group 63 49 Table 10. Block Search Group 64 50 Table 11. 8-Bit Arithmetic and Logic 65 51 The INC and DEC instructions specify a register or a memory location as both the source 66 52 Note: Descriptions of the General-Purpose Arithmetic and CPU Control Groups instructions 67 53 Rotate and Shift 68 54 Source 69 55 Bit Manipulation 70 56 Table 14. Bit Manipulation Group (Continued) 71 57 Table 14. Bit Manipulation Group (Continued) 72 58 Register addressing can specify the Accumulator or any general-purpose register on which 73 59 Table 15. Jump, Call, and Return Group 74 60 gram Counter to form a jump address. The call and return instructions allow for simple 75 61 Table 17. Restart Group 76 62 Table 18. Input Group 77 63 Table 19. 8-Bit Arithmetic and Logic 78 64 Table 20. Miscellaneous CPU Control 79 65 Z80 Instruction Set 80 66 Table 22. Flag Definitions 81 67 Decimal Adjust Accumulator Flag 82 68 During the CPI, CPIR, CPD, and CPDR search instructions and the LDI, LDIR, LDD, and 83 69 Sign Flag 84 70 8-Bit Load Group 85 71 LD r, r' 86 72 LD r,n 87 73 Example 88 74 LD r, (HL) 89 75 LD r, (IX+d) 90 76 Example 91 77 LD r, (IY+d) 92 78 Example 93 79 LD (HL), r 94 80 Example 95 81 LD (IX+d), r 96 82 Example 97 83 LD (IY+d), r 98 84 Example 99 85 LD (HL), n 100 86 LD (IX+d), n 101 87 LD (IY+d), n 102 88 LD A, (BC) 103 89 LD A, (DE) 104 90 LD A, (nn) 105 91 LD (BC), A 106 92 LD (DE), A 107 93 LD (nn), A 108 94 LD A, I 109 95 LD A, R 110 96 LD I,A 111 97 LD R, A 112 98 16-Bit Load Group 113 99 LD dd, nn 114 100 LD IX, nn 115 101 LD IY, nn 116 102 LD HL, (nn) 117 103 LD dd, (nn) 118 104 Example 119 105 LD IX, (nn) 120 106 LD IY, (nn) 121 107 LD (nn), HL 122 108 LD (nn), dd 123 109 Example 124 110 LD (nn), IX 125 111 LD (nn), IY 126 112 LD SP, HL 127 113 LD SP, IX 128 114 LD SP, IY 129 115 PUSH qq 130 116 Example 131 117 PUSH IX 132 118 PUSH IY 133 119 POP qq 134 120 Example 135 121 POP IX 136 122 POP IY 137 123 Exchange, Block Transfer, and Search Group 138 124 EX DE, HL 139 125 EX AF, AF′ 140 126 EXX 141 127 EX (SP), HL 142 128 EX (SP), IX 143 129 EX (SP), IY 144 130 LDI 145 131 register pair contains 7h, then the instruction LDI results in the following contents in reg- 146 132 LDIR 147 133 P/V is set if BC – 1 ≠ 0; otherwise, it is reset. 148 134 LDD 149 135 ister pair contains 7h, then instruction LDD results in the following contents in register 150 136 LDDR 151 137 Condition Bits Affected 152 138 CPI 153 139 CPIR 154 140 Condition Bits Affected 155 141 CPD 156 142 CPDR 157 143 P/V is set if BC – 1 ≠ 0; otherwise, it is reset. 158 144 8-Bit Arithmetic Group 159 145 ADD A, r 160 146 P/V is set if overflow; otherwise, it is reset. 161 147 ADD A, n 162 148 ADD A, (HL) 163 149 ADD A, (IX + d) 164 150 ADD A, (IY + d) 165 151 ADC A, s 166 152 r identifies registers B, C, D, E, H, L, or A, assembled as follows in the object code field: 167 153 SUB s 168 154 r identifies registers B, C, D, E, H, L, or A assembled as follows in the object code field: 169 155 SBC A, s 170 156 r identifies registers B, C, D, E, H, L, or A assembled as follows in the object code field: 171 157 AND s 172 158 r identifies registers B, C, D, E, H, L, or A specified in the assembled object code field, as 173 159 OR s 174 160 r identifies registers B, C–, D, E, H, L, or A specified in the assembled object code field, 175 161 XOR s 176 162 r identifies registers B, C, D, E, H, L, or A specified in the assembled object code field, as 177 163 CP s 178 164 r identifies registers B, C, D, E, H, L, or A specified in the assembled object code field, as 179 165 INC r 180 166 N is reset. 181 167 INC (HL) 182 168 INC (IX+d) 183 169 INC (IY+d) 184 170 DEC m 185 171 Description 186 172 General-Purpose Arithmetic and CPU 187 173 DAA 188 174 M Cycles T States 4 MHz E.T. 189 175 CPL 190 176 NEG 191 177 Example 192 178 CCF 193 179 SCF 194 180 NOP 195 181 HALT 196 182 DI 197 183 EI 198 184 IM 0 199 185 IM 1 200 186 IM 2 201 187 16-Bit Arithmetic Group 202 188 ADD HL, ss 203 189 C is set if carry from bit 15; otherwise, it is reset. 204 190 ADC HL, ss 205 191 N is reset. 206 192 SBC HL, ss 207 193 N is set. 208 194 ADD IX, pp 209 195 N is reset. 210 196 ADD IY, rr 211 197 N is reset. 212 198 INC ss 213 199 INC IX 214 200 INC IY 215 201 DEC ss 216 202 DEC IX 217 203 DEC IY 218 204 Rotate and Shift Group 219 205 RLCA 220 206 Example 221 207 RLA 222 208 Example 223 209 RRCA 224 210 7 6 5 4 3 2 1 0 225 211 RRA 226 212 Example 227 213 RLC r 228 214 Condition Bits Affected 229 215 RLC (HL) 230 216 Example 231 217 RLC (IX+d) 232 218 C is data from bit 7 of source register. 233 219 RLC (IY+d) 234 220 C is data from bit 7 of source register. 235 221 RL m 236 222 r identifies registers B, C, D, E, H, L, or A assembled as follows in the object code field: 237 223 Upon the execution of an RL D instruction, the D Register and the Carry flag now contain: 238 224 RRC m 239 225 RRC r* 1 1 0 0 1 0 1 1 CB 240 226 Instruction M Cycles T States 4 MHz E.T. 241 227 RR m 242 228 RR r* 1 1 0 0 1 0 1 1 CB 243 229 Instruction M Cycles T States 4 MHz E.T. 244 230 SLA m 245 231 r identifies registers B, C, D, E, H, L, or A assembled as follows in the object code field: 246 232 Upon the execution of an SLA L instruction, Register L and the Carry flag now contain: 247 233 SRA m 248 234 r identifies registers B, C, D, E, H, L, or A assembled as follows in the object code field: 249 235 Upon the execution of an SRA (IX+3h) instruction, memory location 1003h and the 250 236 SRL m 251 237 r identifies registers B, C, D, E, H, L, or A. 252 238 RLD 253 239 P/V is set if the parity of the Accumulator is even after an operation; otherwise, it is reset. 254 240 RRD 255 241 P/V is set if the parity of the Accumulator is even after an operation; otherwise, it is reset. 256 242 Bit Set, Reset, and Test Group 257 243 BIT b, r 258 244 H is set. 259 245 BIT b, (HL) 260 246 Z is set if specified bit is 0; otherwise, it is reset. 261 247 BIT b, (IX+d) 262 248 Condition Bits Affected 263 249 BIT b, (IY+d) 264 250 Condition Bits Affected 265 251 SET b, r 266 252 Example 267 253 SET b, (HL) 268 254 Example 269 255 SET b, (IX+d) 270 256 Condition Bits Affected 271 257 SET b, (IY+d) 272 258 Condition Bits Affected 273 259 RES b, m 274 260 Bit b Register r 275 261 Jump Group 276 262 JP nn 277 263 JP cc, nn 278 264 M Cycles T States 4 MHz E.T. 279 265 JR e 280 266 Location Instruction 281 267 JR C, e 282 268 Example 283 269 JR NC, e 284 270 Example 285 271 JR Z, e 286 272 Example 287 273 JR NZ, e 288 274 Example 289 275 JP (HL) 290 276 JP (IX) 291 277 JP (IY) 292 278 DJNZ, e 293 279 Condition Bits Affected 294 280 Call and Return Group 295 281 CALL nn 296 282 Example 297 283 CALL cc, nn 298 284 Relevant 299 285 RET 300 286 RET cc 301 287 If cc is true, then the following data is returned: 302 288 RETI 303 289 A B 304 290 RETN 305 291 That address begins an interrupt service routine that ends with a RETN instruction. Upon 306 292 RST p 307 293 M Cycles T States 4 MHz E.T. 308 294 Input and Output Group 309 295 IN A, (n) 310 296 IN r (C) 311 297 Condition Bits Affected 312 298 INI 313 299 Example 314 300 INIR 315 301 Condition Bits Affected 316 302 IND 317 303 Example 318 304 INDR 319 305 Condition Bits Affected 320 306 OUT (n), A 321 307 OUT (C), r 322 308 Condition Bits Affected 323 309 OUTI 324 310 Example 325 311 OTIR 326 312 If B = 0: 327 313 OUTD 328 314 Example 329 315 OTDR 330 316 If B = 0: 331 317 Customer Support 332 318 Customer Support UM008011-0816