Programming the Z80 3Rd (1980)(Sybex)(Pdf)
Total Page:16
File Type:pdf, Size:1020Kb
c J o liiJ U V rlm oooo x oooo r oooo l oo ■GO.? DL=OOOO HL 0000 SI 0300 L 010/, 0106 1A | 0 M ' ^ 0 0 II If OOOO I Oo A | (19,1 MF 9mS o 5 i l ■ Lggf «Sg T LfJ< B l It' |U 1' |g££ja| M?p i ■ 1 'M9 r'!DL9 SH-.:1. ;.-oo^Bi p|S> B l ii Hi .o o o o fVr feesfrig: D'BsB'iiBfl '0^3':■rtS-: jStil i1 (OOOO O 1 aI< •8>e 9B)S k m S mpiu oolR;I S (BL^l-oior9PL.4 oior 7H l <\ r oo w r1< 0 I I 6 K y j > 8|By ■ . r ^ s A to Hi | ■ .[ 00 I Hi * Sf: ' f HE ( S p- 0 I 1 8 H P' fo^AL. ooo|^j|J^P(>iu^BoH^^ooo[Jl 1 lJ L =-00 A 00 DC=070i HE - 000A HL = 0005 S 0300 P 0119 0 1 J V NJ .0 I OF • 00 F< '= 0000 It = 0000 H ' -OOOO X OOOO Y OOOO 1 - 00 (0101 ' ) A 00 in: 0701 ME=OOOA HI. 000‘. S 0300 F 01 Of 0 1 OF i oo n =0900 it' oooo H'--oooo x oooo y oooo T -0 0 . oo F<r:-o.\,o m f -o o o a hi =0005 s 0:100 i- 0111 0111 Nl .0 LI 4 1 - 00 H ' “ OOOO I f OOOO M' -OOOO X OOOO Y OOOO 1 00 ( O i l 4 ' ) a oo r»c=o/oo rtE OOOA 000'; H 0.100 F' 0 1 1.1 0113 A oo H oooo n oooo OOOO X OOOO Y OOOO T =00 r. 00 IK 0 700 m: o o o a A 00 ft oooo n oooo : R n n i\fA \ A” 00 Ml.’” 0700 M E=0014 HI 00(fl O il * ' \ * mm A 00 K'=0000 M' OOOO M OOOO X OOOO Y OOOO [=00 A 00 Id 0/00 Ml =00 I =1 HI -OOOF s - o 100 P - 0 118 o m r Mrc: A 00 l< 0000 I f oooo H ' OOOO y OOOO Y OOOO i oo A OO Hi 0600 Ml 001=1 III OOOF 5-0300 I- 01 IV 011V' II - A ' = 00 !• o'OOO I f =0000 H OOOO X oooo Y OOOO J - 00 t 0101 A =00 H 0 0 6 0 0 DL 001 =1 HL =0001 S 0.100 P 01 OF 0 i o r ' c.;f i 0< B OOOO D ' OOOO H ' " OOOO X OOOO Y OOOO 1 - 00 A 00 !«C= 0600 D£ 0014 HL 0001 5 0100 1=01 L I 01 I I ' JR A =00 Ft -OOOO Ft' OOOO H OOOO x oooo Y OOOO 1 - oo A -00 DC 0600 Ml 00 J 4 III 0001 5 0.100 P -0 I I 4 0 114' SI. A A' 00 F< -OOOO M' OOOO I I ' OOOO x oooo Y OOOO A 00 Jdi 0600 ME=0028 HL 0001 •; 0300 F' O il 6 01 16' LI A 0 0 ft' -OOOO F f OOOO H ' OOOO x-- oooo Y OOOO I = 00 A '= 00 t<i: 0600 I IF 0028 HI OOOF 5=0300 F1 OllO 0J 18' Ml i: A =00 [t OOOO n oooo I f =0000 X oooo Y OOOO I 00 A *00 l« =0500 mi: o o .>ci III OOOF 5 0300 P O i l 9 Oil? If"- N / . 0 L 03 A 00 It ’ OOOO I f 0 H OOOO X OOOO Y OOOO l 00 1 JO I OF '' t A =00 t<C 0500 ME 0 0 .’8 HI OOOF S 0.100 i=oi or 0101 ' SKI A ' -=()0 It ' OOOO M OOOO H * OOOO X oooo Y OOOO •I “ ,0Q. A 00 r«C 0500 ML = 0028 HI =0001 S 0.300 I-' 01 I I 0 III . IR A 00 H ' OOOO It ' OOOO H OOOO X oooo Y OOOO 1 OO A 00 Itf 0500 MF 0078 111 0001 S 0 100 F' 01 M o i i -i • *;i a -A'—GQFt' OOOo It OOOO H OOOO y =0000 Y OOOO A 00 ?<C 01.-00 Ml 0050 HI OOOF 5 0300 P 01 16 0116 P I A 00 H OOOO II* OOOO II OOOO x -oooo Y OOOO 1 00 a =00 tot: o5oo III 0050 III - 0001 5 0300 i • o J i n 0 1 I f f ME' A A A ii'rflrtrtn n nr.A.i II ftiWV> X dKtOft y oooo r oo PROGRAMMING THEZ80 PROGRAMMING THEZ80 RODNAY ZAKS THIRD EDITION “ Z80” is a registered trademark of ZILOG Inc., with whom SYBEX is not connected in any way. Cover Design by Daniel le Noury Every effort has been made to supply complete and accurate information. However, Sybex assumes no responsibility for its use; nor any infringements of patents or other rights of third parties which would result. No license is granted by the equipment manu facturers under any patent or patent rights. Manufacturers reserve the right to change circuitry at any time without notice. In particular, technical characteristics and prices are subject to rapid change. Com parisons and evaluations are presented for their educational value and for guidance principles. The reader is referred to the manufacturer’s data for exact specifications. Copyright ©1980, SYBEX Inc. World rights reserved. No part of this publication may be stored in a retrieval system, transmitted, or reproduced in any way, including but not limited to, photocopy, photograph, or magnetic or other record, without the poor written permission of the publisher. Library of Congress Card Number: 80-5468 ISBN: 0-89588-094-6 First Edition published 1979. Third Edition 1981 Printed in the United States of America Printing 109 8 7 6 5 43 ACKNOWLEDGEMENTS Designing a programming textbook is always difficult. Designing it so that it will teach elementary programming as well as advanced concepts while covering both hardware and software aspects makes it a challenge. The author would like to acknowledge here the many constructive suggestions for improvements or changes made by: O.M. Barlow, Dennis L. Feick, Richard D, Reid, Stanley E. Erwin, Philip Hooper, Dennis B. Kitsz, R. Ralke, and Jim Crocker. A special acknowledgement is also due to Chris Williams for his contribution to the instruction-set and the data structures section. Any additional suggestions for improvements or changes should be sent to the author, and will be reflected in forthcoming editions. Several tables in Chapter Four showing hexadecimal codes for the Z80 instructions have been reprinted by permission of Zilog Inc. Tables 2.26 and 2.27 have been reprinted by permission of Intel Corporation. TABLE OF CONTENTS PREFACE 13 L BASIC CONCEPTS IS Introduction, What is programming?, Flowcharting, Informa tion Representation H. Z80 HARDWARE ORGANIZATION 46 Introduction, System Architecture, Internal Organization of the Z80, Instruction Formats, Execution o f Instructions with the Z80, Hardware Summary III. BASIC PROGRAMMING TECHNIQUES 94 Introduction, Arithmetic Programs, BCD Arithmetic Multipli cation, Binary Division, Instruction Summary, Subroutines, Summary IV. THE Z80 INSTRUCTION SET 154 Introduction, Classes o f Instructions, Summary, Individual Descriptions V. ADDRESSING TECHNIQUES 438 Introduction, Possible Addressing Modes, Z80 Addressing Modes, Using the Z80 Addressing Modes, Summary VI. INPUT/OUTPUT TECHNIQUES 460 Introduction, Input/output, Parallel Word Transfer, Bit Serial Transfer, Peripheral Summary, Input/Output Scheduling, Summary VII. INPUT/OUTPUT DEVICES 511 Introduction, The StandardPIO, The Internal Control Register, Programming a PIO, The Zilog Z80 PIO VIH. APPLICATION EXAMPLES 520 Introduction, Clearing a Section of Memory, Polling I/O Devices, Getting Characters In, Testing A Character, Bracket Testing, Parity Generation, Code Conversion: ASCII to BCD, Convert Hex to ASCII, Finding the Largest Element o f a Table. Sum of N Elements, A Checksum Computation, Count the Zeroes, Block Transfer, BCD Block Transfer, Compare Two Signed 16-bit Numbers, Bubble-Sort, Summary IX. DATA STRUCTURES 539 PARTI-THEORY Introduction, Pointers, Lists, Searching and Sorting, Section Summary PART 2—DESIGN EXAMPLES Introduction, Data Representation for the List, A Simple List, Alphabetic Set, Linked List, Summary X. PROGRAM DEVELOPMENT 579 introduction, Basic Programming Choices, Software Support, The Program Development Sequence, Hardware Alternatives, The Assembler, Conditional Assembly, Summary XI. CONCLUSION 602 Technological Development, The Next Step APPENDIX A 604 Hexadecimal Conversion Table APPENDIX B 605 ASCII Conversion Table APPENDIX C 606 Relative Branch Tables APPENDIX D 607 Decimal to BCD Conversion APPENDIX E 608 Z80 Instruction Codes APPENDIX F 615 Z80 to 8080 Equivalence APPENDIX G 616 8080 to Z80 Equivalence INDEX 617 PREFACE This book has been designed as a complete self-contained text for learning programming, using the Z80. It can be used by a person who has never programmed before, and should also be of value to anyone using the Z80. For the person who has already programmed, this book will teach specific programming techniques using (or working around) the speci fic characteristics of the Z80. This text covers the elementary to inter mediate techniques required to start programming effectively. This text aims at providing a true level of competence to the person who wishes to program using this microprocessor. Naturally, no book will effectively teach how to program, unless one actually practices, However, it is hoped that this book will take the reader to the point where he feels that he can start programming by himself and can solve simple or even moderately complex problems using a microcomputer. This book is based on the author’s experience in teaching more than 1000 persons how to program microcomputers.