The Complete Machine Code Tutor (UK) (Face 4) (1985) [Original] [TAPE] [UTILITAIRE].cdt
HexaDumpAscii only
000000:  5A 58 54 61 70 65 21 1A 01 0C 20 9E 39 11 05 09    ZXTape!... .9...
000010:  57 04 A6 04 88 04 10 09 00 10 08 FF 09 07 01 00    W...............
000020:  FC 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
000030:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
000040:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
000050:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
000060:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
000070:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
000080:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
000090:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
0000A0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
0000B0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
0000C0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
0000D0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
0000E0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
0000F0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
000100:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
000110:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
000120:  00 C9 9A FF FF FF FF 11 05 09 08 04 A6 04 8A 04    ................
000130:  14 09 00 10 08 C9 1B AF 55 00 FB 06 58 28 58 CC    ........U...X(X.
000140:  9F 28 58 2C 58 39 58 40 58 44 58 4B 58 58 58 5C    .(X,X9X@XDXKXXX\
000150:  58 63 58 73 58 7A 58 81 58 88 58 8F 58 9F 58 A6    XcXsXzX.X.X.X.X.
000160:  58 B9 58 00 B2 9E 01 00 C0 58 00 E2 5A 00 97 5D    X.X......X..Z..]
000170:  00 A9 5E 01 00 7D 60 02 17 61 01 00 BE 61 01 00    ..^..}`..a...a..
000180:  C5 63 02 87 64 01 00 2B 65 00 8C 67 00 C5 68 00    .c..d..+e..g..h.
000190:  FD 6A 01 00 95 6B 01 00 CE 6D 00 FB 6F 01 00 F5    .j...k...m..o...
0001A0:  70 00 24 72 00 5E 74 00 0E 77 00 7D 78 01 00 69    p.$r.^t..w.}x..i
0001B0:  79 06 8F 7A 01 00 28 7B 00 DA 7D 01 00 C4 7E 06    y..z..({..}...~.
0001C0:  53 7F 01 00 EA 7F 00 99 81 01 00 A3 83 00 08 86    S..........£....
0001D0:  00 8B 88 00 64 8A 00 6B 8C 01 00 07 8D 02 47 8F    ....d..k......G.
0001E0:  01 00 8C 8F 00 4D 92 00 5F 94 00 5C 96 00 31 99    .....M.._..\..1.
0001F0:  00 F2 99 01 00 BA 9B 00 82 9E 01 20 20 20 20 20    ...........     
000200:  20 20 20 20 20 20 20 20 49 4E 44 45 58 20 52 45            INDEX RE
000210:  47 49 53 54 45 52 53 A0 A0 20 57 65 20 6E 6F 77    GISTERS.. We now
000220:  20 69 6E 74 72 6F 64 75 63 65 20 74 77 6F 20 6E     introduce two n
000230:  65 77 20 72 65 67 69 73 74 65 72 AF 2E 73 2C 20    ew register..s, 
000240:  74 68 65 69 6E 64 65 78 20 72 65 67 69 73 74 65    theindex registe
000250:  72 73 20 20 49 58 20 61 6E 64 20 20 49 59 2E 20    rs  IX and  IY. 
000260:  20 20 54 68 65 73 65 20 74 77 6F 72 65 67 69 73      These tworegis
000270:  74 65 72 73 20 20 61 72 65 20 20 69 64 65 6E 74    ters  are  ident
000280:  69 63 61 6C 20 69 6E 20 20 65 76 65 72 79 20 77    ical in  every w
000290:  61 79 2E 57 68 61 74 20 20 61 70 70 6C 69 65 73    ay.What  applies
0002A0:  20 20 74 6F 20 20 6F 6E 65 20 20 61 70 70 6C 69      to  one  appli
0002B0:  65 73 20 20 74 6F 20 20 74 68 65 6F 74 68 65 72    es  to  theother
0002C0:  2E A0 A0 20 54 68 65 79 20 20 63 61 6E 20 20 74    ... They  can  t
0002D0:  61 6B 65 20 20 74 68 65 20 70 6C 61 63 65 20 20    ake  the place  
0002E0:  6F 66 20 20 74 68 65 20 20 48 4C 72 65 67 69 73    of  the  HLregis
0002F0:  74 65 72 20 20 69 6E 20 20 6D 6F 73 74 20 20 69    ter  in  most  i
000300:  6E 73 74 72 75 63 74 69 6F 6E 73 2E 20 20 49 74    nstructions.  It
000310:  20 69 73 73 69 6D 70 6C 65 72 20 20 74 6F 20 20     issimpler  to  
000320:  6C 69 73 74 20 74 68 65 20 20 69 6E 73 74 72 75    list the  instru
000330:  63 74 69 6F 6E 73 20 74 68 61 74 63 61 C9 9C 6E    ctions thatca..n
000340:  20 62 65 20 70 65 72 66 6F 72 6D 65 64 20 62 79     be performed by
000350:  20 74 68 65 20 48 4C 20 72 65 67 69 73 74 65 72     the HL register
000360:  20 20 62 75 74 6E 6F 74 20 69 6E 64 65 78 20 72      butnot index r
000370:  65 67 69 73 74 65 72 73 3A 2D A0 A0 41 44 43 20    egisters:-..ADC 
000380:  20 48 4C 2C 64 64 20 20 20 53 42 43 20 48 4C 2C     HL,dd   SBC HL,
000390:  64 64 20 20 61 6E 64 20 45 58 20 44 45 2C 48 4C    dd  and EX DE,HL
0003A0:  20 61 72 65 74 68 65 20 6F 6E 6C 79 20 65 78 63     arethe only exc
0003B0:  65 70 74 69 6F 6E 73 2E A0 A0 20 54 68 65 79 20    eptions... They 
0003C0:  63 61 6E 6E 6F 74 20 62 65 20 65 78 63 68 61 6E    cannot be exchan
0003D0:  67 65 64 20 66 6F 72 20 48 4C 20 69 66 20 74 68    ged for HL if th
0003E0:  61 74 72 65 67 69 73 74 65 72 20 20 70 61 69 72    atregister  pair
0003F0:  20 69 73 20 20 6F 6E 6C 79 20 20 69 6D 70 6C 69     is  only  impli
000400:  65 64 20 20 69 6E 20 74 68 65 69 6E 73 74 72 75    ed  in theinstru
000410:  63 74 69 6F 6E 2C 20 69 2E 65 2E 20 52 52 44 2E    ction, i.e. RRD.
000420:  A3 20 54 68 65 20 20 20 67 72 65 61 74 20 20 20    £ The   great   
000430:  61 64 76 61 6E 74 61 67 65 20 20 6F 66 20 20 6B    advantage  of  k
000440:  FC 74 68 65 20 20 69 6E 64 65 78 72 65 67 69 73    .the  indexregis
000450:  74 65 72 73 20 20 20 68 6F 77 65 76 65 72 20 20    ters   however  
000460:  20 69 73 20 20 74 68 61 74 20 20 69 6E 64 69 72     is  that  indir
000470:  65 63 74 61 64 64 72 65 73 73 69 6E 67 20 20 69    ectaddressing  i
000480:  73 20 20 6E 6F 74 20 20 20 73 69 6D 70 6C 79 20    s  not   simply 
000490:  20 28 48 4C 29 20 20 20 62 75 74 28 49 58 2B 64     (HL)   but(IX+d
0004A0:  29 2E 20 20 20 20 54 68 65 20 20 20 69 6E 64 69    ).    The   indi
0004B0:  72 65 63 74 20 20 20 61 64 64 72 65 73 73 20 20    rect   address  
0004C0:  20 69 73 63 61 6C 63 75 6C 61 74 65 64 20 61 73     iscalculated as
0004D0:  20 74 68 65 20 20 73 75 6D 20 20 6F 66 20 74 68     the  sum  of th
0004E0:  65 20 20 63 6F 6E 74 65 6E 74 73 6F 66 20 74 68    e  contentsof th
0004F0:  65 20 20 49 58 2F 49 59 20 72 65 67 69 73 74 65    e  IX/IY registe
000500:  72 20 61 6E 64 20 74 68 65 20 6F 66 66 73 65 74    r and the offset
000510:  20 20 64 73 70 65 63 69 66 69 65 64 20 20 20 69      dspecified   i
000520:  6E 20 20 74 68 65 20 20 69 6E 73 74 72 75 63 74    n  the  instruct
000530:  69 6F 6E 2E A0 A0 20 49 74 20 69 73 20 65 61 73    ion... It is eas
000540:  69 45 84 65 72 20 74 6F 20 75 73 65 20 74 68 65    iE.er to use the
000550:  20 69 6E 64 65 78 20 72 65 67 69 73 74 65 72 73     index registers
000560:  74 6F 20 20 69 6E 74 65 72 72 6F 67 61 74 65 20    to  interrogate 
000570:  20 74 61 62 6C 65 73 20 74 68 61 6E 20 20 75 73     tables than  us
000580:  69 6E 67 20 20 48 4C 2E 54 68 65 20 6F 66 66 73    ing  HL.The offs
000590:  65 74 20 20 63 61 6E 20 64 65 66 69 6E 65 20 74    et  can define t
0005A0:  68 65 20 63 6F 6C 75 6D 6E 20 69 6E 20 74 68 65    he column in the
0005B0:  74 61 62 6C 65 20 20 61 6E 64 20 20 49 58 2F 49    table  and  IX/I
0005C0:  59 20 20 72 65 67 69 73 74 65 72 20 70 6F 69 6E    Y  register poin
0005D0:  74 20 74 6F 20 74 68 65 62 65 67 69 6E 6E 69 6E    t to thebeginnin
0005E0:  67 20 20 6F 66 20 20 74 68 65 20 20 6C 69 6E 65    g  of  the  line
0005F0:  2E 20 20 41 20 20 73 75 62 72 6F 75 74 69 6E 65    .  A  subroutine
000600:  63 6F 75 6C 64 20 20 6D 61 6E 69 70 75 6C 61 74    could  manipulat
000610:  65 20 20 74 68 65 20 20 64 61 74 61 20 20 77 69    e  the  data  wi
000620:  74 68 69 6E 20 74 68 65 6C 69 6E 65 2C 20 20 75    thin theline,  u
000630:  73 69 6E 67 20 20 61 20 20 63 6F 6E 73 74 61 6E    sing  a  constan
000640:  74 20 49 1A 94 58 2F 49 59 20 70 6F 69 6E 74 65    t I..X/IY pointe
000650:  72 2E 53 75 62 73 65 71 75 65 6E 74 20 6C 69 6E    r.Subsequent lin
000660:  65 73 20 63 61 6E 20 74 68 65 6E 20 62 65 20 6D    es can then be m
000670:  61 6E 69 70 75 6C 61 74 65 64 73 69 6D 70 6C 79    anipulatedsimply
000680:  20 20 62 79 20 75 73 69 6E 67 20 74 68 65 20 73      by using the s
000690:  61 6D 65 20 73 75 62 72 6F 75 74 69 6E 65 20 61    ame subroutine a
0006A0:  6E 64 63 68 61 6E 67 69 6E 67 20 74 68 65 20 20    ndchanging the  
0006B0:  49 58 2F 49 59 20 72 65 67 69 73 74 65 72 20 74    IX/IY register t
0006C0:  6F 20 70 6F 69 6E 74 20 74 6F 61 20 64 69 66 66    o point toa diff
0006D0:  65 72 65 6E 74 20 6C 69 6E 65 2E A3 20 54 68 65    erent line.£ The
0006E0:  20 20 6F 6E 6C 79 20 69 6E 73 74 72 75 63 74 69      only instructi
0006F0:  6F 6E 20 20 66 6F 72 20 20 77 68 69 63 68 20 20    on  for  which  
000700:  28 48 4C 29 63 61 6E 6E 6F 74 20 20 62 65 20 20    (HL)cannot  be  
000710:  73 75 62 73 74 69 74 75 74 65 64 20 20 62 79 20    substituted  by 
000720:  20 28 49 58 2B 64 29 20 20 20 6F 72 28 49 59 2B     (IX+d)   or(IY+
000730:  64 29 20 69 73 20 4A 50 20 28 48 4C 29 2E 20 20    d) is JP (HL).  
000740:  4A 50 20 28 49 46 28 58 29 20 61 6E 64 20 20 4A    JP (IF(X) and  J
000750:  50 20 28 49 59 29 61 72 65 20 61 76 61 69 6C 61    P (IY)are availa
000760:  62 6C 65 20 68 6F 77 65 76 65 72 2E A0 A0 20 54    ble however... T
000770:  68 65 20 20 73 75 6D 6D 61 72 79 20 20 20 6C 69    he  summary   li
000780:  73 74 73 20 20 20 61 6C 6C 20 69 6E 73 74 72 75    sts   all instru
000790:  63 74 69 6F 6E 73 61 76 61 69 6C 61 62 6C 65 20    ctionsavailable 
0007A0:  20 75 73 69 6E 67 20 20 74 68 65 20 20 49 58 20     using  the  IX 
0007B0:  72 65 67 69 73 74 65 72 2E 20 54 68 69 73 6C 69    register. Thisli
0007C0:  73 74 20 20 20 63 61 6E 20 20 20 62 65 20 20 72    st   can   be  r
0007D0:  65 70 65 61 74 65 64 20 20 66 6F 72 20 20 74 68    epeated  for  th
0007E0:  65 20 20 20 49 59 72 65 67 69 73 74 65 72 2E A3    e   IYregister.£
0007F0:  20 53 75 6D 6D 61 72 79 20 2D 20 69 6E 64 65 78     Summary - index
000800:  20 72 65 67 69 73 74 65 72 73 A0 A0 4C 44 20 72     registers..LD r
000810:  2C 28 49 58 2B 64 29 20 20 20 4C 44 20 49 58 2C    ,(IX+d)   LD IX,
000820:  6E 6E 20 20 20 20 20 4C 44 20 53 50 2C 49 58 A0    nn     LD SP,IX.
000830:  4C 44 20 28 49 58 2B 64 29 2C 72 20 20 20 4C 44    LD (IX+d),r   LD
000840:  20 49 58 2C 28 6E 6E 19 3A 29 A0 4C 44 20 28 49     IX,(nn.:).LD (I
000850:  58 2B 64 29 2C 6E 20 20 20 4C 44 20 28 6E 6E 29    X+d),n   LD (nn)
000860:  2C 49 58 20 20 20 45 58 20 28 53 50 29 2C 49 58    ,IX   EX (SP),IX
000870:  A0 A0 41 44 44 20 41 2C 28 49 58 2B 64 29 20 20    ..ADD A,(IX+d)  
000880:  49 4E 43 20 28 49 58 2B 64 29 20 20 20 41 4E 44    INC (IX+d)   AND
000890:  20 28 49 58 2B 64 29 A0 41 44 43 20 41 2C 28 49     (IX+d).ADC A,(I
0008A0:  58 2B 64 29 20 20 44 45 43 20 28 49 58 2B 64 29    X+d)  DEC (IX+d)
0008B0:  20 20 20 4F 52 20 28 49 58 2B 64 29 A0 53 55 42       OR (IX+d).SUB
0008C0:  20 28 49 58 2B 64 29 20 20 20 20 20 20 20 20 20     (IX+d)         
0008D0:  20 20 20 20 20 20 20 20 58 4F 52 20 28 49 58 2B            XOR (IX+
0008E0:  64 29 A0 53 42 43 20 41 2C 28 49 58 2B 64 29 20    d).SBC A,(IX+d) 
0008F0:  20 43 50 20 28 49 58 2B 64 29 A0 A0 41 44 44 20     CP (IX+d)..ADD 
000900:  49 58 2C 64 64 20 20 20 20 20 49 4E 43 20 49 58    IX,dd     INC IX
000910:  20 20 20 20 20 20 20 44 45 43 20 49 58 A0 A0 53           DEC IX..S
000920:  4C 41 20 28 49 58 2B 64 29 20 20 20 20 53 52 41    LA (IX+d)    SRA
000930:  20 28 49 58 2B 64 29 20 20 20 53 52 4C 20 28 49     (IX+d)   SRL (I
000940:  58 2B 64 29 A0 52 4C 43 20 4E D4 28 49 58 2B 64    X+d).RLC N.(IX+d
000950:  29 20 20 20 20 52 4C 20 28 49 58 2B 64 29 20 20    )    RL (IX+d)  
000960:  20 20 52 52 43 20 28 49 58 2B 64 29 A0 52 52 20      RRC (IX+d).RR 
000970:  20 28 49 58 2B 64 29 A0 A0 53 45 54 20 4E 20 28     (IX+d)..SET N (
000980:  49 58 2B 64 29 20 20 52 45 53 20 4E 2C 28 49 58    IX+d)  RES N,(IX
000990:  2B 64 29 20 42 49 54 20 4E 2C 28 49 58 2B 64 29    +d) BIT N,(IX+d)
0009A0:  A0 A0 4A 50 20 28 49 58 29 A0 A0 57 69 74 68 20    ..JP (IX)..With 
0009B0:  61 6E 20 69 64 65 6E 74 69 63 61 6C 20 73 65 74    an identical set
0009C0:  20 66 6F 72 20 49 59 A3 20 20 20 20 20 45 58 41     for IY£     EXA
0009D0:  4D 50 4C 45 20 4F 46 20 55 53 45 20 4F 46 20 49    MPLE OF USE OF I
0009E0:  4E 44 45 58 20 52 45 47 49 53 54 45 52 A0 A0 20    NDEX REGISTER.. 
0009F0:  54 68 65 20 65 78 61 6D 70 6C 65 20 20 75 73 65    The example  use
000A00:  73 20 20 74 68 65 20 49 58 20 72 65 67 69 73 74    s  the IX regist
000A10:  65 72 20 61 73 20 61 70 6F 69 6E 74 65 72 20 74    er as apointer t
000A20:  6F 20 61 20 74 61 62 6C 65 20 6F 66 20 74 77 6F    o a table of two
000A30:  20 20 62 79 74 65 20 6E 75 6D 62 65 72 73 2E 45      byte numbers.E
000A40:  61 63 68 20 6E 75 6D 62 65 72 20 5E 08 69 73 20    ach number ^.is 
000A50:  74 6F 20 62 65 20 64 69 76 69 64 65 64 20 62 79    to be divided by
000A60:  20 32 2E A3 20 4C 44 20 42 2C 36 A0 20 20 4C 44     2.£ LD B,6.  LD
000A70:  20 49 58 2C 49 54 45 4D 31 A0 20 4C 4F 4F 50 20     IX,ITEM1. LOOP 
000A80:  20 53 52 4C 20 28 49 58 2B 31 29 A0 20 20 52 52     SRL (IX+1).  RR
000A90:  20 28 49 58 2B 30 29 A0 20 20 49 4E 43 20 49 58     (IX+0).  INC IX
000AA0:  A0 20 20 49 4E 43 20 49 58 A0 20 20 44 4A 4E 5A    .  INC IX.  DJNZ
000AB0:  20 4C 4F 4F 50 A0 20 20 52 45 54 A0 20 20 A0 20     LOOP.  RET.  . 
000AC0:  49 54 45 4D 31 20 44 45 46 57 20 35 36 30 A0 20    ITEM1 DEFW 560. 
000AD0:  20 44 45 46 57 20 31 36 A0 20 20 44 45 46 57 20     DEFW 16.  DEFW 
000AE0:  39 36 33 34 A0 20 20 44 45 46 57 20 31 38 37 A0    9634.  DEFW 187.
000AF0:  20 20 44 45 46 57 20 38 38 34 A0 20 20 44 45 46      DEFW 884.  DEF
000B00:  57 20 35 39 33 37 A0 20 20 A0 20 20 20 20 54 48    W 5937.  .    TH
000B10:  45 20 41 4C 54 45 52 4E 41 54 49 56 45 20 53 45    E ALTERNATIVE SE
000B20:  54 20 4F 46 20 52 45 47 49 53 54 45 52 53 A0 A0    T OF REGISTERS..
000B30:  20 54 68 65 20 20 20 5A 38 30 20 20 20 68 61 73     The   Z80   has
000B40:  20 20 20 77 69 74 68 69 6E 20 20 74 68 8F D8 65       within  th..e
000B50:  20 20 63 68 69 70 20 20 61 6E 61 6C 74 65 72 6E      chip  analtern
000B60:  61 74 69 76 65 20 73 65 74 20 6F 66 20 74 68 65    ative set of the
000B70:  20 70 72 69 6D 61 72 79 20 72 65 67 69 73 74 65     primary registe
000B80:  72 73 41 46 2C 20 42 43 2C 20 44 45 20 20 61 6E    rsAF, BC, DE  an
000B90:  64 20 48 4C 2E 20 20 54 68 65 73 65 20 20 61 72    d HL.  These  ar
000BA0:  65 20 6E 6F 72 6D 61 6C 6C 79 64 65 73 69 67 6E    e normallydesign
000BB0:  61 74 65 64 20 61 73 20 20 41 46 27 2C 20 20 42    ated as  AF',  B
000BC0:  43 27 2C 20 20 44 45 27 20 61 6E 64 20 20 48 4C    C',  DE' and  HL
000BD0:  27 2E 41 6C 74 68 6F 75 67 68 20 20 6E 6F 20 6F    '.Although  no o
000BE0:  70 65 72 61 74 69 6F 6E 73 20 63 61 6E 20 62 65    perations can be
000BF0:  20 70 65 72 66 6F 72 6D 65 64 6F 6E 20 74 68 65     performedon the
000C00:  73 65 20 72 65 67 69 73 74 65 72 73 2C 20 20 74    se registers,  t
000C10:  68 65 79 20 63 61 6E 20 62 65 20 75 73 65 64 20    hey can be used 
000C20:  61 73 61 20 66 61 73 74 20 6D 65 74 68 6F 64 20    asa fast method 
000C30:  6F 66 20 73 74 6F 72 61 67 65 2E A0 A0 A0 20 54    of storage.... T
000C40:  68 65 72 65 20 20 20 61 72 65 20 20 20 6F 6E 2D    here   are   on-
000C50:  EE 6C 79 20 20 20 74 77 6F 20 20 20 69 6E 73 74    .ly   two   inst
000C60:  72 75 63 74 69 6F 6E 73 69 6E 76 6F 6C 76 69 6E    ructionsinvolvin
000C70:  67 20 74 68 65 20 61 6C 74 65 72 6E 61 74 69 76    g the alternativ
000C80:  65 20 72 65 67 69 73 74 65 72 73 2E A0 A0 20 45    e registers... E
000C90:  58 20 41 46 2C 41 46 27 20 20 65 78 63 68 61 6E    X AF,AF'  exchan
000CA0:  67 65 73 20 74 68 65 20 63 6F 6E 74 65 6E 74 73    ges the contents
000CB0:  20 6F 66 20 41 46 20 20 20 20 20 20 20 20 20 20     of AF          
000CC0:  20 20 61 6E 64 20 41 46 27 A0 A0 20 45 58 58 20      and AF'.. EXX 
000CD0:  20 20 20 20 20 20 20 65 78 63 68 61 6E 67 65 73           exchanges
000CE0:  20 42 43 2C 44 45 20 61 6E 64 20 48 4C 2C 20 77     BC,DE and HL, w
000CF0:  69 74 68 20 20 20 20 20 20 20 20 20 20 20 20 42    ith            B
000D00:  43 27 2C 20 44 45 27 20 61 6E 64 20 48 4C 27 20    C', DE' and HL' 
000D10:  72 65 73 70 2E A3 20 20 20 20 45 58 41 4D 50 4C    resp.£    EXAMPL
000D20:  45 20 55 53 49 4E 47 20 54 48 45 20 41 4C 54 45    E USING THE ALTE
000D30:  52 4E 41 54 49 56 45 20 53 45 54 A0 A0 20 54 68    RNATIVE SET.. Th
000D40:  65 20 20 65 78 61 6D 70 6C 65 20 6C 6F 61 64 73    e  example loads
000D50:  20 07 C1 61 6C 6C 20 72 65 67 69 73 74 65 72 73     ..all registers
000D60:  2C 20 20 74 68 65 6E 73 77 6F 70 73 20 20 74 68    ,  thenswops  th
000D70:  65 6D 20 20 77 69 74 68 20 20 74 68 65 20 61 6C    em  with  the al
000D80:  74 65 72 6E 61 74 69 76 65 20 20 73 65 74 2E 48    ternative  set.H
000D90:  61 76 69 6E 67 20 72 65 2D 6C 6F 61 64 65 64 20    aving re-loaded 
000DA0:  74 68 65 20 72 65 67 69 73 74 65 72 73 20 61 20    the registers a 
000DB0:  66 75 72 74 68 65 72 73 77 6F 70 20 72 65 74 75    furtherswop retu
000DC0:  72 6E 73 20 74 68 65 20 6F 72 69 67 69 6E 61 6C    rns the original
000DD0:  20 6E 75 6D 62 65 72 73 2E A3 20 4C 44 20 41 2C     numbers.£ LD A,
000DE0:  33 30 A0 20 20 4C 44 20 42 43 2C 31 30 32 34 A0    30.  LD BC,1024.
000DF0:  20 20 4C 44 20 44 45 2C 38 30 30 30 A0 20 20 4C      LD DE,8000.  L
000E00:  44 20 48 4C 2C 36 34 30 30 30 A0 20 20 45 58 58    D HL,64000.  EXX
000E10:  A0 20 20 45 58 20 41 46 2C 41 46 27 A0 20 20 4C    .  EX AF,AF'.  L
000E20:  44 20 41 2C 36 30 A0 20 20 4C 44 20 42 43 2C 31    D A,60.  LD BC,1
000E30:  32 38 30 A0 20 20 4C 44 20 44 45 2C 32 30 30 A0    280.  LD DE,200.
000E40:  20 20 4C 44 20 48 4C 2C 33 32 31 30 30 A0 20 4C      LD HL,32100. L
000E50:  4F 4F 50 40 CC 20 20 45 58 58 A0 20 20 45 58 20    OOP@.  EXX.  EX 
000E60:  41 46 2C 41 46 27 A0 20 20 44 4A 4E 5A 20 4C 4F    AF,AF'.  DJNZ LO
000E70:  4F 50 A0 20 20 52 45 54 A0 20 20 A0 20 20 A0 20    OP.  RET.  .  . 
000E80:  20 20 20 20 20 20 49 4E 50 55 54 20 41 4E 44 20          INPUT AND 
000E90:  4F 55 54 50 55 54 20 49 4E 53 54 52 55 43 54 49    OUTPUT INSTRUCTI
000EA0:  4F 4E 53 A0 A0 20 53 6F 20 66 61 72 20 77 65 20    ONS.. So far we 
000EB0:  68 61 76 65 20 20 6D 61 6E 69 70 75 6C 61 74 65    have  manipulate
000EC0:  64 20 64 61 74 61 20 77 69 74 68 69 6E 74 68 65    d data withinthe
000ED0:  20 70 72 6F 63 65 73 73 6F 72 20 61 6E 64 20 69     processor and i
000EE0:  74 73 20 61 73 73 6F 63 69 61 74 65 64 20 6D 65    ts associated me
000EF0:  6D 6F 72 79 2E 20 49 66 20 61 20 20 6D 65 6D 6F    mory. If a  memo
000F00:  72 79 20 6C 6F 63 61 74 69 6F 6E 20 69 73 20 75    ry location is u
000F10:  73 65 64 20 20 64 69 72 65 63 74 6C 79 62 79 20    sed  directlyby 
000F20:  20 61 20 20 65 78 74 65 72 6E 61 6C 20 20 64 65     a  external  de
000F30:  76 69 63 65 2C 20 20 74 68 65 20 20 64 65 76 69    vice,  the  devi
000F40:  63 65 20 69 73 74 65 72 6D 65 64 20 20 6D 65 6D    ce istermed  mem
000F50:  6F 72 79 20 61 2C 19 64 64 72 65 73 73 20 6D 61    ory a,.ddress ma
000F60:  70 70 65 64 2E 20 20 54 68 65 20 20 5A 38 30 61    pped.  The  Z80a
000F70:  6C 73 6F 20 73 75 70 70 6F 72 74 73 20 20 32 35    lso supports  25
000F80:  36 20 20 6F 75 74 70 75 74 20 61 6E 64 20 32 35    6  output and 25
000F90:  36 20 69 6E 70 75 74 70 6F 72 74 73 2C 20 6F 72    6 inputports, or
000FA0:  20 20 20 38 20 20 62 69 74 20 69 6E 66 6F 72 6D       8  bit inform
000FB0:  61 74 69 6F 6E 20 20 73 6F 75 72 63 65 73 2C 65    ation  sources,e
000FC0:  78 74 65 72 6E 61 6C 20 74 6F 20 6D 65 6D 6F 72    xternal to memor
000FD0:  79 2E A0 A0 20 57 65 20 20 63 61 6E 20 20 69 6E    y... We  can  in
000FE0:  70 75 74 20 20 64 61 74 61 20 20 64 69 72 65 63    put  data  direc
000FF0:  74 6C 79 20 69 6E 74 6F 20 74 68 65 61 63 63 75    tly into theaccu
001000:  6D 75 6C 61 74 6F 72 20 77 69 74 68 20 49 4E 20    mulator with IN 
001010:  41 2C 28 6E 29 20 77 68 65 72 65 20 6E 20 69 73    A,(n) where n is
001020:  20 74 68 65 6E 75 6D 62 65 72 20 20 6F 66 20 20     thenumber  of  
001030:  74 68 65 20 69 6E 70 75 74 20 70 6F 72 74 20 62    the input port b
001040:  65 74 77 65 65 6E 20 30 20 61 6E 64 32 35 35 2E    etween 0 and255.
001050:  20 20 20 53 69 6D 69 D1 D9 6C 61 72 6C 79 20 77       Simi..larly w
001060:  65 20 63 61 6E 20 6F 75 74 70 75 74 20 64 61 74    e can output dat
001070:  61 20 66 72 6F 6D 74 68 65 20 41 63 63 75 6D 75    a fromthe Accumu
001080:  6C 61 74 6F 72 20 20 74 6F 20 20 70 6F 72 74 20    lator  to  port 
001090:  20 6E 20 20 75 73 69 6E 67 20 20 74 68 65 69 6E     n  using  thein
0010A0:  73 74 72 75 63 74 69 6F 6E 20 20 20 4F 55 54 20    struction   OUT 
0010B0:  28 6E 29 2C 41 2E 20 20 4E 6F 20 20 66 6C 61 67    (n),A.  No  flag
0010C0:  73 20 20 61 72 65 61 66 66 65 63 74 65 64 20 62    s  areaffected b
0010D0:  79 20 74 68 65 73 65 20 69 6E 73 74 72 75 63 74    y these instruct
0010E0:  69 6F 6E 73 A3 20 57 65 20 63 61 6E 20 61 6C 73    ions£ We can als
0010F0:  6F 20 20 69 6E 70 75 74 20 20 64 61 74 61 20 74    o  input  data t
001100:  6F 20 61 6E 79 20 20 38 20 20 62 69 74 72 65 67    o any  8  bitreg
001110:  69 73 74 65 72 20 20 75 73 69 6E 67 20 20 74 68    ister  using  th
001120:  65 20 20 42 20 61 6E 64 20 43 20 72 65 67 69 73    e  B and C regis
001130:  74 65 72 73 2E 54 68 65 20 69 6E 73 74 72 75 63    ters.The instruc
001140:  74 69 6F 6E 20 20 49 4E 20 72 2C 28 43 29 2C 20    tion  IN r,(C), 
001150:  74 72 61 6E 73 6D 69 74 73 70 BE 20 74 68 65 63    transmitsp. thec
001160:  6F 6E 74 65 6E 74 73 20 20 6F 66 20 20 74 68 65    ontents  of  the
001170:  20 42 20 72 65 67 69 73 74 65 72 20 74 6F 20 74     B register to t
001180:  68 65 20 70 6F 72 74 77 68 6F 73 65 20 20 6E 75    he portwhose  nu
001190:  6D 62 65 72 20 20 69 73 20 69 6E 20 74 68 65 20    mber  is in the 
0011A0:  43 20 72 65 67 69 73 74 65 72 2E 20 54 68 65 70    C register. Thep
0011B0:  6F 72 74 20 20 6D 61 79 20 20 20 6F 72 20 20 6D    ort  may   or  m
0011C0:  61 79 20 20 6E 6F 74 20 20 61 63 74 20 20 75 70    ay  not  act  up
0011D0:  6F 6E 20 74 68 69 73 69 6E 66 6F 72 6D 61 74 69    on thisinformati
0011E0:  6F 6E 2E 20 20 54 68 65 20 72 65 74 75 72 6E 65    on.  The returne
0011F0:  64 20 64 61 74 61 20 66 72 6F 6D 20 74 68 65 70    d data from thep
001200:  6F 72 74 20 69 73 20 20 6C 6F 61 64 65 64 20 69    ort is  loaded i
001210:  6E 74 6F 20 72 65 67 69 73 74 65 72 20 72 2E A3    nto register r.£
001220:  20 49 4E 20 72 2C 20 28 43 29 20 20 61 66 66 65     IN r, (C)  affe
001230:  63 74 20 74 68 65 20 20 5A 65 72 6F 2C 20 20 53    ct the  Zero,  S
001240:  69 67 6E 2C 20 61 6E 64 50 61 72 69 74 79 20 66    ign, andParity f
001250:  6C 61 67 73 2E 20 20 54 68 65 20 45 65 69 6E 73    lags.  The Eeins
001260:  74 72 75 63 74 69 6F 6E 20 49 4E 20 46 2C 20 28    truction IN F, (
001270:  43 29 69 73 20 74 68 65 20 6F 6E 6C 79 20 69 6E    C)is the only in
001280:  73 74 72 75 63 74 69 6F 6E 20 74 68 61 74 20 20    struction that  
001290:  64 65 61 6C 73 20 77 69 74 68 74 68 65 20 46 6C    deals withthe Fl
0012A0:  61 67 20 72 65 67 69 73 74 65 72 20 73 65 70 61    ag register sepa
0012B0:  72 61 74 65 6C 79 2E 20 20 4F 6E 6C 79 20 20 74    rately.  Only  t
0012C0:  68 65 66 6C 61 67 73 20 61 72 65 20 61 66 66 65    heflags are affe
0012D0:  63 74 65 64 20 62 79 20 20 74 68 69 73 20 20 69    cted by  this  i
0012E0:  6E 73 74 72 75 63 74 69 6F 6E 61 6E 64 20 20 6E    nstructionand  n
0012F0:  6F 20 20 64 61 74 61 20 20 69 73 20 20 74 72 61    o  data  is  tra
001300:  6E 73 66 65 72 72 65 64 20 20 69 6E 74 6F 20 74    nsferred  into t
001310:  68 65 70 72 6F 63 65 73 73 6F 72 2E A0 A0 20 4F    heprocessor... O
001320:  55 54 20 28 43 29 2C 20 72 20 69 73 20 61 20 20    UT (C), r is a  
001330:  73 69 6D 69 6C 61 72 20 69 6E 73 74 72 75 63 74    similar instruct
001340:  69 6F 6E 20 74 6F 49 4E 20 72 2C 28 43 29 2C 20    ion toIN r,(C), 
001350:  20 62 75 74 20 20 20 74 68 65 20 20 20 2E C9 63     but   the   ..c
001360:  6F 6E 74 65 6E 74 73 20 20 6F 66 20 20 74 68 65    ontents  of  the
001370:  72 65 67 69 73 74 65 72 20 72 20 69 73 20 6C 6F    register r is lo
001380:  61 64 65 64 20 69 6E 74 6F 20 70 6F 72 74 20 28    aded into port (
001390:  43 29 2E A0 A0 20 54 68 65 20 41 4D 53 54 52 41    C)... The AMSTRA
0013A0:  44 20 20 43 50 43 20 34 36 34 20 20 75 73 65 73    D  CPC 464  uses
0013B0:  20 74 68 65 20 49 4E 20 72 2C 28 43 29 61 6E 64     the IN r,(C)and
0013C0:  20 4F 55 54 20 28 43 29 2C 72 20 66 6F 72 6D 73     OUT (C),r forms
0013D0:  20 6F 66 20 49 2F 4F 20 69 6E 73 74 72 75 63 74     of I/O instruct
0013E0:  69 6F 6E 73 2C 62 65 63 61 75 73 65 20 20 6F 66    ions,because  of
0013F0:  20 20 74 68 65 20 20 63 6F 6E 66 69 67 75 72 61      the  configura
001400:  74 69 6F 6E 20 20 6F 66 20 20 74 68 65 69 6E 74    tion  of  theint
001410:  65 72 66 61 63 65 73 20 20 49 2F 4F 20 69 6E 73    erfaces  I/O ins
001420:  74 72 75 63 74 69 6F 6E 73 20 6F 66 20 74 68 65    tructions of the
001430:  20 66 6F 72 6D 49 4E 20 41 2C 28 6E 29 20 6F 72     formIN A,(n) or
001440:  20 20 4F 55 54 20 28 6E 29 2C 41 20 63 61 6E 6E      OUT (n),A cann
001450:  6F 74 20 62 65 20 75 73 65 64 2E A3 20 53 75 21    ot be used.£ Su!
001460:  61 6D 6D 61 72 79 20 2D 20 73 69 6D 70 6C 65 20    ammary - simple 
001470:  69 6E 70 75 74 2F 6F 75 74 70 75 74 A0 A0 49 4E    input/output..IN
001480:  20 41 2C 28 6E 29 20 20 20 20 77 68 65 72 65 20     A,(n)    where 
001490:  6E 20 69 73 20 74 68 65 20 6E 75 6D 62 65 72 20    n is the number 
0014A0:  6F 66 20 74 68 65 20 20 20 20 20 20 20 20 20 20    of the          
0014B0:  20 20 20 20 20 20 20 20 20 20 20 20 69 6E 70 75                inpu
0014C0:  74 20 70 6F 72 74 20 28 30 2D 32 35 35 29 A0 49    t port (0-255).I
0014D0:  4E 20 72 2C 28 43 29 A0 49 4E 20 46 2C 28 6E 29    N r,(C).IN F,(n)
0014E0:  A0 A0 4F 55 54 20 28 6E 29 2C 41 A0 4F 55 54 20    ..OUT (n),A.OUT 
0014F0:  28 43 29 2C 72 A3 20 20 45 58 41 4D 50 4C 45 53    (C),r£  EXAMPLES
001500:  20 4F 46 20 49 4E 50 55 54 2F 4F 55 54 50 55 54     OF INPUT/OUTPUT
001510:  20 49 4E 53 54 52 55 43 54 49 4F 4E 53 A0 A0 20     INSTRUCTIONS.. 
001520:  4F 6E 20 74 68 65 20 41 4D 53 54 52 41 44 20 61    On the AMSTRAD a
001530:  6C 6C 20 75 73 65 66 75 6C 20 49 2F 4F 20 61 64    ll useful I/O ad
001540:  64 72 65 73 73 65 73 61 72 65 20 20 20 20 61 6C    dressesare    al
001550:  6C 6F 63 61 74 65 64 20 20 20 20 74 6F 20 20 20    located    to   
001560:  64 BE 01 72 69 76 65 20 20 20 76 61 72 69 6F 75    d..rive   variou
001570:  73 70 65 72 69 70 68 65 72 61 6C 20 64 65 76 69    speripheral devi
001580:  63 65 73 2C 20 73 75 63 68 20 61 73 20 74 68 65    ces, such as the
001590:  20 50 61 72 61 6C 6C 65 6C 49 6E 70 75 74 2F 4F     ParallelInput/O
0015A0:  75 74 70 75 74 20 20 20 20 63 68 69 70 20 20 20    utput    chip   
0015B0:  28 20 50 49 4F 20 29 20 20 6F 72 20 20 20 43 52    ( PIO )  or   CR
0015C0:  54 43 6F 6E 74 72 6F 6C 6C 65 72 20 20 63 68 69    TController  chi
0015D0:  70 20 20 65 74 63 2E 20 20 54 68 65 20 20 64 72    p  etc.  The  dr
0015E0:  69 76 69 6E 67 20 20 6F 66 74 68 65 73 65 20 63    iving  ofthese c
0015F0:  68 69 70 73 20 69 73 20 6F 75 74 73 69 64 65 20    hips is outside 
001600:  74 68 65 20 73 63 6F 70 65 20 6F 66 20 74 68 69    the scope of thi
001610:  73 54 55 54 4F 52 2E 20 20 20 53 69 6E 63 65 20    sTUTOR.   Since 
001620:  65 72 72 6F 6E 65 6F 75 73 20 6F 75 74 70 75 74    erroneous output
001630:  20 74 6F 20 74 68 65 73 65 64 65 76 69 63 65 73     to thesedevices
001640:  20 63 61 6E 20 72 65 73 75 6C 74 20 69 6E 20 73     can result in s
001650:  79 73 74 65 6D 20 63 72 61 73 68 2C 20 74 68 69    ystem crash, thi
001660:  73 53 49 B9 13 4D 55 4C 41 54 4F 52 20 20 20 63    sSI..MULATOR   c
001670:  61 6E 6E 6F 74 20 20 73 61 66 65 6C 79 20 73 75    annot  safely su
001680:  70 70 6F 72 74 20 6D 65 61 6E 2D 69 6E 67 66 75    pport mean-ingfu
001690:  6C 20 49 2F 4F 20 20 69 6E 73 74 72 75 63 74 69    l I/O  instructi
0016A0:  6F 6E 73 2E 20 20 20 49 66 20 74 68 65 20 70 75    ons.   If the pu
0016B0:  70 69 6C 77 69 73 68 65 73 20 20 74 6F 20 20 70    pilwishes  to  p
0016C0:  72 6F 63 65 65 64 20 20 20 66 75 72 74 68 65 72    roceed   further
0016D0:  20 20 69 6E 20 20 20 74 68 69 73 64 69 72 65 63      in   thisdirec
0016E0:  74 69 6F 6E 2C 20 69 74 20 69 73 20 72 65 63 6F    tion, it is reco
0016F0:  6D 6D 65 6E 64 65 64 20 74 6F 20 72 65 61 64 20    mmended to read 
001700:  74 68 65 43 50 43 34 36 34 20 20 46 49 52 4D 57    theCPC464  FIRMW
001710:  41 52 45 20 20 20 4D 61 6E 75 61 6C 20 20 70 75    ARE   Manual  pu
001720:  62 6C 69 73 68 65 64 20 20 62 79 41 4D 53 4F 46    blished  byAMSOF
001730:  54 2E A3 20 20 20 20 20 20 20 20 20 20 20 42 4C    T.£           BL
001740:  4F 43 4B 20 49 4E 53 54 52 55 43 54 49 4F 4E 53    OCK INSTRUCTIONS
001750:  A0 A0 20 54 68 65 72 65 20 61 72 65 20 66 6F 75    .. There are fou
001760:  72 20 67 72 6F 51 8E 75 70 73 20 6F 66 20 20 66    r groQ.ups of  f
001770:  6F 75 72 20 74 79 70 65 73 20 6F 66 69 6E 73 74    our types ofinst
001780:  72 75 63 74 69 6F 6E 73 20 20 74 68 61 74 20 70    ructions  that p
001790:  65 72 66 6F 72 6D 20 6F 70 65 72 61 74 69 6F 6E    erform operation
0017A0:  73 20 6F 6E 62 6C 6F 63 6B 73 20 20 20 20 6F 66    s onblocks    of
0017B0:  20 20 20 20 6D 65 6D 6F 72 79 2E 20 20 20 20 53        memory.    S
0017C0:  69 6E 63 65 20 20 20 74 68 65 73 65 69 6E 73 74    ince   theseinst
0017D0:  72 75 63 74 69 6F 6E 73 20 68 61 76 65 20 73 69    ructions have si
0017E0:  6D 69 6C 61 72 69 74 69 65 73 2C 20 74 68 65 79    milarities, they
0017F0:  20 61 72 65 69 6E 74 72 6F 64 75 63 65 64 20 74     areintroduced t
001800:  6F 67 65 74 68 65 72 2E A0 A0 20 41 6C 6C 20 62    ogether... All b
001810:  6C 6F 63 6B 20 69 6E 73 74 72 75 63 74 69 6F 6E    lock instruction
001820:  73 20 75 73 65 20 20 72 65 67 69 73 74 65 72 28    s use  register(
001830:  73 29 61 73 20 61 20 70 6F 69 6E 74 65 72 28 73    s)as a pointer(s
001840:  29 20 20 74 6F 20 20 73 63 61 6E 20 74 68 6F 75    )  to  scan thou
001850:  67 68 20 61 20 62 6C 6F 63 6B 6F 66 20 6D 65 6D    gh a blockof mem
001860:  6F 72 79 20 61 6E 64 57 1E 20 61 6E 6F 74 68 65    ory andW. anothe
001870:  72 20 61 73 20 61 20 63 6F 75 6E 74 65 72 2E A0    r as a counter..
001880:  A0 20 41 6C 6C 20 20 62 6C 6F 63 6B 20 20 69 6E    . All  block  in
001890:  73 74 72 75 63 74 69 6F 6E 73 20 20 68 61 76 65    structions  have
0018A0:  20 20 73 69 6D 69 6C 61 72 6D 6E 65 6D 6F 6E 69      similarmnemoni
0018B0:  63 73 2E 20 20 20 20 49 20 20 20 69 6E 64 69 63    cs.    I   indic
0018C0:  61 74 65 73 20 20 20 74 68 61 74 20 20 20 74 68    ates   that   th
0018D0:  65 70 6F 69 6E 74 65 72 28 73 29 20 20 61 72 65    epointer(s)  are
0018E0:  20 20 49 6E 63 72 65 6D 65 6E 74 65 64 2C 20 20      Incremented,  
0018F0:  20 44 20 20 20 74 68 61 74 74 68 65 20 20 70 6F     D   thatthe  po
001900:  69 6E 74 65 72 28 73 29 20 61 72 65 20 20 44 65    inter(s) are  De
001910:  63 72 65 6D 65 6E 74 65 64 2C 20 61 6E 64 20 20    cremented, and  
001920:  52 74 68 61 74 20 20 74 68 65 20 69 6E 73 74 72    Rthat  the instr
001930:  75 63 74 69 6F 6E 20 69 73 20 74 6F 20 62 65 20    uction is to be 
001940:  20 72 65 70 65 61 74 65 64 75 6E 74 69 6C 20 74     repeateduntil t
001950:  68 65 20 63 6F 75 6E 74 65 72 20 69 73 20 7A 65    he counter is ze
001960:  72 6F 2E A3 20 54 68 65 20 DF 25 74 6F 74 61 6C    ro.£ The .%total
001970:  20 6C 69 73 74 20 69 73 A0 A0 20 54 72 61 6E 73     list is.. Trans
001980:  66 65 72 73 20 4C 44 20 2E 2E 2E 2E 2E 4C 44 49    fers LD .....LDI
001990:  2C 4C 44 49 52 2C 4C 44 44 2C 4C 44 44 52 A0 A0    ,LDIR,LDD,LDDR..
0019A0:  20 43 6F 6D 70 61 72 65 20 20 20 43 50 20 2E 2E     Compare   CP ..
0019B0:  2E 2E 2E 43 50 49 2C 43 50 49 52 2C 43 50 44 2C    ...CPI,CPIR,CPD,
0019C0:  43 50 44 52 A0 A0 20 49 6E 70 75 74 20 20 20 20    CPDR.. Input    
0019D0:  20 49 4E 20 2E 2E 2E 2E 2E 49 4E 49 2C 49 4E 49     IN .....INI,INI
0019E0:  52 2C 49 4E 44 2C 49 4E 44 52 A0 A0 20 4F 75 74    R,IND,INDR.. Out
0019F0:  70 75 74 20 20 20 20 4F 55 54 2F 4F 54 2E 2E 4F    put    OUT/OT..O
001A00:  55 54 49 2C 4F 54 44 52 2C 4F 55 54 44 2C 4F 54    UTI,OTDR,OUTD,OT
001A10:  44 52 A0 A0 20 54 68 65 20 20 55 20 20 69 6E 20    DR.. The  U  in 
001A20:  4F 55 54 20 69 73 20 64 72 6F 70 70 65 64 20 20    OUT is dropped  
001A30:  74 6F 20 6B 65 65 70 20 20 74 68 65 6D 6E 65 6D    to keep  themnem
001A40:  6F 6E 69 63 20 74 6F 20 61 20 6D 61 78 69 6D 75    onic to a maximu
001A50:  6D 20 6F 66 20 34 20 6C 65 74 74 65 72 73 2E A3    m of 4 letters.£
001A60:  20 20 20 20 20 20 42 4C 4F 43 4B 0A AC 20 54 52          BLOCK.. TR
001A70:  41 4E 53 46 45 52 20 49 4E 53 54 52 55 43 54 49    ANSFER INSTRUCTI
001A80:  4F 4E 53 A0 A0 20 42 6C 6F 63 6B 20 20 74 72 61    ONS.. Block  tra
001A90:  6E 73 66 65 72 20 20 69 6E 73 74 72 75 63 74 69    nsfer  instructi
001AA0:  6F 6E 73 20 20 74 72 61 6E 73 66 65 72 74 68 65    ons  transferthe
001AB0:  20 20 63 6F 6E 74 65 6E 74 73 20 20 6F 66 20 20      contents  of  
001AC0:  61 6E 20 61 72 65 61 20 20 6F 66 20 6D 65 6D 6F    an area  of memo
001AD0:  72 79 20 74 6F 61 6E 6F 74 68 65 72 20 61 72 65    ry toanother are
001AE0:  61 2E 20 54 77 6F 20 70 6F 69 6E 74 65 72 73 20    a. Two pointers 
001AF0:  61 72 65 20 75 73 65 64 2E 20 54 68 65 48 4C 20    are used. TheHL 
001B00:  72 65 67 69 73 74 65 72 20 68 6F 6C 64 73 20 74    register holds t
001B10:  68 65 20 73 6F 75 72 63 65 20 61 64 64 72 65 73    he source addres
001B20:  73 20 61 6E 64 74 68 65 20 44 45 20 72 65 67 69    s andthe DE regi
001B30:  73 74 65 72 20 74 68 65 20 64 65 73 74 69 6E 61    ster the destina
001B40:  74 69 6F 6E 20 61 64 64 72 65 73 73 2E 54 68 65    tion address.The
001B50:  20 73 69 7A 65 20 6F 66 20 74 68 65 20 62 6C 6F     size of the blo
001B60:  63 6B 20 74 6F 20 62 65 20 20 74 72 61 6F 69 6E    ck to be  traoin
001B70:  73 66 65 72 72 65 64 69 73 20 68 65 6C 64 20 69    sferredis held i
001B80:  6E 20 74 68 65 20 42 43 20 72 65 67 69 73 74 65    n the BC registe
001B90:  72 2E A3 20 4C 44 49 20 20 74 72 61 6E 73 66 65    r.£ LDI  transfe
001BA0:  72 73 20 28 48 4C 29 20 74 6F 20 28 44 45 29 2C    rs (HL) to (DE),
001BB0:  20 69 6E 63 72 65 6D 65 6E 74 73 62 6F 74 68 20     incrementsboth 
001BC0:  20 70 6F 69 6E 74 65 72 73 2C 20 20 61 6E 64 20     pointers,  and 
001BD0:  20 64 65 63 72 65 6D 65 6E 74 73 20 42 43 2E 20     decrements BC. 
001BE0:  20 49 66 42 43 3D 30 20 74 68 65 20 50 2F 56 20     IfBC=0 the P/V 
001BF0:  66 6C 61 67 20 69 73 20 30 20 20 28 69 2E 65 2E    flag is 0  (i.e.
001C00:  20 65 71 75 69 76 61 6C 65 6E 74 74 6F 20 70 61     equivalentto pa
001C10:  72 69 74 79 20 62 65 69 6E 67 20 6F 64 64 20 29    rity being odd )
001C20:  2E 20 49 66 20 20 42 43 20 20 64 6F 65 73 20 20    . If  BC  does  
001C30:  6E 6F 74 65 71 75 61 6C 20 30 20 74 68 65 20 50    notequal 0 the P
001C40:  2F 56 20 66 6C 61 67 20 69 73 20 31 20 28 70 61    /V flag is 1 (pa
001C50:  72 69 74 79 20 65 76 65 6E 29 2E 4C 44 49 20 74    rity even).LDI t
001C60:  68 65 72 65 66 6F 72 65 20 70 65 72 66 6F 72 AB    herefore perfor.
001C70:  DA 6D 73 20 6F 6E 6C 79 20 20 6F 6E 65 20 73 74    .ms only  one st
001C80:  65 70 20 6F 66 74 68 65 20 74 72 61 6E 73 66 65    ep ofthe transfe
001C90:  72 20 20 20 6F 66 20 20 74 68 65 20 20 62 6C 6F    r   of  the  blo
001CA0:  63 6B 2C 20 20 61 6C 6C 6F 77 69 6E 67 69 6E 74    ck,  allowingint
001CB0:  65 72 6D 65 64 69 61 74 65 20 20 6F 70 65 72 61    ermediate  opera
001CC0:  74 69 6F 6E 73 20 74 6F 20 62 65 20 70 65 72 66    tions to be perf
001CD0:  6F 72 6D 65 64 62 65 66 6F 72 65 20 74 68 65 20    ormedbefore the 
001CE0:  69 6E 73 74 72 75 63 74 69 6F 6E 20 69 73 20 72    instruction is r
001CF0:  65 70 65 61 74 65 64 2E A0 A0 20 4C 44 49 52 20    epeated... LDIR 
001D00:  20 69 73 20 73 69 6D 69 6C 61 72 20 74 6F 20 20     is similar to  
001D10:  4C 44 49 2C 20 20 74 72 61 6E 73 66 65 72 72 69    LDI,  transferri
001D20:  6E 67 64 61 74 61 20 66 72 6F 6D 20 28 48 4C 29    ngdata from (HL)
001D30:  20 74 6F 20 28 44 45 29 20 61 6E 64 20 20 69 6E     to (DE) and  in
001D40:  63 72 65 6D 65 6E 74 69 6E 67 74 68 65 20 70 6F    crementingthe po
001D50:  69 6E 74 65 72 73 2C 20 20 20 62 75 74 20 20 20    inters,   but   
001D60:  74 68 69 73 20 20 20 69 6E 73 74 72 75 63 74 69    this   instructi
001D70:  6F 18 62 6E 61 75 74 6F 6D 61 74 69 63 61 6C 6C    o.bnautomaticall
001D80:  79 20 20 20 72 65 70 65 61 74 73 20 20 20 74 68    y   repeats   th
001D90:  65 20 20 6F 70 65 72 61 74 69 6F 6E 75 6E 74 69    e  operationunti
001DA0:  6C 20 20 42 43 3D 30 20 20 20 61 6E 64 20 20 74    l  BC=0   and  t
001DB0:  68 65 20 20 77 68 6F 6C 65 20 20 62 6C 6F 63 6B    he  whole  block
001DC0:  20 20 69 73 74 72 61 6E 73 66 65 72 72 65 64 2E      istransferred.
001DD0:  A3 20 4C 44 44 20 20 69 73 20 73 69 6D 69 6C 61    £ LDD  is simila
001DE0:  72 20 74 6F 20 20 4C 44 49 20 65 78 63 65 70 74    r to  LDI except
001DF0:  20 74 68 61 74 20 74 68 65 70 6F 69 6E 74 65 72     that thepointer
001E00:  73 20 61 72 65 20 44 65 63 72 65 6D 65 6E 74 65    s are Decremente
001E10:  64 2E 20 54 68 75 73 20 48 4C 20 61 6E 64 20 44    d. Thus HL and D
001E20:  45 73 74 61 72 74 20 20 61 74 20 20 74 68 65 20    Estart  at  the 
001E30:  20 74 6F 70 20 20 6F 66 20 20 74 68 65 20 20 72     top  of  the  r
001E40:  65 73 70 65 63 74 69 76 65 62 6C 6F 63 6B 73 20    espectiveblocks 
001E50:  6F 66 20 6D 65 6D 6F 72 79 2E A0 A0 20 4C 44 44    of memory... LDD
001E60:  52 20 20 52 65 70 65 61 74 73 20 20 4C 44 44 20    R  Repeats  LDD 
001E70:  75 6E 74 44 03 69 6C 20 42 43 3D 30 20 61 73 20    untD.il BC=0 as 
001E80:  69 6E 20 74 68 65 4C 44 49 52 20 69 6E 73 74 72    in theLDIR instr
001E90:  75 63 74 69 6F 6E 2E A0 A0 20 42 6F 74 68 20 20    uction... Both  
001EA0:  70 61 69 72 73 20 20 6F 66 20 69 6E 73 74 72 75    pairs  of instru
001EB0:  63 74 69 6F 6E 73 20 20 28 4C 44 49 52 20 61 6E    ctions  (LDIR an
001EC0:  64 4C 44 44 52 29 20 20 61 72 65 20 20 72 65 71    dLDDR)  are  req
001ED0:  75 69 72 65 64 2E A0 A0 20 54 61 6B 65 20 74 68    uired... Take th
001EE0:  65 20 65 78 61 6D 70 6C 65 20 6F 66 20 61 6E 20    e example of an 
001EF0:  4C 44 49 52 20 69 6E 73 74 72 75 63 74 69 6F 6E    LDIR instruction
001F00:  77 69 74 68 20 74 68 65 20 72 65 67 69 73 74 65    with the registe
001F10:  72 73 20 69 6E 69 74 69 61 6C 6C 79 20 73 65 74    rs initially set
001F20:  20 74 6F 3A 2D A0 48 4C 20 3D 20 31 30 30 30 20     to:-.HL = 1000 
001F30:  20 44 45 20 3D 20 31 35 30 30 20 20 61 6E 64 20     DE = 1500  and 
001F40:  20 42 43 20 3D 20 31 30 30 30 2E A0 54 68 65 20     BC = 1000..The 
001F50:  20 20 69 6E 73 74 72 75 63 74 69 6F 6E 20 20 73      instruction  s
001F60:  68 6F 75 6C 64 20 20 74 72 61 6E 73 66 65 72 20    hould  transfer 
001F70:  20 74 68 65 63 84 BB 6F 6E 74 65 6E 74 73 20 6F     thec..ontents o
001F80:  66 20 74 68 65 20 20 62 6C 6F 63 6B 20 6F 66 20    f the  block of 
001F90:  20 6D 65 6D 6F 72 79 20 20 31 30 30 30 2D 32 30     memory  1000-20
001FA0:  30 30 20 20 20 74 6F 20 20 6D 65 6D 6F 72 79 20    00   to  memory 
001FB0:  20 6C 6F 63 61 74 69 6F 6E 73 20 20 31 35 30 30     locations  1500
001FC0:  2D 32 35 30 30 2E 55 6E 66 6F 72 74 75 6E 61 74    -2500.Unfortunat
001FD0:  65 6C 79 20 20 74 68 65 20 66 69 72 73 74 20 73    ely  the first s
001FE0:  74 65 70 20 20 74 72 61 6E 73 66 65 72 73 74 68    tep  transfersth
001FF0:  65 20 20 63 6F 6E 74 65 6E 74 73 20 20 6F 66 20    e  contents  of 
002000:  20 31 30 30 30 20 74 6F 20 31 35 30 30 2E 20 20     1000 to 1500.  
002010:  42 79 20 74 68 65 74 69 6D 65 20 69 74 20 69 73    By thetime it is
002020:  20 74 68 65 20 74 75 72 6E 20 6F 66 20 6C 6F 63     the turn of loc
002030:  61 74 69 6F 6E 20 20 31 35 30 30 20 74 6F 62 65    ation  1500 tobe
002040:  20 74 72 61 6E 73 66 65 72 72 65 64 20 20 20 20     transferred    
002050:  69 74 20 20 68 61 73 20 20 61 6C 72 65 61 64 79    it  has  already
002060:  20 20 62 65 65 6E 6F 76 65 72 77 72 69 74 74 65      beenoverwritte
002070:  6E 20 69 6E 20 74 68 33 F7 65 20 66 69 72 73 74    n in th3.e first
002080:  20 73 74 65 70 2E A3 20 54 61 6B 69 6E 67 20 74     step.£ Taking t
002090:  68 65 20 69 6E 69 74 69 61 6C 20 63 6F 6E 64 69    he initial condi
0020A0:  74 69 6F 6E 73 20 3A 2D A0 48 4C 20 3D 31 39 39    tions :-.HL =199
0020B0:  39 20 20 20 44 45 20 3D 20 32 34 39 39 20 61 6E    9   DE = 2499 an
0020C0:  64 20 20 42 43 20 3D 20 31 30 30 30 20 20 61 6E    d  BC = 1000  an
0020D0:  64 75 73 69 6E 67 20 20 74 68 65 20 20 4C 44 44    dusing  the  LDD
0020E0:  52 20 20 69 6E 73 74 72 75 63 74 69 6F 6E 2C 20    R  instruction, 
0020F0:  20 74 68 65 20 73 61 6D 65 62 6C 6F 63 6B 20 77     the sameblock w
002100:  69 6C 6C 20 20 62 65 20 20 74 72 61 6E 73 66 65    ill  be  transfe
002110:  72 72 65 64 20 20 74 6F 20 74 68 65 20 73 61 6D    rred  to the sam
002120:  65 6D 65 6D 6F 72 79 20 6C 6F 63 61 74 69 6F 6E    ememory location
002130:  73 20 77 69 74 68 6F 75 74 20 74 68 69 73 20 70    s without this p
002140:  72 6F 62 6C 65 6D 2E A0 A0 20 49 6E 20 20 67 65    roblem... In  ge
002150:  6E 65 72 61 6C 2C 20 20 69 66 20 74 68 65 20 74    neral,  if the t
002160:  77 6F 20 62 6C 6F 63 6B 73 20 6F 76 65 72 6C 61    wo blocks overla
002170:  70 75 73 65 20 74 68 65 20 03 BD 20 69 6E 73 74    puse the .. inst
002180:  72 75 63 74 69 6F 6E 20 20 74 68 61 74 20 20 65    ruction  that  e
002190:  6E 73 75 72 65 73 20 20 74 68 65 69 6E 69 74 69    nsures  theiniti
0021A0:  61 6C 20 20 66 69 67 75 72 65 20 69 6E 20 74 68    al  figure in th
0021B0:  65 20 20 48 4C 20 72 65 67 69 73 74 65 72 20 6C    e  HL register l
0021C0:  69 65 73 77 69 74 68 69 6E 20 74 68 65 20 20 62    ieswithin the  b
0021D0:  6C 6F 63 6B 20 74 6F 20 77 68 69 63 68 20 64 61    lock to which da
0021E0:  74 61 20 69 73 20 74 6F 20 62 65 74 72 61 6E 73    ta is to betrans
0021F0:  66 65 72 72 65 64 2E A3 20 53 75 6D 6D 61 72 79    ferred.£ Summary
002200:  20 2D 20 62 6C 6F 63 6B 20 74 72 61 6E 73 66 65     - block transfe
002210:  72 A0 A0 4C 44 49 20 20 20 20 20 70 6F 69 6E 74    r..LDI     point
002220:  65 72 20 69 6E 63 72 65 6D 65 6E 74 65 64 A0 A0    er incremented..
002230:  4C 44 49 52 20 20 20 20 70 6F 69 6E 74 65 72 20    LDIR    pointer 
002240:  69 6E 63 72 65 6D 65 6E 74 65 64 20 61 6E 64 20    incremented and 
002250:  72 65 70 65 61 74 65 64 20 20 20 20 20 20 20 20    repeated        
002260:  75 6E 74 69 6C 20 6E 75 6D 62 65 72 20 66 6F 75    until number fou
002270:  6E 64 20 6F 72 20 42 43 3D 30 A0 AE FD A0 4C 44    nd or BC=0....LD
002280:  44 20 20 20 20 20 70 6F 69 6E 74 65 72 20 64 65    D     pointer de
002290:  63 72 65 6D 65 6E 74 65 64 A0 A0 4C 44 44 52 20    cremented..LDDR 
0022A0:  20 20 20 70 6F 69 6E 74 65 72 20 64 65 63 72 65       pointer decre
0022B0:  6D 65 6E 74 65 64 20 61 6E 64 20 72 65 70 65 61    mented and repea
0022C0:  74 65 64 20 20 20 20 20 20 20 20 75 6E 74 69 6C    ted        until
0022D0:  20 6E 75 6D 62 65 72 20 66 6F 75 6E 64 20 6F 72     number found or
0022E0:  20 42 43 3D 30 A3 20 20 20 20 20 20 20 45 58 41     BC=0£       EXA
0022F0:  4D 50 4C 45 20 4F 46 20 42 4C 4F 43 4B 20 54 52    MPLE OF BLOCK TR
002300:  41 4E 53 46 45 52 A0 A0 20 54 68 65 20 65 78 61    ANSFER.. The exa
002310:  6D 70 6C 65 20 75 73 65 73 20 74 68 65 20 20 4C    mple uses the  L
002320:  44 49 52 20 20 69 6E 73 74 72 75 63 74 69 6F 6E    DIR  instruction
002330:  74 6F 20 20 74 72 61 6E 73 66 65 72 20 20 74 68    to  transfer  th
002340:  65 20 20 70 72 6F 67 72 61 6D 20 20 20 64 6F 77    e  program   dow
002350:  6E 20 20 74 6F 20 20 61 6D 65 6D 6F 72 79 20 61    n  to  amemory a
002360:  72 65 61 2E A0 A0 20 54 68 65 20 70 6F 77 65 72    rea... The power
002370:  20 6F 66 20 74 68 65 73 65 20 69 6E 73 56 75 74     of these insVut
002380:  72 75 63 74 69 6F 6E 73 20 69 73 20 77 65 6C 6C    ructions is well
002390:  69 6C 6C 75 73 74 72 61 74 65 64 20 62 79 20 74    illustrated by t
0023A0:  68 65 20 73 69 6D 70 6C 65 20 6F 70 65 72 61 74    he simple operat
0023B0:  69 6F 6E 2E A0 A0 20 54 68 65 73 65 20 69 6E 73    ion... These ins
0023C0:  74 72 75 63 74 69 6F 6E 73 20 63 61 6E 20 20 62    tructions can  b
0023D0:  65 20 75 73 65 64 20 61 6C 73 6F 20 74 6F 66 69    e used also tofi
0023E0:  6C 6C 20 20 61 20 20 62 6C 6F 63 6B 20 20 6F 66    ll  a  block  of
0023F0:  20 20 6D 65 6D 6F 72 79 20 77 69 74 68 20 61 20      memory with a 
002400:  73 69 6E 67 6C 65 6E 75 6D 62 65 72 2E A3 20 4C    singlenumber.£ L
002410:  44 20 48 4C 2C 46 30 30 48 A0 20 20 4C 44 20 44    D HL,F00H.  LD D
002420:  45 2C 53 54 31 A0 20 20 4C 44 20 42 43 2C 42 48    E,ST1.  LD BC,BH
002430:  A0 20 20 4C 44 49 52 A0 20 20 52 45 54 A0 20 53    .  LDIR.  RET. S
002440:  54 31 20 20 20 44 45 46 42 20 30 A0 20 20 44 45    T1   DEFB 0.  DE
002450:  46 42 20 30 A0 20 20 44 45 46 42 20 30 A0 20 20    FB 0.  DEFB 0.  
002460:  44 45 46 42 20 30 A0 20 20 44 45 46 42 20 30 A0    DEFB 0.  DEFB 0.
002470:  20 20 44 45 46 42 20 30 A0 20 20 44 45 46 42 BE      DEFB 0.  DEFB.
002480:  15 20 30 A0 20 20 44 45 46 42 20 30 A0 20 20 44    . 0.  DEFB 0.  D
002490:  45 46 42 20 30 A0 20 20 44 45 46 42 20 30 A0 20    EFB 0.  DEFB 0. 
0024A0:  20 44 45 46 42 20 30 A0 20 20 20 20 20 20 20 20     DEFB 0.        
0024B0:  20 20 20 20 20 20 20 42 4C 4F 43 4B 20 53 45 41           BLOCK SEA
0024C0:  52 43 48 A0 A0 20 41 73 20 79 6F 75 20 6D 61 79    RCH.. As you may
0024D0:  20 6E 6F 77 20 62 65 20 61 62 6C 65 20 74 6F 20     now be able to 
0024E0:  69 6E 66 65 72 2C 20 74 68 65 20 43 50 67 72 6F    infer, the CPgro
0024F0:  75 70 20 20 43 6F 6D 70 61 72 65 73 20 20 74 68    up  Compares  th
002500:  65 20 63 6F 6E 74 65 6E 74 20 20 6F 66 20 20 6D    e content  of  m
002510:  65 6D 6F 72 79 6C 6F 63 61 74 69 6F 6E 73 20 69    emorylocations i
002520:  6E 20 61 20 20 62 6C 6F 63 6B 20 6F 66 20 20 6D    n a  block of  m
002530:  65 6D 6F 72 79 20 20 77 69 74 68 20 61 70 72 65    emory  with apre
002540:  64 65 74 65 72 6D 69 6E 65 64 20 20 20 6E 75 6D    determined   num
002550:  62 65 72 2E 20 20 20 48 4C 20 20 68 6F 6C 64 73    ber.   HL  holds
002560:  20 20 74 68 65 70 6F 69 6E 74 65 72 20 61 6E 64      thepointer and
002570:  20 20 74 68 65 20 20 42 43 20 72 65 67 69 73 74      the  BC regist
002580:  65 F8 1D 72 20 74 68 65 20 6C 65 6E 67 74 68 6F    e..r the lengtho
002590:  66 20 20 74 68 65 20 20 20 62 6C 6F 63 6B 20 20    f  the   block  
0025A0:  74 6F 20 20 62 65 20 20 73 65 61 72 63 68 65 64    to  be  searched
0025B0:  2E 20 20 20 54 68 65 41 63 63 75 6D 75 6C 61 74    .   TheAccumulat
0025C0:  6F 72 20 20 68 6F 6C 64 73 20 74 68 65 20 6E 75    or  holds the nu
0025D0:  6D 62 65 72 20 66 6F 72 20 20 77 68 69 63 68 74    mber for  whicht
0025E0:  68 65 20 20 69 6E 73 74 72 75 63 74 69 6F 6E 20    he  instruction 
0025F0:  20 77 69 6C 6C 20 20 73 65 61 72 63 68 2E 20 20     will  search.  
002600:  49 66 20 20 74 68 65 6E 75 6D 62 65 72 20 20 69    If  thenumber  i
002610:  73 20 20 66 6F 75 6E 64 20 20 74 68 65 6E 20 74    s  found  then t
002620:  68 65 20 5A 65 72 6F 20 66 6C 61 67 20 69 73 73    he Zero flag iss
002630:  65 74 2E 20 20 41 73 20 20 62 65 66 6F 72 65 20    et.  As  before 
002640:  20 74 68 65 20 50 2F 56 20 66 6C 61 67 20 69 6E     the P/V flag in
002650:  64 69 63 61 74 65 73 77 68 65 74 68 65 72 20 42    dicateswhether B
002660:  43 3D 30 2E A0 A0 20 54 68 65 20 20 62 6C 6F 63    C=0... The  bloc
002670:  6B 20 69 6E 73 74 72 75 63 74 69 6F 6E 73 20 73    k instructions s
002680:  74 6F 70 BF 76 2C 20 6E 6F 74 20 20 77 69 74 68    top.v, not  with
002690:  74 68 65 20 70 6F 69 6E 74 65 72 28 73 29 20 70    the pointer(s) p
0026A0:  6F 69 6E 74 69 6E 67 20 61 74 20 74 68 65 20 61    ointing at the a
0026B0:  64 64 72 65 73 73 65 73 6A 75 73 74 20 6F 70 65    ddressesjust ope
0026C0:  72 61 74 65 64 20 6F 6E 2C 20 20 62 75 74 20 74    rated on,  but t
0026D0:  6F 20 74 68 6F 73 65 20 61 62 6F 75 74 20 74 6F    o those about to
0026E0:  62 65 20 70 72 6F 63 65 73 73 65 64 2E 20 48 65    be processed. He
0026F0:  6E 63 65 20 69 66 20 65 71 75 61 6C 69 74 79 20    nce if equality 
002700:  69 73 20 66 6F 75 6E 64 74 68 65 79 20 20 70 6F    is foundthey  po
002710:  69 6E 74 20 74 6F 20 74 68 65 20 20 6E 65 78 74    int to the  next
002720:  20 61 64 64 72 65 73 73 20 61 6E 64 20 6E 6F 74     address and not
002730:  74 68 65 20 20 6D 65 6D 6F 72 79 20 20 6C 6F 63    the  memory  loc
002740:  61 74 69 6F 6E 20 20 69 6E 20 20 77 68 69 63 68    ation  in  which
002750:  20 20 69 74 20 77 61 73 66 6F 75 6E 64 2E A3 20      it wasfound.£ 
002760:  53 75 6D 6D 61 72 79 20 2D 20 62 6C 6F 63 6B 20    Summary - block 
002770:  73 65 61 72 63 68 A0 A0 43 50 49 20 20 20 20 20    search..CPI     
002780:  70 6F 69 6E 74 EF 5C 65 72 20 69 6E 63 72 65 6D    point.\er increm
002790:  65 6E 74 65 64 A0 A0 43 50 49 52 20 20 20 20 70    ented..CPIR    p
0027A0:  6F 69 6E 74 65 72 20 69 6E 63 72 65 6D 65 6E 74    ointer increment
0027B0:  65 64 20 61 6E 64 20 72 65 70 65 61 74 65 64 20    ed and repeated 
0027C0:  20 20 20 20 20 20 20 75 6E 74 69 6C 20 6E 75 6D           until num
0027D0:  62 65 72 20 66 6F 75 6E 64 20 6F 72 20 42 43 3D    ber found or BC=
0027E0:  30 A0 A0 43 50 44 20 20 20 20 20 70 6F 69 6E 74    0..CPD     point
0027F0:  65 72 20 64 65 63 72 65 6D 65 6E 74 65 64 A0 A0    er decremented..
002800:  43 50 44 52 20 20 20 20 70 6F 69 6E 74 65 72 20    CPDR    pointer 
002810:  64 65 63 72 65 6D 65 6E 74 65 64 20 61 6E 64 20    decremented and 
002820:  72 65 70 65 61 74 65 64 20 20 20 20 20 20 20 20    repeated        
002830:  75 6E 74 69 6C 20 6E 75 6D 62 65 72 20 66 6F 75    until number fou
002840:  6E 64 20 6F 72 20 42 43 3D 30 A3 20 20 20 20 20    nd or BC=0£     
002850:  20 20 45 58 41 4D 50 4C 45 20 4F 46 20 42 4C 4F      EXAMPLE OF BLO
002860:  43 4B 20 53 45 41 52 43 48 A0 A0 20 49 6E 20 74    CK SEARCH.. In t
002870:  68 69 73 20 65 78 61 6D 70 6C 65 20 74 68 65 20    his example the 
002880:  20 70 72 6F 67 72 61 A9 88 6D 20 69 74 73 65 6C     progra..m itsel
002890:  66 20 20 69 73 73 65 61 72 63 68 65 64 20 74 68    f  issearched th
0028A0:  72 6F 75 67 68 20 75 6E 74 69 6C 20 74 68 65 20    rough until the 
0028B0:  6E 75 6D 62 65 72 20 43 39 48 20 69 73 66 6F 75    number C9H isfou
0028C0:  6E 64 20 28 43 39 48 20 63 6F 72 72 65 73 70 6F    nd (C9H correspo
0028D0:  6E 64 73 20 74 6F 20 52 45 54 29 A3 20 4C 44 20    nds to RET)£ LD 
0028E0:  41 2C 43 39 48 A0 20 53 54 41 52 54 20 4C 44 20    A,C9H. START LD 
0028F0:  42 43 2C 31 30 30 A0 20 20 4C 44 20 48 4C 2C 53    BC,100.  LD HL,S
002900:  54 41 52 54 A0 20 20 43 50 49 52 A0 20 20 44 45    TART.  CPIR.  DE
002910:  43 20 48 4C A0 20 20 4C 44 20 41 2C 46 46 48 A0    C HL.  LD A,FFH.
002920:  20 20 43 50 49 52 A0 20 20 44 45 43 20 48 4C A0      CPIR.  DEC HL.
002930:  20 20 4C 44 20 41 2C 28 48 4C 29 A0 20 20 52 45      LD A,(HL).  RE
002940:  54 A0 20 20 A0 20 20 44 45 46 42 20 36 48 A0 20    T.  .  DEFB 6H. 
002950:  20 44 45 46 42 20 30 48 A0 20 20 44 45 46 42 20     DEFB 0H.  DEFB 
002960:  46 46 48 A0 20 20 44 45 46 42 20 38 38 48 A0 20    FFH.  DEFB 88H. 
002970:  20 A0 20 20 20 20 20 42 4C 4F 43 4B 20 49 4E 50     .     BLOCK INP
002980:  55 54 2F 4F 55 54 50 55 54 2C 67 20 49 4E 53 54    UT/OUTPUT,g INST
002990:  52 55 43 54 49 4F 4E 53 A0 A0 20 54 68 65 20 20    RUCTIONS.. The  
0029A0:  49 4E 20 20 20 67 72 6F 75 70 20 20 6F 66 20 20    IN   group  of  
0029B0:  62 6C 6F 63 6B 20 69 6E 73 74 72 75 63 74 69 6F    block instructio
0029C0:  6E 73 69 6E 70 75 74 20 64 61 74 61 20 66 72 6F    nsinput data fro
0029D0:  6D 20 74 68 65 20 69 6E 70 75 74 20 70 6F 72 74    m the input port
0029E0:  20 73 70 65 63 69 66 69 65 64 62 79 20 74 68 65     specifiedby the
0029F0:  20 20 63 6F 6E 74 65 6E 74 73 20 6F 66 20 74 68      contents of th
002A00:  65 20 43 20 20 72 65 67 69 73 74 65 72 20 69 6E    e C  register in
002A10:  74 6F 61 20 20 62 6C 6F 63 6B 20 20 6F 66 20 20    toa  block  of  
002A20:  20 6D 65 6D 6F 72 79 20 20 73 74 61 72 74 69 6E     memory  startin
002A30:  67 20 20 61 74 20 20 74 68 65 61 64 64 72 65 73    g  at  theaddres
002A40:  73 20 20 68 65 6C 64 20 20 69 6E 20 20 74 68 65    s  held  in  the
002A50:  20 20 48 4C 20 72 65 67 69 73 74 65 72 2C 20 74      HL register, t
002A60:  68 65 6C 65 6E 67 74 68 20 20 6F 66 20 20 77 68    helength  of  wh
002A70:  69 63 68 20 20 69 73 20 69 6E 20 74 68 65 20 42    ich  is in the B
002A80:  20 72 65 67 69 73 74 65 72 2E 41 FB 04 6C 6C 20     register.A..ll 
002A90:  66 6F 72 6D 73 20 6F 66 20 49 4E 20 61 70 70 6C    forms of IN appl
002AA0:  79 3A 2D A0 A0 20 69 2E 65 2E 20 20 49 4E 49 20    y:-.. i.e.  INI 
002AB0:  69 6E 63 72 65 6D 65 6E 74 69 6E 67 20 A0 20 20    incrementing .  
002AC0:  20 20 20 20 20 49 4E 49 52 20 69 6E 63 72 65 6D         INIR increm
002AD0:  65 6E 74 69 6E 67 20 61 6E 64 20 72 65 70 65 61    enting and repea
002AE0:  74 69 6E 67 A0 A0 20 20 20 20 20 20 20 49 4E 44    ting..       IND
002AF0:  20 20 64 65 63 72 65 6D 65 6E 74 69 6E 67 A0 20      decrementing. 
002B00:  20 20 20 20 20 20 49 4E 44 52 20 64 65 63 72 65          INDR decre
002B10:  6D 65 6E 74 69 6E 67 20 61 6E 64 20 72 65 70 65    menting and repe
002B20:  61 74 69 6E 67 A3 20 54 68 65 20 20 4F 55 54 20    ating£ The  OUT 
002B30:  20 20 67 72 6F 75 70 20 69 73 20 69 64 65 6E 74      group is ident
002B40:  69 63 61 6C 20 74 6F 20 74 68 65 20 49 4E 67 72    ical to the INgr
002B50:  6F 75 70 2C 20 62 75 74 20 64 61 74 61 20 66 72    oup, but data fr
002B60:  6F 6D 20 6D 65 6D 6F 72 79 20 69 73 20 6F 75 74    om memory is out
002B70:  70 75 74 20 74 6F 70 6F 72 74 20 20 20 28 43 29    put toport   (C)
002B80:  20 20 69 6E 20 20 73 65 71 75 65 6E 63 A5 13 65      in  sequenc..e
002B90:  20 20 20 66 72 6F 6D 20 20 20 6D 65 6D 6F 72 79       from   memory
002BA0:  62 65 67 69 6E 6E 69 6E 67 20 61 74 20 6C 6F 63    beginning at loc
002BB0:  61 74 69 6F 6E 20 28 48 4C 29 A0 A0 20 54 68 65    ation (HL).. The
002BC0:  20 20 42 20 72 65 67 69 73 74 65 72 20 69 73 20      B register is 
002BD0:  75 73 65 64 20 61 73 20 61 20 63 6F 75 6E 74 65    used as a counte
002BE0:  72 20 61 73 74 68 65 20 49 4E 20 67 72 6F 75 70    r asthe IN group
002BF0:  2E A0 A0 20 4F 55 54 49 20 20 20 20 20 69 6E 63    ... OUTI     inc
002C00:  72 65 6D 65 6E 74 69 6E 67 A0 20 4F 54 49 52 20    rementing. OTIR 
002C10:  20 20 20 20 69 6E 63 72 65 6D 65 6E 74 69 6E 67        incrementing
002C20:  20 61 6E 64 20 72 65 70 65 61 74 69 6E 67 A0 A0     and repeating..
002C30:  20 4F 55 54 44 20 20 20 20 20 64 65 63 72 65 6D     OUTD     decrem
002C40:  65 6E 74 69 6E 67 A0 20 4F 54 44 52 20 20 20 20    enting. OTDR    
002C50:  20 64 65 63 72 65 6D 65 6E 74 69 6E 67 20 61 6E     decrementing an
002C60:  64 20 72 65 70 65 61 74 69 6E 67 A0 A0 20 54 68    d repeating.. Th
002C70:  65 20 20 5A 65 72 6F 20 20 66 6C 61 67 20 69 6E    e  Zero  flag in
002C80:  64 69 63 61 74 65 73 20 20 42 3D 30 20 69 6E FE    dicates  B=0 in.
002C90:  90 20 74 68 65 73 65 63 61 73 65 73 A0 A0 20 53    . thesecases.. S
002CA0:  69 6E 63 65 20 20 74 68 65 20 20 41 4D 53 54 52    ince  the  AMSTR
002CB0:  41 44 20 20 75 73 65 73 20 74 68 65 20 64 61 74    AD  uses the dat
002CC0:  61 20 73 65 6E 74 6F 75 74 20 66 72 6F 6D 20 74    a sentout from t
002CD0:  68 65 20 20 42 20 72 65 67 69 73 74 65 72 20 61    he  B register a
002CE0:  73 20 50 6F 72 74 20 61 64 64 72 65 73 73 69 6E    s Port addressin
002CF0:  20 20 49 2F 4F 20 20 69 6E 73 74 72 75 63 74 69      I/O  instructi
002D00:  6F 6E 73 2C 20 69 74 20 63 61 6E 6E 6F 74 20 73    ons, it cannot s
002D10:  75 70 70 6F 72 74 74 68 65 73 65 20 62 6C 6F 63    upportthese bloc
002D20:  6B 20 49 2F 4F 20 69 6E 73 74 72 75 63 74 69 6F    k I/O instructio
002D30:  6E 73 2E A3 20 20 20 20 20 50 52 4F 43 45 53 53    ns.£     PROCESS
002D40:  4F 52 20 43 4F 4E 54 52 4F 4C 20 49 4E 53 54 52    OR CONTROL INSTR
002D50:  55 43 54 49 4F 4E 53 A0 A0 20 54 68 69 73 20 20    UCTIONS.. This  
002D60:  67 72 6F 75 70 20 20 6F 66 20 20 69 6E 73 74 72    group  of  instr
002D70:  75 63 74 69 6F 6E 73 2C 20 74 6F 67 65 74 68 65    uctions, togethe
002D80:  72 77 69 74 68 20 74 68 65 20 69 6E 74 65 72 72    rwith the interr
002D90:  75 DA 32 70 74 20 69 6E 73 74 72 75 63 74 69 6F    u.2pt instructio
002DA0:  6E 73 2C 20 63 6F 6E 74 72 6F 6C 74 68 65 20 61    ns, controlthe a
002DB0:  63 74 69 6F 6E 20 6F 66 20 74 68 65 20 70 72 6F    ction of the pro
002DC0:  63 65 73 73 6F 72 2E A0 A0 20 4E 4F 50 20 20 20    cessor... NOP   
002DD0:  6F 72 20 20 20 4E 6F 20 20 4F 50 65 72 61 74 69    or   No  OPerati
002DE0:  6F 6E 20 20 20 63 61 75 73 65 73 20 20 20 74 68    on   causes   th
002DF0:  65 70 72 6F 63 65 73 73 6F 72 20 20 74 6F 20 20    eprocessor  to  
002E00:  64 6F 20 20 6E 6F 74 68 69 6E 67 20 66 6F 72 20    do  nothing for 
002E10:  6F 6E 65 20 73 74 65 70 2E 53 69 6E 63 65 20 69    one step.Since i
002E20:  74 73 20 63 6F 64 65 20 69 73 20 20 30 20 2C 20    ts code is  0 , 
002E30:  20 61 20 63 6C 65 61 72 65 64 20 6D 65 6D 6F 72     a cleared memor
002E40:  79 61 72 65 61 20 77 69 6C 6C 20 62 65 20 73 65    yarea will be se
002E50:  71 75 65 6E 63 65 64 20 20 74 68 72 6F 75 67 68    quenced  through
002E60:  20 75 6E 74 69 6C 20 20 61 6E 6F 6E 2D 7A 65 72     until  anon-zer
002E70:  6F 20 69 6E 73 74 72 75 63 74 69 6F 6E 20 69 73    o instruction is
002E80:  20 66 6F 75 6E 64 2E A0 A0 20 48 41 4C 54 20 20     found... HALT  
002E90:  20 73 74 38 81 6F 70 73 20 20 20 74 68 65 20 20     st8.ops   the  
002EA0:  20 73 65 71 75 65 6E 63 69 6E 67 20 20 6F 66 20     sequencing  of 
002EB0:  74 68 65 70 72 6F 63 65 73 73 6F 72 20 75 6E 74    theprocessor unt
002EC0:  69 6C 20 61 6E 20 69 6E 74 65 72 72 75 70 74 20    il an interrupt 
002ED0:  69 73 20 72 65 63 65 69 76 65 64 28 20 73 65 65    is received( see
002EE0:  20 6E 65 78 74 20 6C 65 73 73 6F 6E 20 29 2E 20     next lesson ). 
002EF0:  41 66 74 65 72 20 74 68 65 20 69 6E 74 65 72 72    After the interr
002F00:  75 70 74 68 61 73 20 20 62 65 65 6E 20 20 64 65    upthas  been  de
002F10:  61 6C 74 20 20 77 69 74 68 2C 20 20 74 68 65 20    alt  with,  the 
002F20:  69 6E 73 74 72 75 63 74 69 6F 6E 61 66 74 65 72    instructionafter
002F30:  20 74 68 65 20 20 48 41 4C 54 20 20 69 73 20 20     the  HALT  is  
002F40:  70 65 72 66 6F 72 6D 65 64 2E 20 54 68 75 73 20    performed. Thus 
002F50:  74 68 65 70 72 6F 67 72 61 6D 20 20 20 63 61 6E    theprogram   can
002F60:  20 20 20 62 65 20 20 20 73 79 6E 63 68 72 6F 6E       be   synchron
002F70:  69 73 65 64 20 20 20 77 69 74 68 6F 70 65 72 61    ised   withopera
002F80:  74 69 6F 6E 73 20 6F 75 74 73 69 64 65 20 74 68    tions outside th
002F90:  65 20 70 72 6F D4 83 63 65 73 73 6F 72 2E A3 20    e pro..cessor.£ 
002FA0:  41 73 20 20 20 77 65 6C 6C 20 20 20 61 73 20 20    As   well   as  
002FB0:  20 74 68 65 20 20 20 73 74 61 6E 64 61 72 64 20     the   standard 
002FC0:  20 20 20 43 41 4C 4C 69 6E 73 74 72 75 63 74 69       CALLinstructi
002FD0:  6F 6E 73 20 20 69 6E 63 6F 72 70 6F 72 61 74 69    ons  incorporati
002FE0:  6E 67 20 20 74 68 65 20 61 64 64 72 65 73 73 74    ng  the addresst
002FF0:  6F 20 77 68 69 63 68 20 20 74 68 65 20 70 72 6F    o which  the pro
003000:  63 65 73 73 6F 72 20 20 69 73 20 74 6F 20 6A 75    cessor  is to ju
003010:  6D 70 2C 20 74 68 65 5A 38 30 20 20 20 68 61 73    mp, theZ80   has
003020:  20 20 69 6E 73 74 72 75 63 74 69 6F 6E 73 20 20      instructions  
003030:  69 6E 20 20 77 68 69 63 68 20 20 20 74 68 65 61    in  which   thea
003040:  64 64 72 65 73 73 20 20 6F 66 20 20 74 68 65 20    ddress  of  the 
003050:  20 43 41 4C 4C 20 20 69 73 20 20 69 6D 70 6C 69     CALL  is  impli
003060:  65 64 2E 20 54 68 65 69 6E 73 74 72 75 63 74 69    ed. Theinstructi
003070:  6F 6E 73 20 20 20 52 53 54 20 6E 20 28 20 77 68    ons   RST n ( wh
003080:  65 72 65 20 6E 3D 30 30 48 2C 20 30 38 48 2C 31    ere n=00H, 08H,1
003090:  30 48 2C 20 31 38 48 36 00 2C 20 32 30 48 2C 20    0H, 18H6., 20H, 
0030A0:  32 38 48 2C 20 33 30 48 2C 20 33 38 48 20 29 20    28H, 30H, 38H ) 
0030B0:  63 61 6C 6C 73 20 74 68 65 72 6F 75 74 69 6E 65    calls theroutine
0030C0:  20 61 74 20 30 30 6E 20 48 20 20 64 69 72 65 63     at 00n H  direc
0030D0:  74 6C 79 2E 20 69 2E 65 2E 20 52 53 54 20 32 38    tly. i.e. RST 28
0030E0:  48 69 73 20 20 65 71 75 69 76 61 6C 65 6E 74 20    His  equivalent 
0030F0:  74 6F 20 43 41 4C 4C 20 30 30 32 38 48 A0 A0 20    to CALL 0028H.. 
003100:  54 68 65 69 72 20 20 70 72 69 6D 65 20 20 75 73    Their  prime  us
003110:  65 20 20 6F 6E 20 20 73 6F 6D 65 20 20 73 79 73    e  on  some  sys
003120:  74 65 6D 73 20 69 73 74 6F 20 20 61 6C 6C 6F 77    tems isto  allow
003130:  20 20 65 78 74 65 72 6E 61 6C 20 20 68 61 72 64      external  hard
003140:  77 61 72 65 20 20 74 6F 20 20 66 6F 72 63 65 74    ware  to  forcet
003150:  68 65 20 20 73 69 6E 67 6C 65 20 20 62 79 74 65    he  single  byte
003160:  20 20 69 6E 73 74 72 75 63 74 69 6F 6E 73 20 69      instructions i
003170:  6E 74 6F 20 74 68 65 70 72 6F 63 65 73 73 6F 72    nto theprocessor
003180:  2C 20 20 74 68 75 73 20 20 6D 61 6B 69 6E 67 20    ,  thus  making 
003190:  20 69 74 20 20 74 68 69 6E F8 3C 6B 20 20 69 74     it  thin.<k  it
0031A0:  73 6E 65 78 74 20 20 20 69 6E 73 74 72 75 63 74    snext   instruct
0031B0:  69 6F 6E 20 20 20 69 73 20 20 61 6E 20 20 52 53    ion   is  an  RS
0031C0:  54 20 6E 2E 20 20 20 49 74 74 68 65 72 65 66 6F    T n.   Ittherefo
0031D0:  72 65 20 66 6F 72 6D 73 20 61 20 6D 65 74 68 6F    re forms a metho
0031E0:  64 20 6F 66 20 69 6E 74 65 72 72 75 70 74 69 6E    d of interruptin
0031F0:  67 74 68 65 20 20 70 72 6F 63 65 73 73 6F 72 2E    gthe  processor.
003200:  20 20 20 28 20 73 65 65 20 20 74 68 65 20 20 6C       ( see  the  l
003210:  65 73 73 6F 6E 20 20 6F 6E 69 6E 74 65 72 72 75    esson  oninterru
003220:  70 74 73 29 2E A3 20 41 6C 6C 20 62 75 74 20 6F    pts).£ All but o
003230:  6E 65 20 52 53 54 20 63 61 6C 6C 20 61 72 65 20    ne RST call are 
003240:  20 73 70 65 63 69 66 69 65 64 20 20 6F 6E 74 68     specified  onth
003250:  65 20 41 4D 53 54 52 41 44 20 28 20 74 68 65 20    e AMSTRAD ( the 
003260:  43 50 43 34 36 34 20 46 49 52 4D 57 41 52 45 20    CPC464 FIRMWARE 
003270:  6D 61 6E 75 61 6C 64 65 66 69 6E 65 73 20 20 74    manualdefines  t
003280:  68 65 6D 20 20 61 6C 6C 20 20 69 6E 20 20 64 65    hem  all  in  de
003290:  74 61 69 6C 20 29 2E 20 20 20 4D 90 8D 6F 73 74    tail ).   M..ost
0032A0:  61 66 66 65 63 74 20 20 74 68 65 20 20 73 79 73    affect  the  sys
0032B0:  74 65 6D 20 20 63 6F 6E 66 69 67 75 72 61 74 69    tem  configurati
0032C0:  6F 6E 20 20 65 74 63 2E 69 2E 65 2E 20 52 53 54    on  etc.i.e. RST
0032D0:  20 30 30 48 20 20 69 73 20 65 71 75 69 76 61 6C     00H  is equival
0032E0:  65 6E 74 20 74 6F 20 4E 45 57 2C 20 74 68 61 74    ent to NEW, that
0032F0:  63 6C 65 61 72 73 20 20 6F 75 74 20 20 20 61 6C    clears  out   al
003300:  6C 20 20 74 68 65 20 20 6D 65 6D 6F 72 79 20 20    l  the  memory  
003310:  61 6E 64 20 20 72 65 2D 65 73 74 61 62 6C 69 73    and  re-establis
003320:  68 65 73 20 20 74 68 65 20 20 73 79 73 74 65 6D    hes  the  system
003330:  2E 20 20 20 4E 65 65 64 6C 65 73 73 20 20 74 6F    .   Needless  to
003340:  73 61 79 20 20 74 68 65 20 73 69 6D 75 6C 61 74    say  the simulat
003350:  6F 72 20 64 6F 65 73 20 6E 6F 74 20 70 65 72 66    or does not perf
003360:  6F 72 6D 20 20 52 53 54 69 6E 73 74 72 75 63 74    orm  RSTinstruct
003370:  69 6F 6E 73 2E A0 A0 20 54 68 65 72 65 20 20 61    ions... There  a
003380:  72 65 20 6F 6E 6C 79 20 20 74 77 6F 20 20 6D 6F    re only  two  mo
003390:  72 65 20 72 65 67 69 73 74 65 72 73 20 50 F5 69    re registers P.i
0033A0:  6E 74 68 65 20 5A 38 30 20 74 6F 20 64 69 73 63    nthe Z80 to disc
0033B0:  75 73 73 2C 20 74 68 65 20 20 49 20 6F 72 20 20    uss, the  I or  
0033C0:  49 6E 74 65 72 72 75 70 74 72 65 67 69 73 74 65    Interruptregiste
0033D0:  72 20 28 73 65 65 20 6E 65 78 74 20 6C 65 73 73    r (see next less
0033E0:  6F 6E 29 2C 20 61 6E 64 20 74 68 65 20 52 20 6F    on), and the R o
0033F0:  72 52 65 66 72 65 73 68 20 72 65 67 69 73 74 65    rRefresh registe
003400:  72 2E A3 20 54 68 65 20 20 52 65 66 72 65 73 68    r.£ The  Refresh
003410:  20 20 72 65 67 69 73 74 65 72 20 69 73 20 75 73      register is us
003420:  65 64 20 20 62 79 20 73 6F 6D 65 66 6F 72 6D 73    ed  by someforms
003430:  20 20 6F 66 20 20 52 61 6E 64 6F 6D 20 20 41 63      of  Random  Ac
003440:  63 65 73 73 20 20 4D 65 6D 6F 72 79 20 20 77 68    cess  Memory  wh
003450:  69 63 68 72 65 71 75 69 72 65 20 20 63 6F 6E 74    ichrequire  cont
003460:  69 6E 75 6F 75 73 20 20 77 72 69 74 69 6E 67 20    inuous  writing 
003470:  74 6F 20 6D 61 69 6E 74 61 69 6E 69 74 73 20 20    to maintainits  
003480:  69 6E 66 6F 72 6D 61 74 69 6F 6E 2E 20 20 20 54    information.   T
003490:  68 65 20 20 52 20 20 72 65 67 69 73 74 65 72 AB    he  R  register.
0034A0:  D4 20 20 69 73 69 6E 63 72 65 6D 65 6E 74 65 64    .  isincremented
0034B0:  20 61 75 74 6F 6D 61 74 69 63 61 6C 6C 79 20 65     automatically e
0034C0:  76 65 72 79 20 74 69 6D 65 20 74 68 65 70 72 6F    very time thepro
0034D0:  63 65 73 73 6F 72 20 20 20 66 65 74 63 68 65 73    cessor   fetches
0034E0:  20 20 20 65 61 63 68 20 20 20 70 61 72 74 20 20       each   part  
0034F0:  6F 66 20 61 6E 69 6E 73 74 72 75 63 74 69 6F 6E    of aninstruction
003500:  20 20 66 72 6F 6D 20 20 6D 65 6D 6F 72 79 2E 20      from  memory. 
003510:  54 68 69 73 20 70 72 6F 76 69 64 65 73 74 68 65    This providesthe
003520:  20 70 72 6F 67 72 61 6D 6D 65 72 20 20 77 69 74     programmer  wit
003530:  68 20 20 61 20 20 72 65 67 69 73 74 65 72 20 20    h  a  register  
003540:  77 68 6F 73 65 63 6F 6E 74 65 6E 74 73 20 6D 61    whosecontents ma
003550:  79 20 62 65 20 20 63 6F 6E 73 69 64 65 72 65 64    y be  considered
003560:  20 20 72 61 6E 64 6F 6D 20 20 66 6F 72 73 6F 6D      random  forsom
003570:  65 20 61 70 70 6C 69 63 61 74 69 6F 6E 73 2E A0    e applications..
003580:  A0 20 54 68 65 20 20 52 20 20 61 6E 64 20 20 49    . The  R  and  I
003590:  20 20 72 65 67 69 73 74 65 72 73 20 63 61 6E 20      registers can 
0035A0:  62 89 08 65 20 6C 6F 61 64 65 64 66 72 6F 6D 20    b..e loadedfrom 
0035B0:  20 74 68 65 20 20 41 63 63 75 6D 75 6C 61 74 6F     the  Accumulato
0035C0:  72 2E 20 54 68 65 20 69 6E 73 74 72 75 63 74 69    r. The instructi
0035D0:  6F 6E 73 69 6E 76 6F 6C 76 65 64 20 61 72 65 20    onsinvolved are 
0035E0:  73 69 6D 70 6C 79 20 20 4C 44 20 41 2C 52 20 3A    simply  LD A,R :
0035F0:  20 20 4C 44 20 52 2C 41 20 20 3A 4C 44 20 41 2C      LD R,A  :LD A,
003600:  49 20 61 6E 64 20 4C 44 20 49 2C 41 2E A3 53 75    I and LD I,A.£Su
003610:  6D 6D 61 72 79 20 2D 20 70 72 6F 63 65 73 73 6F    mmary - processo
003620:  72 20 63 6F 6E 74 72 6F 6C 20 69 6E 73 74 72 75    r control instru
003630:  63 74 69 6F 6E 73 A0 4E 4F 50 20 A0 48 41 4C 54    ctions.NOP .HALT
003640:  A0 A0 52 53 54 20 6E 20 20 77 68 65 72 65 20 6E    ..RST n  where n
003650:  20 3D 30 30 48 2C 20 30 38 48 2C 20 31 30 48 2C     =00H, 08H, 10H,
003660:  20 31 38 48 2C 20 32 30 48 2C 20 20 20 20 20 20     18H, 20H,      
003670:  20 20 20 20 20 20 20 20 20 20 32 38 48 2C 20 33              28H, 3
003680:  30 48 2C 20 6F 72 20 33 38 48 2E A0 A0 4C 44 20    0H, or 38H...LD 
003690:  41 2C 52 A0 4C 44 20 52 2C 41 A0 A0 4C 44 20 41    A,R.LD R,A..LD A
0036A0:  2C 49 A0 00 37 4C 44 20 49 2C 41 A3 20 20 20 45    ,I..7LD I,A£   E
0036B0:  58 41 4D 50 4C 45 20 4F 46 20 55 53 45 20 4F 46    XAMPLE OF USE OF
0036C0:  20 52 45 46 52 45 53 48 20 52 45 47 49 53 54 45     REFRESH REGISTE
0036D0:  52 A0 A0 20 4D 6F 73 74 20 6F 66 20 74 68 65 20    R.. Most of the 
0036E0:  69 6E 73 74 72 75 63 74 69 6F 6E 20 69 6E 20 74    instruction in t
0036F0:  68 69 73 20 61 6E 64 20 74 68 65 6C 61 73 74 20    his and thelast 
003700:  20 6C 65 73 73 6F 6E 20 20 69 6E 76 6F 6C 76 65     lesson  involve
003710:  20 20 73 74 65 70 73 20 74 68 61 74 20 63 68 61      steps that cha
003720:  6E 67 65 74 68 65 20 65 6E 76 69 72 6F 6E 6D 65    ngethe environme
003730:  6E 74 20 69 6E 20 77 68 69 63 68 20 74 68 65 20    nt in which the 
003740:  20 20 70 72 6F 63 65 73 73 6F 72 6F 70 65 72 61      processoropera
003750:  74 65 73 2E 20 20 49 74 20 69 73 20 20 74 68 65    tes.  It is  the
003760:  72 65 66 6F 72 65 20 64 69 66 66 69 63 75 6C 74    refore difficult
003770:  20 74 6F 73 69 6D 75 6C 61 74 65 20 74 68 65 73     tosimulate thes
003780:  65 20 69 6E 73 74 72 75 63 74 69 6F 6E 73 2E 20    e instructions. 
003790:  20 4C 69 74 74 6C 65 20 63 61 6E 62 65 20 6C 65     Little canbe le
0037A0:  61 72 6E 74 20 E8 CE 66 72 6F 6D 20 20 73 69 6E    arnt ..from  sin
0037B0:  67 6C 65 20 73 74 65 70 70 69 6E 67 20 20 74 68    gle stepping  th
0037C0:  72 6F 75 67 68 61 6E 20 20 65 78 61 6D 70 6C 65    roughan  example
0037D0:  2E 20 20 48 6F 77 65 76 65 72 20 63 68 61 6E 67    .  However chang
0037E0:  69 6E 67 20 69 6E 74 65 72 72 75 70 74 65 74 63    ing interruptetc
0037F0:  2E 20 28 20 73 65 65 20 6E 65 78 74 20 6C 65 73    . ( see next les
003800:  73 6F 6E 20 29 20 20 6F 6E 20 20 61 20 50 65 72    son )  on  a Per
003810:  73 6F 6E 61 6C 43 6F 6D 70 75 74 65 72 20 69 73    sonalComputer is
003820:  20 20 61 64 76 61 6E 63 65 64 20 20 70 72 6F 67      advanced  prog
003830:  72 61 6D 6D 69 6E 67 2E 20 20 54 72 79 67 61 69    ramming.  Trygai
003840:  6E 69 6E 67 20 20 20 65 78 70 65 72 69 65 6E 63    ning   experienc
003850:  65 20 20 20 6F 6E 20 20 6D 61 63 68 69 6E 65 20    e   on  machine 
003860:  20 63 6F 64 65 70 72 6F 67 72 61 6D 6D 69 6E 67     codeprogramming
003870:  20 20 62 65 66 6F 72 65 20 20 76 65 6E 74 75 72      before  ventur
003880:  69 6E 67 20 69 6E 74 6F 20 74 68 69 73 66 69 65    ing into thisfie
003890:  6C 64 2E A0 A0 20 54 68 65 20 20 65 78 61 6D 70    ld... The  examp
0038A0:  6C 65 20 20 73 68 6F 81 EF 77 73 20 20 74 68 65    le  sho..ws  the
0038B0:  20 20 75 73 65 20 20 6F 66 20 20 20 74 68 65 52      use  of   theR
0038C0:  65 66 72 65 73 68 20 20 72 65 67 69 73 74 65 72    efresh  register
0038D0:  20 20 61 73 20 61 20 73 6F 75 72 63 65 20 6F 66      as a source of
0038E0:  20 72 61 6E 64 6F 6D 6E 75 6D 62 65 72 73 2E A3     randomnumbers.£
0038F0:  20 4E 4F 50 A0 20 4C 4F 4F 50 20 20 4C 44 20 41     NOP. LOOP  LD A
003900:  2C 52 A0 20 20 4A 52 20 4C 4F 4F 50 A0 20 20 A0    ,R.  JR LOOP.  .
003910:  20 20 A0 20 20 A0 20 20 A0 20 20 A0 20 20 A0 20      .  .  .  .  . 
003920:  20 A0 20 20 A0 20 20 A0 20 20 A0 20 20 A0 20 20     .  .  .  .  .  
003930:  A0 20 20 A0 20 20 20 20 20 20 20 20 20 20 20 20    .  .            
003940:  20 20 20 49 4E 54 45 52 52 55 50 54 53 A0 A0 20       INTERRUPTS.. 
003950:  41 6E 20 20 69 6E 74 65 72 72 75 70 74 20 20 6F    An  interrupt  o
003960:  72 69 67 69 6E 61 74 65 73 20 66 72 6F 6D 20 20    riginates from  
003970:  6F 75 74 73 69 64 65 74 68 65 20 70 72 6F 63 65    outsidethe proce
003980:  73 73 6F 72 2C 20 20 72 65 71 75 65 73 74 69 6E    ssor,  requestin
003990:  67 20 20 69 74 20 20 74 6F 20 62 72 65 61 6B 6F    g  it  to breako
0039A0:  66 66 20 69 74 73 20 63 75 39 7B 72 72 65 6E 74    ff its cu9{rrent
0039B0:  20 20 73 65 71 75 65 6E 63 65 20 6F 66 20 20 6F      sequence of  o
0039C0:  70 65 72 61 74 69 6F 6E 73 61 6E 64 20 64 65 61    perationsand dea
0039D0:  6C 20 77 69 74 68 20 73 6F 6D 65 20 6F 74 68 65    l with some othe
0039E0:  72 20 66 75 6E 63 74 69 6F 6E 2E A0 A0 20 49 6E    r function... In
0039F0:  74 65 72 72 75 70 74 73 20 20 66 61 6C 6C 20 69    terrupts  fall i
003A00:  6E 74 6F 20 20 74 77 6F 20 74 79 70 65 73 2C 20    nto  two types, 
003A10:  20 4E 6F 6E 2D 4D 61 73 6B 61 62 6C 65 20 49 6E     Non-Maskable In
003A20:  74 65 72 72 75 70 74 73 20 28 4E 4D 49 29 20 20    terrupts (NMI)  
003A30:  61 6E 64 20 20 4D 61 73 6B 61 62 6C 65 49 6E 74    and  MaskableInt
003A40:  65 72 72 75 70 74 73 20 28 4D 49 29 2E 20 20 4D    errupts (MI).  M
003A50:  61 73 6B 61 62 6C 65 20 69 6E 74 65 72 72 75 70    askable interrup
003A60:  74 20 63 61 6E 62 65 20 20 69 67 6E 6F 72 65 64    t canbe  ignored
003A70:  20 20 62 79 20 20 74 68 65 20 20 73 6F 66 74 77      by  the  softw
003A80:  61 72 65 2C 20 62 75 74 20 4E 4D 49 73 63 61 6E    are, but NMIscan
003A90:  6E 6F 74 2E A0 A0 20 4F 6E 65 20 4E 6F 6E 2D 4D    not... One Non-M
003AA0:  61 73 6B 61 62 6C 65 20 49 6E 74 87 A2 65 72 72    askable Int..err
003AB0:  75 70 74 20 69 73 20 61 76 61 69 6C 61 62 6C 65    upt is available
003AC0:  6F 6E 20 20 74 68 65 20 20 20 5A 38 30 20 20 20    on  the   Z80   
003AD0:  63 68 69 70 2E 20 20 20 20 54 68 65 20 20 20 69    chip.    The   i
003AE0:  6E 74 65 72 72 75 70 74 61 75 74 6F 6D 61 74 69    nterruptautomati
003AF0:  63 61 6C 6C 79 20 70 65 72 66 6F 72 6D 73 20 61    cally performs a
003B00:  6E 20 52 53 54 20 6F 72 20 43 41 4C 4C 20 74 6F    n RST or CALL to
003B10:  61 64 64 72 65 73 73 20 20 30 30 36 36 48 20 20    address  0066H  
003B20:  6F 6E 20 20 63 6F 6D 70 6C 65 74 69 6F 6E 20 20    on  completion  
003B30:  6F 66 20 20 20 74 68 65 63 75 72 72 65 6E 74 20    of   thecurrent 
003B40:  20 69 6E 73 74 72 75 63 74 69 6F 6E 73 2E 20 20     instructions.  
003B50:  54 68 65 20 20 72 6F 75 74 69 6E 65 20 20 61 74    The  routine  at
003B60:  30 30 36 36 48 20 69 73 20 70 65 72 66 6F 72 6D    0066H is perform
003B70:  65 64 2E 20 54 68 65 20 69 6E 73 74 72 75 63 74    ed. The instruct
003B80:  69 6F 6E 20 52 45 54 4E 6F 72 20 52 45 54 75 72    ion RETNor RETur
003B90:  6E 20 66 72 6F 6D 20 20 20 4E 6F 6E 2D 6D 61 73    n from   Non-mas
003BA0:  6B 61 62 6C 65 20 20 69 6E 74 65 72 72 CB FA 75    kable  interr..u
003BB0:  70 74 72 65 74 75 72 6E 73 20 20 63 6F 6E 74 72    ptreturns  contr
003BC0:  6F 6C 20 62 61 63 6B 20 74 6F 20 74 68 65 20 69    ol back to the i
003BD0:  6E 74 65 72 72 75 70 74 65 64 72 6F 75 74 69 6E    nterruptedroutin
003BE0:  65 20 61 74 20 69 74 73 20 6E 65 78 74 20 69 6E    e at its next in
003BF0:  73 74 72 75 63 74 69 6F 6E 20 2E A3 54 68 65 20    struction .£The 
003C00:  70 72 6F 67 72 61 6D 6D 65 72 20 63 61 6E 20 61    programmer can a
003C10:  72 72 61 6E 67 65 20 74 68 61 74 20 6D 61 73 6B    rrange that mask
003C20:  61 62 6C 65 69 6E 74 65 72 72 75 70 74 73 20 20    ableinterrupts  
003C30:  28 4D 49 29 20 61 72 65 20 69 67 6E 6F 72 65 64    (MI) are ignored
003C40:  2E 20 57 69 74 68 69 6E 20 74 68 65 5A 38 30 20    . Within theZ80 
003C50:  20 74 68 65 72 65 20 20 69 73 20 20 61 20 20 66     there  is  a  f
003C60:  6C 61 67 2C 20 20 74 68 65 20 20 69 6E 74 65 72    lag,  the  inter
003C70:  72 75 70 74 65 6E 61 62 6C 65 20 20 66 6C 61 67    ruptenable  flag
003C80:  2C 20 20 20 74 68 61 74 20 20 63 61 6E 20 20 62    ,   that  can  b
003C90:  65 20 20 73 65 74 20 20 20 61 6E 64 63 6C 65 61    e  set   andclea
003CA0:  72 65 64 2E 20 20 20 44 65 70 65 6E 64 69 6E A4    red.   Dependin.
003CB0:  C5 67 20 20 75 70 6F 6E 20 20 74 68 65 20 73 74    .g  upon  the st
003CC0:  61 74 65 20 6F 66 74 68 69 73 20 20 66 6C 61 67    ate ofthis  flag
003CD0:  20 20 20 4D 49 73 20 20 77 69 6C 6C 20 20 62 65       MIs  will  be
003CE0:  20 20 61 63 63 65 70 74 65 64 20 20 6F 72 69 67      accepted  orig
003CF0:  6E 6F 72 65 64 2E A0 A0 20 54 68 65 20 20 74 77    nored... The  tw
003D00:  6F 20 20 69 6E 73 74 72 75 63 74 69 6F 6E 73 20    o  instructions 
003D10:  20 74 68 61 74 20 6D 61 6E 69 70 75 6C 61 74 65     that manipulate
003D20:  74 68 69 73 20 66 6C 61 67 20 61 72 65 A0 A0 20    this flag are.. 
003D30:  45 49 20 20 20 45 6E 61 62 6C 65 20 49 6E 74 65    EI   Enable Inte
003D40:  72 72 75 70 74 73 2E 20 20 41 66 74 65 72 20 6F    rrupts.  After o
003D50:  6E 65 20 6D 6F 72 65 20 20 20 20 20 20 73 69 6E    ne more      sin
003D60:  67 6C 65 20 20 62 79 74 65 20 20 69 6E 73 74 72    gle  byte  instr
003D70:  75 63 74 69 6F 6E 2C 20 66 75 72 74 68 65 72 20    uction, further 
003D80:  20 20 20 20 20 69 6E 74 65 72 72 75 70 74 73 20         interrupts 
003D90:  61 72 65 20 61 63 63 65 70 74 65 64 2E A0 A0 20    are accepted... 
003DA0:  44 49 20 20 20 44 69 73 61 62 6C 65 20 49 6E 74    DI   Disable Int
003DB0:  65 EE 76 72 72 75 70 74 73 20 69 6D 6D 65 64 69    e.vrrupts immedi
003DC0:  61 74 65 6C 79 2E A0 A0 20 45 6E 74 72 79 20 20    ately... Entry  
003DD0:  20 69 6E 74 6F 20 20 20 61 20 20 20 6D 61 73 6B     into   a   mask
003DE0:  61 62 6C 65 20 20 20 69 6E 74 65 72 72 75 70 74    able   interrupt
003DF0:  61 75 74 6F 6D 61 74 69 63 61 6C 6C 79 20 64 69    automatically di
003E00:  73 61 62 6C 65 73 20 69 6E 74 65 72 72 75 70 74    sables interrupt
003E10:  2E A3 54 68 72 65 65 20 20 20 74 79 70 65 73 2C    .£Three   types,
003E20:  20 20 6F 72 20 20 6D 6F 64 65 73 2C 20 20 6F 66      or  modes,  of
003E30:  20 20 6D 61 73 6B 61 62 6C 65 69 6E 74 65 72 72      maskableinterr
003E40:  75 70 74 73 20 61 72 65 20 61 76 61 69 6C 61 62    upts are availab
003E50:  6C 65 2E A0 A0 20 4D 4F 44 45 20 30 20 69 73 20    le... MODE 0 is 
003E60:  73 65 74 20 62 79 20 74 68 65 20 69 6E 73 74 72    set by the instr
003E70:  75 63 74 69 6F 6E 20 20 49 4D 20 30 2E 54 68 69    uction  IM 0.Thi
003E80:  73 20 20 20 6D 6F 64 65 20 20 20 69 73 20 20 20    s   mode   is   
003E90:  74 68 65 20 20 20 6F 6E 65 20 20 20 64 65 73 63    the   one   desc
003EA0:  72 69 62 65 64 70 72 65 76 69 6F 75 73 6C 79 2C    ribedpreviously,
003EB0:  20 20 77 B5 19 68 65 72 65 20 74 68 65 20 52 53      w..here the RS
003EC0:  54 20 6E 20 69 6E 73 74 72 75 63 74 69 6F 6E 69    T n instructioni
003ED0:  73 20 66 6F 72 63 65 64 20 6F 6E 74 6F 20 74 68    s forced onto th
003EE0:  65 20 64 61 74 61 20 68 69 67 68 77 61 79 20 74    e data highway t
003EF0:  6F 20 20 66 6F 6F 6C 74 68 65 20 20 70 72 6F 63    o  foolthe  proc
003F00:  65 73 73 6F 72 20 20 20 69 6E 74 6F 20 20 20 70    essor   into   p
003F10:  65 72 66 6F 72 6D 69 6E 67 20 20 20 74 68 65 72    erforming   ther
003F20:  65 73 74 61 72 74 2E A0 A0 20 4D 4F 44 45 20 31    estart... MODE 1
003F30:  20 69 73 20 74 68 65 20 20 6F 6E 65 20 20 75 73     is the  one  us
003F40:  65 64 20 62 79 20 74 68 65 20 41 4D 53 54 52 41    ed by the AMSTRA
003F50:  44 73 79 73 74 65 6D 20 52 4F 4D 2E 20 49 74 20    Dsystem ROM. It 
003F60:  69 73 20 73 65 74 20 62 79 20 74 68 65 20 69 6E    is set by the in
003F70:  73 74 72 75 63 74 69 6F 6E 49 4D 20 31 2E 20 20    structionIM 1.  
003F80:  54 68 69 73 20 6D 6F 64 65 20 69 73 20 73 69 6D    This mode is sim
003F90:  69 6C 61 72 20 69 6E 20 6F 70 65 72 61 74 69 6F    ilar in operatio
003FA0:  6E 74 6F 20 20 74 68 65 20 20 4E 6F 6E 20 4D 61    nto  the  Non Ma
003FB0:  73 6B 61 62 6C 9D 4D 65 20 20 49 6E 74 65 72 72    skabl.Me  Interr
003FC0:  75 70 74 20 20 65 78 63 65 70 74 74 68 61 74 20    upt  exceptthat 
003FD0:  20 70 72 6F 63 65 73 73 6F 72 20 69 73 20 20 72     processor is  r
003FE0:  65 73 74 61 72 74 65 64 20 20 61 74 20 20 30 30    estarted  at  00
003FF0:  33 38 48 69 6E 73 74 65 61 64 20 6F 66 20 30 30    38Hinstead of 00
004000:  36 36 48 20 61 73 20 69 6E 20 74 68 65 20 4E 4D    66H as in the NM
004010:  49 2E A3 20 4D 4F 44 45 20 32 20 20 69 73 20 20    I.£ MODE 2  is  
004020:  74 68 65 20 20 6D 6F 73 74 20 20 20 66 6C 65 78    the  most   flex
004030:  69 62 6C 65 2C 20 20 20 74 68 65 61 64 64 72 65    ible,   theaddre
004040:  73 73 20 74 6F 20 77 68 69 63 68 20 74 68 65 20    ss to which the 
004050:  70 72 6F 63 65 73 73 6F 72 20 69 73 20 66 6F 72    processor is for
004060:  63 65 64 69 73 20 74 68 65 20 69 6E 64 69 72 65    cedis the indire
004070:  63 74 20 61 64 64 72 65 73 73 20 68 65 6C 64 20    ct address held 
004080:  69 6E 20 61 20 6D 65 6D 6F 72 79 6C 6F 63 61 74    in a memorylocat
004090:  69 6F 6E 2E 20 20 20 54 68 65 20 61 64 64 72 65    ion.   The addre
0040A0:  73 73 20 20 6F 66 20 74 68 69 73 20 20 6D 65 6D    ss  of this  mem
0040B0:  6F 72 79 6C 6F 63 61 89 B0 74 69 6F 6E 20 20 69    oryloca..tion  i
0040C0:  73 20 63 6F 6D 70 75 74 65 64 20 66 72 6F 6D 20    s computed from 
0040D0:  20 74 68 65 20 20 63 6F 6E 74 65 6E 74 6F 66 20     the  contentof 
0040E0:  74 68 65 20 20 49 20 72 65 67 69 73 74 65 72 2C    the  I register,
0040F0:  20 20 77 68 69 63 68 20 20 70 72 6F 76 69 64 65      which  provide
004100:  73 20 74 68 65 68 69 67 68 20 20 62 79 74 65 20    s thehigh  byte 
004110:  61 6E 64 20 20 74 68 65 20 20 69 6E 74 65 72 72    and  the  interr
004120:  75 70 74 69 6E 67 20 64 65 76 69 63 65 77 68 69    upting devicewhi
004130:  63 68 20 20 70 72 6F 76 69 64 65 73 20 20 74 68    ch  provides  th
004140:  65 20 20 6C 6F 77 20 20 20 62 79 74 65 2E 20 20    e  low   byte.  
004150:  53 69 6E 63 65 74 68 65 20 20 69 6E 74 65 72 72    Sincethe  interr
004160:  75 70 74 20 20 72 6F 75 74 69 6E 65 20 20 20 69    upt  routine   i
004170:  73 20 20 20 61 64 64 72 65 73 73 65 64 69 6E 64    s   addressedind
004180:  69 72 65 63 74 6C 79 20 20 74 68 65 20 20 69 6E    irectly  the  in
004190:  74 65 72 72 75 70 74 73 20 20 61 72 65 20 20 74    terrupts  are  t
0041A0:  65 72 6D 65 64 76 65 63 74 6F 72 65 64 20 69 6E    ermedvectored in
0041B0:  74 65 72 72 75 70 74 73 2E D0 EE A0 A0 20 41 6E    terrupts..... An
0041C0:  20 20 69 6E 74 65 72 72 75 70 74 20 20 63 61 6E      interrupt  can
0041D0:  20 20 6F 63 63 75 72 20 61 74 20 61 6E 79 20 20      occur at any  
0041E0:  74 69 6D 65 2E 49 74 20 20 20 66 6F 6C 6C 6F 77    time.It   follow
0041F0:  73 20 20 20 74 68 65 72 65 66 6F 72 65 20 20 74    s   therefore  t
004200:  68 61 74 20 20 20 69 66 20 20 74 68 65 69 6E 74    hat   if  theint
004210:  65 72 72 75 70 74 65 64 20 20 70 72 6F 67 72 61    errupted  progra
004220:  6D 20 69 73 20 74 6F 20 62 65 20 20 63 6F 6E 74    m is to be  cont
004230:  69 6E 75 65 64 28 20 69 2E 65 2E 20 62 65 20 72    inued( i.e. be r
004240:  65 2D 65 6E 74 65 72 65 64 20 29 2C 20 20 74 68    e-entered ),  th
004250:  65 20 63 6F 6E 74 65 6E 74 73 20 6F 66 61 6E 79    e contents ofany
004260:  20 72 65 67 69 73 74 65 72 20 74 68 61 74 20 74     register that t
004270:  68 65 20 20 69 6E 74 65 72 72 75 70 74 20 72 6F    he  interrupt ro
004280:  75 74 69 6E 65 75 73 65 73 20 20 6D 75 73 74 20    utineuses  must 
004290:  20 62 65 20 73 74 6F 72 65 64 20 6F 72 20 70 75     be stored or pu
0042A0:  73 68 65 64 20 6F 6E 74 6F 20 74 68 65 73 74 61    shed onto thesta
0042B0:  63 6B 2C 20 61 6E 64 20 72 65 6C 82 2C 6F 61 64    ck, and rel.,oad
0042C0:  65 64 20 6F 72 20 50 4F 50 70 65 64 20 20 66 72    ed or POPped  fr
0042D0:  6F 6D 20 20 74 68 65 73 74 61 63 6B 20 62 65 66    om  thestack bef
0042E0:  6F 72 65 20 72 65 74 75 72 6E 69 6E 67 A3 20 54    ore returning£ T
0042F0:  6F 20 20 65 6E 73 75 72 65 20 20 74 68 61 74 20    o  ensure  that 
004300:  20 20 6E 6F 20 20 6F 74 68 65 72 20 20 69 6E 74      no  other  int
004310:  65 72 72 75 70 74 6F 63 63 75 72 73 20 64 75 72    erruptoccurs dur
004320:  69 6E 67 20 74 68 69 73 20 70 65 72 69 6F 64 20    ing this period 
004330:  61 6E 64 20 20 74 68 65 72 65 66 6F 72 65 63 6F    and  thereforeco
004340:  72 72 75 70 74 73 20 20 74 68 65 20 20 72 65 67    rrupts  the  reg
004350:  69 73 74 65 72 20 20 63 6F 6E 74 65 6E 74 73 20    ister  contents 
004360:  62 65 66 6F 72 65 74 68 65 79 20 20 20 61 72 65    beforethey   are
004370:  20 20 73 61 66 65 2C 20 20 74 68 65 20 20 69 6E      safe,  the  in
004380:  74 65 72 72 75 70 74 73 20 20 20 61 72 65 64 69    terrupts   aredi
004390:  61 62 6C 65 64 20 64 75 72 69 6E 67 20 74 68 65    abled during the
0043A0:  73 65 20 6F 70 65 72 61 74 69 6F 6E 73 2E A3 20    se operations.£ 
0043B0:  57 65 20 20 6D 75 73 74 20 20 20 72 65 66 8A 74    We  must   ref.t
0043C0:  75 72 6E 20 20 66 72 6F 6D 20 20 61 6E 20 20 20    urn  from  an   
0043D0:  69 6E 74 65 72 72 75 70 74 72 6F 75 74 69 6E 65    interruptroutine
0043E0:  20 20 77 69 74 68 20 20 20 74 68 65 20 20 69 6E      with   the  in
0043F0:  73 74 72 75 63 74 69 6F 6E 20 20 20 20 52 45 54    struction    RET
004400:  49 28 20 52 45 54 75 72 6E 20 66 72 6F 6D 20 49    I( RETurn from I
004410:  6E 74 65 72 72 75 70 74 20 29 20 61 6E 64 20 6E    nterrupt ) and n
004420:  6F 74 20 52 45 54 2E A0 A0 20 48 65 6E 63 65 20    ot RET... Hence 
004430:  69 6E 74 65 72 72 75 70 74 20 72 6F 75 74 69 6E    interrupt routin
004440:  65 20 74 61 6B 65 20 74 68 65 20 66 6F 72 6D 3A    e take the form:
004450:  2D A0 28 31 29 20 45 6E 74 65 72 20 6D 61 73 6B    -.(1) Enter mask
004460:  61 62 6C 65 20 69 6E 74 65 72 72 75 70 74 2C 20    able interrupt, 
004470:  69 6E 74 65 72 72 75 70 74 73 20 20 20 20 61 72    interrupts    ar
004480:  65 20 64 69 73 61 62 6C 65 64 20 61 74 20 74 68    e disabled at th
004490:  69 73 20 74 69 6D 65 2E A0 28 32 29 20 50 55 53    is time..(2) PUS
0044A0:  48 20 6F 72 20 45 58 63 68 61 6E 67 65 20 72 65    H or EXchange re
0044B0:  71 75 69 72 65 64 20 72 65 67 69 73 74 65 72 15    quired register.
0044C0:  29 65 64 28 33 29 20 45 6E 61 62 6C 65 73 20 69    )ed(3) Enables i
0044D0:  6E 74 65 72 72 75 70 74 20 69 66 20 72 65 71 75    nterrupt if requ
0044E0:  69 72 65 64 2E A0 28 34 29 20 44 6F 20 69 6E 74    ired..(4) Do int
0044F0:  65 72 72 75 70 74 20 72 6F 75 74 69 6E 65 2E A0    errupt routine..
004500:  28 35 29 20 44 69 73 61 62 6C 65 20 69 6E 74 65    (5) Disable inte
004510:  72 72 75 70 74 20 69 66 20 72 65 71 75 69 72 65    rrupt if require
004520:  64 2E A0 28 36 29 20 50 4F 50 20 6F 72 20 45 58    d..(6) POP or EX
004530:  63 68 61 6E 67 65 20 72 65 67 69 73 74 65 72 73    change registers
004540:  2E A0 28 37 29 20 45 6E 61 62 6C 65 73 20 69 6E    ..(7) Enables in
004550:  74 65 72 72 75 70 74 73 A0 28 38 29 20 52 65 74    terrupts.(8) Ret
004560:  75 72 6E 20 66 72 6F 6D 20 69 6E 74 65 72 72 75    urn from interru
004570:  70 74 20 28 52 45 54 49 29 2E A3 20 54 68 69 73    pt (RETI).£ This
004580:  20 20 20 63 6F 6D 70 6C 65 74 65 73 20 20 61 20       completes  a 
004590:  20 73 74 75 64 79 20 20 6F 66 20 20 61 6C 6C 20     study  of  all 
0045A0:  74 68 65 69 6E 73 74 72 75 63 74 69 6F 6E 73 20    theinstructions 
0045B0:  61 76 61 69 6C 61 62 6C 65 20 6F 6E 20 74 68 65    available on the
0045C0:  20 F7 21 5A 38 30 20 63 68 69 70 2E A0 20 59 6F     .!Z80 chip.. Yo
0045D0:  75 20 20 73 68 6F 75 6C 64 20 20 6E 6F 77 20 20    u  should  now  
0045E0:  62 65 20 20 61 62 6C 65 20 74 6F 20 75 73 65 20    be  able to use 
0045F0:  6F 74 68 65 72 61 73 73 65 6D 62 6C 65 72 73 20    otherassemblers 
004600:  20 74 6F 20 20 77 72 69 74 65 20 79 6F 75 72 20     to  write your 
004610:  6F 77 6E 20 70 72 6F 67 72 61 6D 73 2E 59 6F 75    own programs.You
004620:  20 20 77 69 6C 6C 20 20 66 69 6E 64 20 20 74 68      will  find  th
004630:  61 74 20 20 6D 6F 73 74 20 20 61 72 65 20 20 6E    at  most  are  n
004640:  6F 74 20 73 6F 75 73 65 72 20 66 72 69 65 6E 64    ot souser friend
004650:  6C 79 2C 20 20 61 6E 64 20 20 74 68 61 74 20 20    ly,  and  that  
004660:  79 6F 75 20 20 77 69 6C 6C 20 6E 6F 74 62 65 20    you  will notbe 
004670:  20 61 62 6C 65 20 20 74 6F 20 20 6F 6E 65 20 20     able  to  one  
004680:  73 74 65 70 20 20 65 61 73 69 6C 79 20 20 74 68    step  easily  th
004690:  72 6F 75 67 68 69 6E 73 74 72 75 63 74 69 6F 6E    roughinstruction
0046A0:  73 2E 20 20 20 44 6F 6E 27 74 20 20 64 65 73 70    s.   Don't  desp
0046B0:  61 69 72 2E 20 20 59 6F 75 20 63 61 6E 61 6C 77    air.  You canalw
0046C0:  61 79 73 98 D6 20 20 72 65 74 75 72 6E 20 74 6F    ays..  return to
0046D0:  20 74 68 69 73 20 54 75 74 6F 72 20 74 6F 20 73     this Tutor to s
0046E0:  69 6D 75 6C 61 74 65 79 6F 75 72 20 70 72 6F 62    imulateyour prob
0046F0:  6C 65 6D 2E A0 20 53 69 6E 63 65 20 74 68 65 20    lem.. Since the 
004700:  20 41 4D 53 54 52 41 44 20 43 50 43 20 34 36 34     AMSTRAD CPC 464
004710:  20 70 72 6F 63 65 73 73 6F 72 20 69 73 73 75 72     processor issur
004720:  72 6F 75 6E 64 65 64 20 20 77 69 74 68 20 69 6E    rounded  with in
004730:  74 65 72 66 61 63 65 20 63 68 69 70 73 20 20 41    terface chips  A
004740:  4D 53 4F 46 54 72 65 63 6F 6D 6D 65 6E 64 20 20    MSOFTrecommend  
004750:  74 68 65 20 20 6D 61 63 68 69 6E 65 20 20 63 6F    the  machine  co
004760:  64 65 20 70 72 6F 67 72 61 6D 6D 65 72 74 6F 20    de programmerto 
004770:  20 61 64 64 72 65 73 73 20 20 74 68 65 73 65 20     address  these 
004780:  20 64 65 76 69 63 65 73 20 20 74 68 72 6F 75 67     devices  throug
004790:  68 20 74 68 65 73 6F 66 74 77 61 72 65 20 20 72    h thesoftware  r
0047A0:  65 73 69 64 65 6E 74 20 20 77 69 74 68 69 6E 20    esident  within 
0047B0:  74 68 65 20 52 4F 4D 73 2E 20 54 68 65 41 4D 53    the ROMs. TheAMS
0047C0:  54 52 41 44 20 09 4A 43 50 43 34 36 34 20 46 49    TRAD .JCPC464 FI
0047D0:  52 4D 57 41 52 45 20 4D 41 4E 55 41 4C 20 70 75    RMWARE MANUAL pu
0047E0:  62 6C 69 73 68 65 64 62 79 20 41 4D 53 4F 46 54    blishedby AMSOFT
0047F0:  20 64 65 66 69 6E 65 73 20 69 6E 20 64 65 74 61     defines in deta
004800:  69 6C 20 6E 6F 74 20 6F 6E 6C 79 20 74 68 65 76    il not only thev
004810:  61 72 69 6F 75 73 20 43 41 4C 4C 73 20 20 61 76    arious CALLs  av
004820:  61 69 6C 61 62 6C 65 20 20 62 75 74 20 20 74 68    ailable  but  th
004830:  65 20 74 6F 74 61 6C 73 79 73 74 65 6D 20 73 74    e totalsystem st
004840:  72 75 63 74 75 72 65 2E A3 A0 A0 A0 A0 A0 A0 A0    ructure.£.......
004850:  A0 A0 A0 20 20 20 47 4F 4F 44 20 20 4C 55 43 4B    ...   GOOD  LUCK
004860:  20 20 61 6E 64 20 48 41 50 50 59 20 20 50 52 4F      and HAPPY  PRO
004870:  47 52 41 4D 4D 49 4E 47 A3 20 20 20 20 20 20 20    GRAMMING£       
004880:  20 20 20 20 20 20 49 4E 54 52 4F 44 55 43 54 49          INTRODUCTI
004890:  4F 4E A0 A0 20 54 68 65 20 20 66 69 6E 61 6C 20    ON.. The  final 
0048A0:  20 73 65 74 20 20 6F 66 20 20 6C 65 73 73 6F 6E     set  of  lesson
0048B0:  73 20 69 6E 74 72 6F 64 75 63 65 73 6D 6F 72 65    s introducesmore
0048C0:  20 73 70 65 63 69 61 62 C6 6C 69 73 65 64 20 72     speciab.lised r
0048D0:  65 67 69 73 74 65 72 73 20 61 6E 64 20 69 6E 73    egisters and ins
0048E0:  74 72 75 63 74 2D 69 6F 6E 73 2C 20 20 61 6E 64    truct-ions,  and
0048F0:  20 20 6C 6F 6F 6B 73 20 61 74 20 74 68 65 20 77      looks at the w
004900:  61 79 20 74 68 65 20 5A 38 30 20 63 61 6E 74 61    ay the Z80 canta
004910:  6C 6B 20 77 69 74 68 20 74 68 65 20 6F 75 74 73    lk with the outs
004920:  69 64 65 20 77 6F 72 6C 64 2E A0 A0 20 54 68 65    ide world... The
004930:  20 6C 61 73 74 20 6C 65 73 73 6F 6E 73 20 64 65     last lessons de
004940:  61 6C 20 77 69 74 68 20 69 6E 73 74 72 75 63 74    al with instruct
004950:  69 6F 6E 73 74 68 61 74 20 20 20 61 6C 6C 6F 77    ionsthat   allow
004960:  20 20 20 74 68 65 20 20 20 6F 75 74 73 69 64 65       the   outside
004970:  20 20 77 6F 72 6C 64 20 20 20 74 6F 69 6E 74 65      world   tointe
004980:  72 72 75 70 74 20 74 68 65 20 70 72 6F 63 65 73    rrupt the proces
004990:  73 6F 72 2E A3 20 20 20 20 20 20 20 20 20 20 20    sor.£           
0049A0:  20 4C 45 53 53 4F 4E 53 20 20 32 36 20 2D 20 33     LESSONS  26 - 3
0049B0:  35 A0 A0 20 32 36 2E 20 20 54 68 65 20 69 6E 64    5.. 26.  The ind
0049C0:  65 78 20 72 65 67 69 73 74 62 77 65 72 73 A0 20    ex registbwers. 
0049D0:  20 20 20 20 20 20 20 20 20 20 20 20 45 78 20 2D                Ex -
0049E0:  20 75 73 65 20 6F 66 20 69 6E 64 65 78 20 72 65     use of index re
0049F0:  67 69 73 74 65 72 73 20 32 37 2E 20 20 54 68 65    gisters 27.  The
004A00:  20 61 6C 74 65 72 6E 61 74 69 76 65 20 73 65 74     alternative set
004A10:  20 6F 66 20 72 65 67 69 73 74 65 72 73 A0 20 20     of registers.  
004A20:  20 20 20 20 20 20 20 20 20 20 20 45 78 20 2D 20               Ex - 
004A30:  75 73 69 6E 67 20 61 6C 74 65 72 6E 61 74 69 76    using alternativ
004A40:  65 20 73 65 74 A0 20 32 38 2E 20 20 49 6E 70 75    e set. 28.  Inpu
004A50:  74 2F 4F 75 74 70 75 74 20 69 6E 73 74 72 75 63    t/Output instruc
004A60:  74 69 6F 6E 73 A0 20 20 20 20 20 20 20 20 20 20    tions.          
004A70:  20 20 20 45 78 20 2D 20 49 2F 4F 20 69 6E 73 74       Ex - I/O inst
004A80:  72 75 63 74 69 6F 6E 73 A0 20 32 39 2E 20 20 42    ructions. 29.  B
004A90:  6C 6F 63 6B 20 69 6E 73 74 72 75 63 74 69 6F 6E    lock instruction
004AA0:  73 20 2D 20 69 6E 74 72 6F 64 75 63 74 69 6F 6E    s - introduction
004AB0:  A0 20 33 30 2E 20 20 42 6C 6F 63 6B 20 74 72 61    . 30.  Block tra
004AC0:  6E 66 65 72 20 69 6E 73 74 72 75 13 CB 63 74 69    nfer instru..cti
004AD0:  6F 6E 73 A0 20 20 20 20 20 20 20 20 20 20 20 20    ons.            
004AE0:  20 45 78 20 2D 20 62 6C 6F 63 6B 20 74 72 61 6E     Ex - block tran
004AF0:  73 66 65 72 A0 20 33 31 2E 20 20 42 6C 6F 63 6B    sfer. 31.  Block
004B00:  20 73 65 61 72 63 68 20 69 6E 73 74 72 75 63 74     search instruct
004B10:  69 6F 6E 73 A0 20 20 20 20 20 20 20 20 20 20 20    ions.           
004B20:  20 20 45 78 20 2D 20 62 6C 6F 63 6B 20 73 65 61      Ex - block sea
004B30:  72 63 68 A0 20 33 32 2E 20 20 42 6C 6F 63 6B 20    rch. 32.  Block 
004B40:  49 2F 4F 20 69 6E 73 74 72 75 63 74 69 6F 6E 73    I/O instructions
004B50:  A0 20 33 33 2E 20 20 50 72 6F 63 65 73 73 6F 72    . 33.  Processor
004B60:  20 63 6F 6E 74 72 6F 6C 20 69 6E 73 74 72 75 63     control instruc
004B70:  74 69 6F 6E 73 A0 20 20 20 20 20 20 20 20 20 20    tions.          
004B80:  20 20 20 45 78 20 2D 20 63 6F 6E 74 72 6F 6C 20       Ex - control 
004B90:  69 6E 73 74 72 75 63 74 69 6F 6E 73 A0 20 33 34    instructions. 34
004BA0:  2E 20 20 49 6E 74 65 72 72 75 70 74 73 A0 20 33    .  Interrupts. 3
004BB0:  35 2E 20 20 46 69 6E 61 6C 65 A0 20 20 20 20 20    5.  Finale.     
004BC0:  20 4C 6F 61 64 20 65 61 72 6C 69 65 72 1D A6 20     Load earlier.. 
004BD0:  6C 65 73 73 6F 6E 73 20 66 6F 72 20 72 65 76 69    lessons for revi
004BE0:  73 69 6F 6E A3 41 20 20 76 65 72 79 69 6D 70 6F    sion£A  veryimpo
004BF0:  72 74 61 6E 74 20 70 6F 69 6E 74 2E A0 A0 20 54    rtant point... T
004C00:  68 65 20 6C 61 72 67 65 73 74 20 70 6F 73 69 74    he largest posit
004C10:  69 76 65 20 6E 75 6D 62 65 72 20 77 65 20 63 61    ive number we ca
004C20:  6E 20 68 6F 6C 64 69 6E 20 20 61 20 20 20 73 69    n holdin  a   si
004C30:  6E 67 6C 65 20 20 20 72 65 67 69 73 74 65 72 2C    ngle   register,
004C40:  20 20 75 73 69 6E 67 20 20 20 74 68 69 73 6E 6F      using   thisno
004C50:  74 61 74 69 6F 6E 20 69 73 20 20 30 31 31 31 31    tation is  01111
004C60:  31 31 31 20 20 20 6F 72 20 20 31 32 37 20 20 61    111   or  127  a
004C70:  6E 64 20 74 68 65 6C 61 72 67 65 73 74 20 20 6E    nd thelargest  n
004C80:  65 67 61 74 69 76 65 20 20 20 6E 75 6D 62 65 72    egative   number
004C90:  20 20 31 30 30 30 30 30 30 30 20 20 6F 72 2D 31      10000000  or-1
004CA0:  32 38 2E A3 20 54 68 65 20 20 5A 38 30 20 20 68    28.£ The  Z80  h
004CB0:  61 73 20 74 77 6F 20 69 6E 73 74 72 75 63 74 69    as two instructi
004CC0:  6F 6E 73 20 74 68 61 74 20 6D 61 79 62 65 20 BD    ons that maybe .
004CD0:  9D 75 73 65 64 20 66 6F 72 20 74 68 65 73 65 20    .used for these 
004CE0:  6F 70 65 72 61 74 69 6F 6E 73 A0 A0 20 43 50 4C    operations.. CPL
004CF0:  20 20 20 63 6F 6D 70 6C 65 6D 65 6E 74 73 20 20       complements  
004D00:  20 20 6F 72 20 20 20 69 6E 76 65 72 74 73 20 20      or   inverts  
004D10:  20 74 68 65 20 20 20 20 20 20 20 63 6F 6E 74 65     the       conte
004D20:  6E 74 73 20 6F 66 20 74 68 65 20 41 63 63 75 6D    nts of the Accum
004D30:  75 6C 61 74 6F 72 2E A0 A0 20 4E 45 47 20 20 20    ulator... NEG   
004D40:  6E 65 67 61 74 65 73 2C 20 20 6F 72 20 6D 61 6B    negates,  or mak
004D50:  65 73 20 20 6E 65 67 61 74 69 76 65 2C 20 74 68    es  negative, th
004D60:  65 20 20 20 20 20 20 20 63 6F 6E 74 65 6E 74 73    e       contents
004D70:  20 20 6F 66 20 20 74 68 65 20 20 41 63 63 75 6D      of  the  Accum
004D80:  75 6C 61 74 6F 72 20 62 79 20 20 20 20 20 20 20    ulator by       
004D90:  63 6F 6D 70 6C 65 6D 65 6E 74 69 6E 67 20 61 6E    complementing an
004DA0:  64 20 61 64 64 69 6E 67 20 31 20 69 6E 20 6F 6E    d adding 1 in on
004DB0:  65 20 20 20 20 20 20 20 6F 70 65 72 61 74 69 6F    e       operatio
004DC0:  6E 2E A0 A0 20 41 20 53 69 67 6E 20 66 6C 61 67    n... A Sign flag
004DD0:  20 46 52 28 53 29 20 69 73 20 70 72 6F 76 69 64     FR(S) is provid
004DE0:  65 64 20 6F 6E 20 74 68 65 20 5A 38 30 2E 49 74    ed on the Z80.It
004DF0:  20 64 75 70 6C 69 63 61 74 65 73 20 20 74 68 65     duplicates  the
004E00:  20 73 69 67 6E 20 28 20 62 69 74 20 37 20 29 20     sign ( bit 7 ) 
004E10:  6F 66 20 74 68 65 61 6E 73 77 65 72 20 61 66 74    of theanswer aft
004E20:  65 72 20 61 6E 79 20 61 72 69 74 68 6D 65 74 69    er any arithmeti
004E30:  63 20 6F 70 65 72 61 74 69 6F 6E 20 6F 6E 74 68    c operation onth
004E40:  65 20 41 63 63 75 6D 75 6C 61 74 6F 72 2E 20 20    e Accumulator.  
004E50:  54 68 65 20 20 73 69 67 6E 20 20 66 6C 61 67 20    The  sign  flag 
004E60:  69 73 20 22 30 22 66 6F 72 20 20 61 20 20 70 6F    is "0"for  a  po
004E70:  73 69 74 69 76 65 20 20 72 65 73 75 6C 74 20 20    sitive  result  
004E80:  61 6E 64 20 20 22 31 22 20 66 6F 72 20 61 6E 65    and  "1" for ane
004E90:  67 61 74 69 76 65 20 72 65 73 75 6C 74 2E A3 20    gative result.£ 
004EA0:  57 68 65 6E 20 70 65 72 66 6F 72 6D 69 6E 67 20    When performing 
004EB0:  20 61 72 69 74 68 6D 65 74 69 63 20 20 6F 70 65     arithmetic  ope
004EC0:  72 61 74 69 6F 6E 73 77 68 69 63 68 20 20 77 65    rationswhich  we
004ED0:  20 20 77 A4 87 69 73 68 20 20 74 6F 20 69 6E 74      w..ish  to int
004EE0:  65 72 70 72 65 74 20 77 69 74 68 69 6E 20 74 68    erpret within th
004EF0:  65 72 61 6E 67 65 20 20 2D 31 32 38 20 74 6F 20    erange  -128 to 
004F00:  2B 31 32 37 2C 20 74 68 65 20 43 61 72 72 79 20    +127, the Carry 
004F10:  20 66 6C 61 67 20 20 6E 6F 6C 6F 6E 67 65 72 20     flag  nolonger 
004F20:  20 73 69 67 6E 61 6C 73 20 20 61 6E 20 6F 75 74     signals  an out
004F30:  20 6F 66 20 72 61 6E 67 65 20 72 65 73 75 6C 74     of range result
004F40:  2E 48 6F 77 65 76 65 72 20 61 6E 6F 74 68 65 72    .However another
004F50:  20 66 6C 61 67 2C 20 74 68 65 20 6F 76 65 72 66     flag, the overf
004F60:  6C 6F 77 20 28 50 2F 56 29 66 6C 61 67 20 20 64    low (P/V)flag  d
004F70:  6F 65 73 2E 20 20 49 74 20 20 69 73 20 20 61 20    oes.  It  is  a 
004F80:  20 22 31 22 20 77 68 65 6E 65 76 65 72 20 74 68     "1" whenever th
004F90:  65 61 6E 73 77 65 72 20 69 73 20 6F 75 74 73 69    eanswer is outsi
004FA0:  64 65 20 74 68 65 20 72 61 6E 67 65 20 2D 31 32    de the range -12
004FB0:  38 20 74 6F 20 2B 31 32 37 61 6E 64 20 20 22 30    8 to +127and  "0
004FC0:  22 20 20 77 69 74 68 69 6E 20 20 20 74 68 65 20    "  within   the 
004FD0:  20 20 72 61 6E D5 E9 67 65 2E 20 20 20 49 74 20      ran..ge.   It 
004FE0:  20 69 73 65 66 66 65 63 74 69 76 65 6C 79 20 20     iseffectively  
004FF0:  61 20 20 63 61 72 72 79 20 20 69 6E 74 6F 20 20    a  carry  into  
005000:  62 69 74 20 37 20 77 68 69 63 68 77 6F 75 6C 64    bit 7 whichwould
005010:  20 6D 61 6B 65 20 74 68 65 20 73 69 67 6E 20 62     make the sign b
005020:  69 74 20 69 6E 63 6F 72 72 65 63 74 2E A3 20 54    it incorrect.£ T
005030:  68 65 72 65 20 20 69 73 20 20 6E 6F 20 20 72 65    here  is  no  re
005040:  61 73 6F 6E 20 66 6F 72 20 73 74 69 63 6B 69 6E    ason for stickin
005050:  67 20 74 6F 20 38 62 69 74 73 20 20 75 73 69 6E    g to 8bits  usin
005060:  67 20 74 68 69 73 20 6D 65 74 68 6F 64 2E 20 20    g this method.  
005070:  53 6F 20 6C 6F 6E 67 20 61 73 20 74 68 65 6E 75    So long as thenu
005080:  6D 62 65 72 20 6F 66 20 20 62 69 74 73 20 69 73    mber of  bits is
005090:  20 20 73 75 66 66 69 63 69 65 6E 74 20 20 61 6E      sufficient  an
0050A0:  64 20 20 74 68 65 6D 6F 73 74 20 20 73 69 67 6E    d  themost  sign
0050B0:  69 66 69 63 61 6E 74 20 20 62 69 74 20 20 69 73    ificant  bit  is
0050C0:  20 20 74 61 6B 65 6E 20 61 73 20 74 68 65 73 69      taken as thesi
0050D0:  67 6E 20 20 62 69 74 03 EF 20 20 61 6E 79 20 73    gn  bit..  any s
0050E0:  69 7A 65 20 70 6F 73 69 74 69 76 65 20 6F 72 20    ize positive or 
0050F0:  6E 65 67 61 74 69 76 65 6E 75 6D 62 65 72 20 63    negativenumber c
005100:  61 6E 20 62 65 20 72 65 70 72 65 73 65 6E 74 65    an be represente
005110:  64 2E A0 A0 20 50 65 72 66 6F 72 6D 69 6E 67 20    d... Performing 
005120:  61 20 73 69 6D 69 6C 61 72 20 63 61 6C 63 75 6C    a similar calcul
005130:  61 74 69 6F 6E 20 74 6F 20 74 68 65 61 62 6F 76    ation to theabov
005140:  65 20 20 77 65 20 63 61 6E 20 20 73 68 6F 77 20    e  we can  show 
005150:  74 68 61 74 20 61 20 72 65 67 69 73 74 65 72 20    that a register 
005160:  70 61 69 72 63 61 6E 20 20 72 65 70 72 65 73 65    paircan  represe
005170:  6E 74 20 20 61 20 20 6E 75 6D 62 65 72 20 20 69    nt  a  number  i
005180:  6E 20 74 68 65 20 20 72 61 6E 67 65 2B 33 32 37    n the  range+327
005190:  36 37 20 74 6F 20 2D 33 32 37 36 38 2E A0 A0 20    67 to -32768... 
0051A0:  54 68 65 20 20 53 69 67 6E 20 61 6E 64 20 20 6F    The  Sign and  o
0051B0:  76 65 72 66 6C 6F 77 20 20 66 6C 61 67 73 20 61    verflow  flags a
0051C0:  72 65 20 61 6C 73 6F 6F 70 65 72 61 74 69 76 65    re alsooperative
0051D0:  20 61 66 74 65 72 20 20 41 76 5B 44 43 20 61 6E     after  Av[DC an
0051E0:  64 20 53 42 43 20 69 6E 73 74 72 75 63 74 69 6F    d SBC instructio
0051F0:  6E 6F 6E 20 74 68 65 20 48 4C 20 72 65 67 69 73    non the HL regis
005200:  74 65 72 2E 20 49 74 20 72 65 66 6C 65 63 74 73    ter. It reflects
005210:  20 74 68 65 20 31 35 74 68 62 69 74 20 28 6F 72     the 15thbit (or
005220:  20 62 69 74 20 37 20 6F 66 20 48 20 72 65 67 69     bit 7 of H regi
005230:  73 74 65 72 29 20 2E A3 20 49 74 20 69 73 20 69    ster) .£ It is i
005240:  6D 70 6F 72 74 61 6E 74 20 20 74 6F 20 20 72 65    mportant  to  re
005250:  6D 65 6D 62 65 72 20 20 74 68 61 74 20 74 68 65    member  that the
005260:  5A 65 72 6F 2C 20 20 43 61 72 72 79 2C 20 20 53    Zero,  Carry,  S
005270:  69 67 6E 2C 20 61 6E 64 20 20 6F 76 65 72 66 6C    ign, and  overfl
005280:  6F 77 20 66 6C 61 67 73 61 72 65 20 61 6C 77 61    ow flagsare alwa
005290:  79 73 20 6F 70 65 72 61 74 69 76 65 20 20 61 66    ys operative  af
0052A0:  74 65 72 20 20 61 6E 20 20 20 38 20 20 62 69 74    ter  an   8  bit
0052B0:  61 72 69 74 68 6D 65 74 69 63 20 20 69 6E 73 74    arithmetic  inst
0052C0:  72 75 63 74 69 6F 6E 20 20 20 6F 72 20 20 61 20    ruction   or  a 
0052D0:  20 31 36 20 20 62 69 74 61 64 64 14 8F 69 74 69     16  bitadd..iti
0052E0:  6F 6E 20 20 20 69 6E 76 6F 6C 76 69 6E 67 20 20    on   involving  
0052F0:  20 74 68 65 20 20 43 61 72 72 79 2E 20 20 59 6F     the  Carry.  Yo
005300:  75 72 69 6E 74 65 72 70 72 65 74 61 74 69 6F 6E    urinterpretation
005310:  20 6F 66 20 74 68 65 20 20 72 65 73 75 6C 74 20     of the  result 
005320:  64 65 74 65 72 6D 69 6E 65 73 69 6E 20 20 20 77    determinesin   w
005330:  68 69 63 68 20 20 20 66 6C 61 67 28 73 29 20 20    hich   flag(s)  
005340:  20 79 6F 75 20 20 20 73 68 6F 75 6C 64 20 20 20     you   should   
005350:  62 65 69 6E 74 65 72 65 73 74 65 64 20 69 6E 2E    beinterested in.
005360:  A3 20 20 20 20 45 58 41 4D 50 4C 45 53 20 4F 46    £    EXAMPLES OF
005370:  20 2B 56 45 20 41 4E 44 20 2D 56 45 20 4E 4F 54     +VE AND -VE NOT
005380:  41 54 49 4F 4E A0 A0 20 41 6C 74 68 6F 75 67 68    ATION.. Although
005390:  20 20 74 68 65 73 65 20 20 65 78 61 6D 70 6C 65      these  example
0053A0:  73 20 20 61 70 70 65 61 72 20 74 6F 20 62 65 61    s  appear to bea
0053B0:  6C 6C 20 70 6F 73 69 74 69 76 65 2C 20 74 68 65    ll positive, the
0053C0:  79 20 63 61 6E 20 62 65 20 76 69 65 77 65 64 20    y can be viewed 
0053D0:  65 71 75 61 6C 6C 79 61 73 20 20 6E 65 65 25 67    equallyas  nee%g
0053E0:  61 74 69 76 65 20 20 77 68 65 72 65 20 61 70 70    ative  where app
0053F0:  72 6F 70 72 69 61 74 65 20 61 6E 64 20 20 74 68    ropriate and  th
005400:  65 53 69 67 6E 20 20 20 61 6E 64 20 20 20 6F 76    eSign   and   ov
005410:  65 72 66 6C 6F 77 20 20 20 66 6C 61 67 73 20 20    erflow   flags  
005420:  20 6F 62 73 65 72 76 65 64 6F 70 65 72 61 74 69     observedoperati
005430:  6E 67 2E A0 A0 20 52 65 6D 65 6D 62 65 72 20 20    ng... Remember  
005440:  61 20 20 20 6E 75 6D 62 65 72 20 20 20 61 62 6F    a   number   abo
005450:  76 65 20 20 20 31 32 38 20 20 20 69 73 6E 65 67    ve   128   isneg
005460:  61 74 69 76 65 2E 20 53 69 6E 63 65 20 61 6C 6C    ative. Since all
005470:  20 74 68 65 20 6E 65 67 61 74 69 76 65 20 6E 75     the negative nu
005480:  6D 62 65 72 73 69 6E 20 74 68 65 20 65 78 61 6D    mbersin the exam
005490:  70 6C 65 73 20 61 72 65 20 73 6D 61 6C 6C 2C 20    ples are small, 
0054A0:  20 74 68 65 79 20 20 63 61 6E 20 62 65 73 65 65     they  can besee
0054B0:  6E 20 71 75 69 63 6B 6C 79 20 61 6E 64 20 73 69    n quickly and si
0054C0:  6D 70 6C 79 20 62 65 20 63 6F 6E 76 65 72 74 65    mply be converte
0054D0:  64 20 20 62 79 73 75 62 74 72 61 63 74 69 6E 7F    d  bysubtractin.
0054E0:  53 67 20 74 68 65 20 6E 75 6D 62 65 72 20 66 72    Sg the number fr
0054F0:  6F 6D 20 32 35 36 2E A0 A0 20 69 2E 65 2E 20 20    om 256... i.e.  
005500:  2D 32 20 20 69 73 20 65 71 75 69 76 61 6C 65 6E    -2  is equivalen
005510:  74 20 74 6F 20 32 35 34 20 65 74 63 2E A3 20 4C    t to 254 etc.£ L
005520:  44 20 41 2C 32 35 34 A0 20 20 4E 45 47 A0 20 20    D A,254.  NEG.  
005530:  4E 45 47 A0 20 20 41 44 44 20 41 2C 32 A0 20 20    NEG.  ADD A,2.  
005540:  49 4E 43 20 41 A0 20 20 4C 44 20 48 4C 2C 32 A0    INC A.  LD HL,2.
005550:  20 20 4C 44 20 44 45 2C 46 46 46 45 48 A0 20 20      LD DE,FFFEH.  
005560:  41 44 44 20 48 4C 2C 44 45 A0 20 20 43 50 4C A0    ADD HL,DE.  CPL.
005570:  20 20 4C 44 20 48 4C 2C 53 54 4F 52 45 A0 20 20      LD HL,STORE.  
005580:  4C 44 20 28 48 4C 29 2C 37 46 48 A0 20 20 49 4E    LD (HL),7FH.  IN
005590:  43 20 28 48 4C 29 A0 20 20 52 45 54 A0 20 20 A0    C (HL).  RET.  .
0055A0:  20 53 54 4F 52 45 20 42 49 4E 20 30 A0 20 20 A0     STORE BIN 0.  .
0055B0:  20 38 38 12 7C 90 28 24 22 38 38 90 7C 12 28 48     88.|.($"88.|.(H
0055C0:  88 00 3C 18 3C 3C 3C 18 00 3C FF FF 18 0C 18 30    ..<.<<<..<.....0
0055D0:  18 18 3C 7E 18 18 7E 3C 18 00 24 66 FF 66 24 00    ..<~..~<..$f.f$.
0055E0:  00 2F 20 00 C9 C9 C9 C9 C9 C9 C9 C9 C9 C9 C9 C9    ./ .............
0055F0:  C9 C9 C9 C9 C9 C9 C9 C9 C9 C9 C9 C9 C9 C9 C9 00    ................
005600:  FF 00 00 FF 00 00 00 84 FF FF 00 00 00 3F 88 80    .............?..
005610:  03 00 00 FF FF 00 00 00 00 00 00 FF FF 00 08 79    ...............y
005620:  C8 FD 00 FF FF 00 00 FF FF 00 08 79 C8 FD 00 FF    ...........y....
005630:  FF 00 00 FF FF 00 08 79 C8 FD 00 FF FF 00 00 FF    .......y........
005640:  FF 00 00 FF FF 00 00 00 02 79 C8 FD FF 00 00 FF    .........y......
005650:  FF 00 00 FF FF 00 00 FF FF 00 04 79 C8 FD 00 FF    ...........y....
005660:  FF 00 00 FF FF 00 00 FF DF 00 00 00 08 79 C8 FD    .............y..
005670:  FF 00 00 FF FF 00 00 FF FF 00 00 FF FF 00 10 79    ...............y
005680:  C8 FD 00 FF FF 00 00 33 00 76 65 20 22 54 45 58    .......3.ve "TEX
005690:  54 33 22 2C 42 2C 26 35 38 30 30 2C 26 35 35 30    T3",B,&5800,&550
0056A0:  30 00 00 00 54 45 52 22 00 61 00 64 00 30 30 31    0...TER".a.d.001
0056B0:  00 00 37 39 2C 26 65 64 2C 26 37 38 2C 26 63 62    ..79,&ed,&78,&cb
0056C0:  2C 26 34 37 00 26 31 62 2C 26 37 61 2C 26 42 33    ,&47.&1b,&7a,&B3
0056D0:  20 00 66 2C 26 30 00 FF FF 00 00 FF FF 00 00 FF     .f,&0..........
0056E0:  FF 00 00 0E 4D FF FF FF FF 11 07 09 08 04 F6 04    ....M...........
0056F0:  89 04 11 09 1D 0E 08 04 0A 07 01 00 FC 00 00 00    ................
005700:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
005710:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
005720:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
005730:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
005740:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
005750:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
005760:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
005770:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
005780:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
005790:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
0057A0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
0057B0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
0057C0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
0057D0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
0057E0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
0057F0:  00 00 00 00 00 00 00 00 00 00 00 00 00 BE 17 FF    ................
005800:  FF FF FF 11 06 09 57 04 F6 04 8B 04 15 09 FF 0F    ......W.........
005810:  08 04 0A AF 55 00 FB 06 58 2E 58 EF 84 2F 58 33    ....U...X.X../X3
005820:  58 37 58 44 58 51 58 5E 58 65 58 6F 58 76 58 83    X7XDXQX^XeXoXvX.
005830:  58 8A 58 91 58 9B 58 A2 58 A9 58 B0 58 B7 58 BE    X.X.X.X.X.X.X.X.
005840:  58 C5 58 CF 58 00 00 74 87 01 00 D6 58 01 00 CB    X.X.X..t....X...
005850:  5B 00 77 5E 00 4E 61 00 76 62 01 00 CD 89 00 92    [.w^.Na.vb......
005860:  8C 00 1A 8E 02 7B 90 01 00 57 63 00 F6 65 00 EE    .....{...Wc..e..
005870:  68 00 F5 6B 01 00 26 91 02 92 93 01 00 C3 6C 00    h..k..&.......l.
005880:  7D 6F 00 F6 6F 01 00 3C 94 02 0A 95 01 00 91 70    }o..o..<.......p
005890:  00 74 73 00 B3 76 00 31 77 01 00 B9 95 02 7A 97    .ts..v.1w.....z.
0058A0:  01 00 0F 98 02 BC 98 01 00 FF 77 00 A7 7A 00 DD    ..........w..z..
0058B0:  7C 01 00 6A 99 02 93 9A 01 00 3A 9B 02 4D 9D 01    |..j......:..M..
0058C0:  00 04 7E 00 D7 80 01 00 19 9E 02 EA 9E 01 00 28    ..~............(
0058D0:  81 00 ED 82 01 00 7A 9F 02 0D A0 01 00 93 A0 00    ......z.........
0058E0:  CA A2 00 A8 A3 01 00 5D A4 02 3F A5 01 20 20 20    ....£..]..?..   
0058F0:  20 20 20 20 20 20 52 45 47 49 53 54 45 52 53 20          REGISTERS 
005900:  61 6E 64 20 4D 45 4D 4F 52 59 A0 A0 20 52 65 67    and MEMORY.. Reg
005910:  69 73 74 65 72 73 20 01 45 20 61 72 65 20 20 6C    isters .E are  l
005920:  69 6B 65 20 20 70 69 67 65 6F 6E 20 20 68 6F 6C    ike  pigeon  hol
005930:  65 73 20 20 69 6E 77 68 69 63 68 20 20 6E 75 6D    es  inwhich  num
005940:  62 65 72 73 20 20 63 61 6E 20 62 65 20 73 74 6F    bers  can be sto
005950:  72 65 64 2E 20 20 41 20 73 69 6E 67 6C 65 72 65    red.  A singlere
005960:  67 69 73 74 65 72 20 63 61 6E 20 73 74 6F 72 65    gister can store
005970:  20 20 61 6E 79 20 20 6E 75 6D 62 65 72 20 20 62      any  number  b
005980:  65 74 77 65 65 6E 30 20 61 6E 64 20 20 32 35 35    etween0 and  255
005990:  2E 20 20 54 68 65 20 20 5A 38 30 20 20 68 61 73    .  The  Z80  has
0059A0:  20 20 20 6D 61 6E 79 20 20 20 73 75 63 68 72 65       many   suchre
0059B0:  67 69 73 74 65 72 73 2E 20 20 49 6E 69 74 69 61    gisters.  Initia
0059C0:  6C 6C 79 20 20 77 65 20 73 68 61 6C 6C 20 63 6F    lly  we shall co
0059D0:  6E 73 69 64 65 72 6F 6E 6C 79 20 74 68 65 20 6D    nsideronly the m
0059E0:  6F 72 65 20 20 67 65 6E 65 72 61 6C 20 6F 6E 65    ore  general one
0059F0:  73 3A 20 20 64 65 73 69 67 6E 61 74 65 64 41 2C    s:  designatedA,
005A00:  42 2C 43 2C 44 2C 45 2C 48 20 61 6E 64 20 4C 2E    B,C,D,E,H and L.
005A10:  20 20 54 68 65 20 41 20 20 A1 AB 72 65 67 69 73      The A  ..regis
005A20:  74 65 72 20 28 20 6F 72 41 63 63 75 6D 75 6C 61    ter ( orAccumula
005A30:  74 6F 72 20 29 20 20 69 73 20 20 74 68 65 20 20    tor )  is  the  
005A40:  6D 6F 73 74 20 20 69 6D 70 6F 72 74 61 6E 74 2C    most  important,
005A50:  73 69 6E 63 65 20 20 6D 6F 72 65 20 20 69 6E 73    since  more  ins
005A60:  74 72 75 63 74 69 6F 6E 73 20 20 69 6E 76 6F 6C    tructions  invol
005A70:  76 65 20 20 74 68 69 73 72 65 67 69 73 74 65 72    ve  thisregister
005A80:  20 74 68 61 6E 20 61 6E 79 20 6F 74 68 65 72 2E     than any other.
005A90:  A0 A0 20 54 68 65 20 73 74 65 70 20 62 79 20 73    .. The step by s
005AA0:  74 65 70 20 69 6E 73 74 72 75 63 74 69 6F 6E 73    tep instructions
005AB0:  20 6D 61 6B 69 6E 67 20 75 70 61 20 70 72 6F 67     making upa prog
005AC0:  72 61 6D 20 61 72 65 20 73 74 6F 72 65 64 20 69    ram are stored i
005AD0:  6E 20 6D 65 6D 6F 72 79 2C 20 61 20 73 65 72 69    n memory, a seri
005AE0:  65 73 6F 66 20 20 20 73 69 6D 69 6C 61 72 20 20    esof   similar  
005AF0:  20 20 72 65 67 69 73 74 65 72 73 20 20 20 20 6F      registers    o
005B00:  72 20 20 20 6D 65 6D 6F 72 79 6C 6F 63 61 74 69    r   memorylocati
005B10:  6F 6E 73 20 20 65 78 74 65 72 6E CF 3B 61 6C 20    ons  extern.;al 
005B20:  20 74 6F 20 20 74 68 65 20 20 5A 38 30 20 20 63     to  the  Z80  c
005B30:  68 69 70 2E 36 35 35 33 36 20 6D 65 6D 6F 72 79    hip.65536 memory
005B40:  20 6C 6F 63 61 74 69 6F 6E 73 20 63 61 6E 20 62     locations can b
005B50:  65 20 20 61 63 63 65 73 73 65 64 2E 54 68 65 79    e  accessed.They
005B60:  20 20 61 72 65 20 20 64 65 73 69 67 6E 61 74 65      are  designate
005B70:  64 20 20 62 79 20 20 74 68 65 69 72 20 20 6E 75    d  by  their  nu
005B80:  6D 62 65 72 62 65 74 77 65 65 6E 20 30 20 61 6E    mberbetween 0 an
005B90:  64 20 36 35 35 33 35 2E 20 20 49 74 20 20 74 61    d 65535.  It  ta
005BA0:  6B 65 73 20 20 74 68 65 20 5A 38 30 6C 6F 6E 67    kes  the Z80long
005BB0:  65 72 20 20 74 6F 20 20 61 63 63 65 73 73 20 20    er  to  access  
005BC0:  6D 65 6D 6F 72 79 20 20 74 68 61 6E 20 69 74 73    memory  than its
005BD0:  20 6F 77 6E 69 6E 74 65 72 6E 61 6C 20 72 65 67     owninternal reg
005BE0:  69 73 74 65 72 73 2E A3 20 20 20 20 20 20 20 53    isters.£       S
005BF0:  49 4D 50 4C 45 20 4C 4F 41 44 20 49 4E 53 54 52    IMPLE LOAD INSTR
005C00:  55 43 54 49 4F 4E 53 A0 A0 20 50 65 72 68 61 70    UCTIONS.. Perhap
005C10:  73 20 20 61 20 20 62 65 74 74 65 72 20 27 F4 20    s  a  better '. 
005C20:  64 65 73 63 72 69 70 74 69 6F 6E 20 6F 66 20 6C    description of l
005C30:  6F 61 64 74 68 61 6E 20 74 68 65 20 63 6F 6E 76    oadthan the conv
005C40:  65 6E 74 69 6F 6E 61 6C 20 6F 6E 65 20 69 73 20    entional one is 
005C50:  63 6F 70 79 2C 20 73 69 6E 63 65 61 20 6C 6F 61    copy, sincea loa
005C60:  64 20 20 69 6E 73 74 72 75 63 74 69 6F 6E 20 20    d  instruction  
005C70:  63 6F 70 69 65 73 20 20 74 68 65 20 20 6E 75 6D    copies  the  num
005C80:  62 65 72 68 65 6C 64 20 69 6E 20 61 20 72 65 67    berheld in a reg
005C90:  69 73 74 65 72 20 20 6F 72 20 20 6D 65 6D 6F 72    ister  or  memor
005CA0:  79 20 20 6C 6F 63 61 74 69 6F 6E 69 6E 74 6F 20    y  locationinto 
005CB0:  20 20 61 6E 6F 74 68 65 72 20 20 20 20 72 65 67      another    reg
005CC0:  69 73 74 65 72 20 20 20 6F 72 20 20 20 6D 65 6D    ister   or   mem
005CD0:  6F 72 79 6C 6F 63 61 74 69 6F 6E 2E 20 20 20 41    orylocation.   A
005CE0:  73 20 20 20 77 69 74 68 20 20 61 6C 6C 20 20 63    s   with  all  c
005CF0:  6F 70 79 69 6E 67 20 20 74 68 65 6F 72 69 67 69    opying  theorigi
005D00:  6E 61 6C 20 72 65 6D 61 69 6E 73 20 75 6E 63 68    nal remains unch
005D10:  61 6E 67 65 64 2E A0 A0 20 54 68 65 20 20 20 4B    anged... The   K
005D20:  BE 6C 6F 61 64 20 20 69 6E 73 74 72 75 63 74 69    .load  instructi
005D30:  6F 6E 20 20 20 69 73 20 20 20 6E 6F 72 6D 61 6C    on   is   normal
005D40:  6C 79 61 62 62 72 65 76 69 61 74 65 64 20 74 6F    lyabbreviated to
005D50:  20 4C 44 2E 20 20 54 68 65 20 73 69 6D 70 6C 65     LD.  The simple
005D60:  73 74 20 66 6F 72 6D 20 6F 66 6C 6F 61 64 20 20    st form ofload  
005D70:  63 6F 70 69 65 73 20 64 61 74 61 20 66 72 6F 6D    copies data from
005D80:  20 20 6F 6E 65 20 20 72 65 67 69 73 74 65 72 20      one  register 
005D90:  74 6F 61 6E 6F 74 68 65 72 2C 20 69 2E 65 2E 20    toanother, i.e. 
005DA0:  4C 44 20 41 2C 42 20 20 2E A0 A0 20 49 6E 20 20    LD A,B  ... In  
005DB0:  74 68 65 73 65 20 20 61 62 62 72 65 76 69 61 74    these  abbreviat
005DC0:  69 6F 6E 65 64 20 20 69 6E 73 74 72 75 63 74 69    ioned  instructi
005DD0:  6F 6E 73 28 20 6D 6E 65 6D 6F 6E 69 63 73 20 29    ons( mnemonics )
005DE0:  2C 20 69 74 20 69 73 20 63 6F 6E 76 65 6E 74 69    , it is conventi
005DF0:  6F 6E 61 6C 20 74 6F 20 70 75 74 74 68 65 20 72    onal to putthe r
005E00:  65 67 69 73 74 65 72 20 61 66 66 65 63 74 65 64    egister affected
005E10:  20 66 69 72 73 74 2C 20 66 6F 6C 6C 6F 77 65 64     first, followed
005E20:  20 90 D0 62 79 74 68 65 20 72 65 67 69 73 74 65     ..bythe registe
005E30:  72 20 66 72 6F 6D 20 77 68 69 63 68 20 20 74 68    r from which  th
005E40:  65 20 69 6E 66 6F 72 6D 61 74 69 6F 6E 69 73 20    e informationis 
005E50:  20 63 6F 70 69 65 64 2E 20 20 20 48 65 6E 63 65     copied.   Hence
005E60:  20 20 4C 44 20 41 2C 42 20 20 63 6F 70 69 65 73      LD A,B  copies
005E70:  20 20 74 68 65 63 6F 6E 74 65 6E 74 73 20 6F 66      thecontents of
005E80:  20 42 20 69 6E 74 6F 20 41 20 6F 72 20 41 63 63     B into A or Acc
005E90:  75 6D 75 6C 61 74 6F 72 2E A3 20 57 65 20 20 63    umulator.£ We  c
005EA0:  61 6E 20 20 61 6C 73 6F 20 6C 6F 61 64 20 61 6E    an  also load an
005EB0:  79 20 6F 66 20 74 68 65 20 72 65 67 69 73 74 65    y of the registe
005EC0:  72 73 77 69 74 68 20 20 61 20 20 6E 75 6D 62 65    rswith  a  numbe
005ED0:  72 2C 20 20 6E 2C 20 62 65 74 77 65 65 6E 20 20    r,  n, between  
005EE0:  30 20 20 61 6E 64 20 32 35 35 64 69 72 65 63 74    0  and 255direct
005EF0:  6C 79 20 2C 20 20 20 77 69 74 68 20 20 20 20 69    ly ,   with    i
005F00:  6E 73 74 72 75 63 74 69 6F 6E 73 20 20 20 6C 69    nstructions   li
005F10:  6B 65 4C 44 20 43 2C 31 32 33 2E 20 57 65 20 20    keLD C,123. We  
005F20:  73 68 61 8D 52 6C 6C 20 20 64 69 73 63 75 73 73    sha.Rll  discuss
005F30:  20 6C 61 74 65 72 20 20 66 72 6F 6D 77 68 65 72     later  fromwher
005F40:  65 20 20 74 68 65 20 6E 75 6D 62 65 72 20 20 69    e  the number  i
005F50:  73 20 63 6F 70 69 65 64 2E 20 53 75 66 66 69 63    s copied. Suffic
005F60:  65 20 74 6F 73 61 79 20 61 74 20 74 68 69 73 20    e tosay at this 
005F70:  20 73 74 61 67 65 2C 20 20 20 74 68 61 74 20 20     stage,   that  
005F80:  69 6E 73 74 72 75 63 74 69 6F 6E 73 61 72 65 20    instructionsare 
005F90:  73 74 6F 72 65 64 20 61 73 20 20 6E 75 6D 62 65    stored as  numbe
005FA0:  72 73 2E 20 20 69 2E 65 2E 20 20 4C 44 20 41 2C    rs.  i.e.  LD A,
005FB0:  42 20 69 73 73 74 6F 72 65 64 20 61 73 20 20 37    B isstored as  7
005FC0:  38 2E 20 20 53 6F 6D 65 20 20 69 6E 73 74 72 75    8.  Some  instru
005FD0:  63 74 69 6F 6E 73 20 20 6C 69 6B 65 4C 44 20 41    ctions  likeLD A
005FE0:  2C 42 20 61 72 65 20 73 74 6F 72 65 64 20 61 73    ,B are stored as
005FF0:  20 6F 6E 65 20 6E 75 6D 62 65 72 2C 20 20 6F 74     one number,  ot
006000:  68 65 72 73 74 61 6B 65 20 75 70 20 74 6F 20 66    herstake up to f
006010:  6F 75 72 2E A0 A0 20 54 68 65 20 74 77 6F 20 74    our... The two t
006020:  79 70 65 73 20 E7 0D 6F 66 20 69 6E 73 74 72 75    ypes ..of instru
006030:  63 74 69 6F 6E 73 20 64 69 73 63 75 73 73 65 64    ctions discussed
006040:  28 20 4C 44 20 72 2C 72 27 20 61 6E 64 20 20 4C    ( LD r,r' and  L
006050:  44 20 72 2C 6E 20 29 20 20 63 61 6E 20 69 6E 76    D r,n )  can inv
006060:  6F 6C 76 65 20 61 6E 79 6F 66 20 74 68 65 20 20    olve anyof the  
006070:  72 65 67 69 73 74 65 72 73 20 63 6F 6E 73 69 64    registers consid
006080:  65 72 65 64 2E 20 20 4F 6E 6C 79 20 20 74 68 65    ered.  Only  the
006090:  41 20 20 72 65 67 69 73 74 65 72 20 20 20 63 61    A  register   ca
0060A0:  6E 20 20 62 65 20 20 6C 6F 61 64 65 64 20 20 77    n  be  loaded  w
0060B0:  69 74 68 20 20 74 68 65 63 6F 6E 74 65 6E 74 73    ith  thecontents
0060C0:  20 20 6F 66 20 20 61 20 20 6D 65 6D 6F 72 79 20      of  a  memory 
0060D0:  20 6C 6F 63 61 74 69 6F 6E 2E 20 20 20 54 68 65     location.   The
0060E0:  69 6E 73 74 72 75 63 74 69 6F 6E 73 20 6F 66 20    instructions of 
0060F0:  74 68 65 20 66 6F 72 6D 20 4C 44 20 41 2C 28 6E    the form LD A,(n
006100:  6E 29 20 6C 6F 61 64 73 6F 72 20 20 63 6F 70 69    n) loadsor  copi
006110:  65 73 20 20 74 68 65 20 20 20 63 6F 6E 74 65 6E    es  the   conten
006120:  74 73 20 20 20 6F 66 8A F3 20 20 20 6D 65 6D 6F    ts   of..   memo
006130:  72 79 6C 6F 63 61 74 69 6F 6E 20 6E 6E 20 20 28    rylocation nn  (
006140:  20 61 20 20 6E 75 6D 62 65 72 20 20 62 65 74 77     a  number  betw
006150:  65 65 6E 20 20 30 20 61 6E 64 36 35 35 33 35 20    een  0 and65535 
006160:  29 20 69 6E 74 6F 20 74 68 65 20 41 20 72 65 67    ) into the A reg
006170:  69 73 74 65 72 2E A3 20 57 65 20 63 61 6E 20 61    ister.£ We can a
006180:  6C 73 6F 20 6C 6F 61 64 20 61 20 6D 65 6D 6F 72    lso load a memor
006190:  79 20 6C 6F 63 61 74 69 6F 6E 20 77 69 74 68 74    y location witht
0061A0:  68 65 20 20 63 6F 6E 74 65 6E 74 73 20 20 6F 66    he  contents  of
0061B0:  20 20 74 68 65 20 20 41 63 63 75 6D 75 6C 61 74      the  Accumulat
0061C0:  6F 72 20 77 69 74 68 4C 44 20 28 6E 6E 29 2C 41    or withLD (nn),A
0061D0:  20 20 20 77 68 65 72 65 20 20 6E 6E 20 20 69 73       where  nn  is
0061E0:  20 20 74 68 65 20 6E 75 6D 62 65 72 20 6F 72 61      the number ora
0061F0:  64 64 72 65 73 73 20 6F 66 20 74 68 65 20 6D 65    ddress of the me
006200:  6D 6F 72 79 20 6C 6F 63 61 74 69 6F 6E 2E A0 A0    mory location...
006210:  20 41 6C 6C 20 20 6F 74 68 65 72 20 73 69 6E 67     All  other sing
006220:  6C 65 20 20 72 65 67 69 73 0E 0A 74 65 72 73 20    le  regis..ters 
006230:  20 63 61 6E 6E 6F 74 20 62 65 6C 6F 61 64 65 64     cannot beloaded
006240:  20 20 64 69 72 65 63 74 6C 79 20 66 72 6F 6D 20      directly from 
006250:  61 20 6D 65 6D 6F 72 79 20 6C 6F 63 61 74 69 6F    a memory locatio
006260:  6E 2E 54 77 6F 20 20 20 69 6E 73 74 72 75 63 74    n.Two   instruct
006270:  69 6F 6E 73 20 20 20 69 6E 76 6F 6C 76 69 6E 67    ions   involving
006280:  20 20 20 74 68 65 20 20 20 41 72 65 67 69 73 74       the   Aregist
006290:  65 72 20 61 72 65 20 72 65 71 75 69 72 65 64 2E    er are required.
0062A0:  A3 20 20 20 53 75 6D 6D 61 72 79 20 2D 20 4C 6F    £   Summary - Lo
0062B0:  61 64 69 6E 67 20 73 69 6E 67 6C 65 20 72 65 67    ading single reg
0062C0:  69 73 74 65 72 73 A0 A0 4C 44 20 72 2C 72 27 20    isters..LD r,r' 
0062D0:  20 20 20 77 68 65 72 65 20 72 20 61 6E 64 20 72       where r and r
0062E0:  27 20 61 72 65 20 61 6E 79 20 6F 66 20 74 68 65    ' are any of the
0062F0:  20 20 20 20 20 20 20 20 20 20 20 66 6F 6C 6C 6F               follo
006300:  77 69 6E 67 3A 20 41 2C 42 2C 43 2C 44 2C 45 2C    wing: A,B,C,D,E,
006310:  48 20 61 6E 64 20 4C 2E 4C 44 20 72 2C 6E 20 20    H and L.LD r,n  
006320:  20 20 20 77 68 65 72 65 20 6E 20 B5 09 69 73 20       where n ..is 
006330:  61 20 6E 75 6D 62 65 72 20 30 20 2D 20 32 35 35    a number 0 - 255
006340:  A0 A0 4C 44 20 41 2C 28 6E 6E 29 20 20 77 68 65    ..LD A,(nn)  whe
006350:  72 65 20 6E 6E 20 69 73 20 61 20 6E 75 6D 62 65    re nn is a numbe
006360:  72 20 20 20 30 20 74 6F A0 20 20 20 20 20 20 20    r   0 to.       
006370:  20 20 20 20 36 35 35 33 35 A0 4C 44 20 28 6E 6E        65535.LD (nn
006380:  29 2C 41 A3 20 20 20 20 20 20 20 20 20 20 20 20    ),A£            
006390:  52 45 47 49 53 54 45 52 20 50 41 49 52 53 A0 A0    REGISTER PAIRS..
0063A0:  20 54 68 65 20 66 61 63 74 20 74 68 61 74 20 20     The fact that  
0063B0:  61 20 20 73 69 6E 67 6C 65 20 20 72 65 67 69 73    a  single  regis
0063C0:  74 65 72 20 20 63 61 6E 6F 6E 6C 79 20 68 6F 6C    ter  canonly hol
0063D0:  64 20 20 6E 75 6D 62 65 72 73 20 20 75 70 20 20    d  numbers  up  
0063E0:  74 6F 20 32 35 35 20 20 61 6E 64 20 20 74 68 65    to 255  and  the
0063F0:  74 6F 74 61 6C 20 6D 65 6D 6F 72 79 20 20 61 76    total memory  av
006400:  61 69 6C 61 62 6C 65 20 20 69 73 20 75 70 20 74    ailable  is up t
006410:  6F 20 36 35 35 33 35 2C 69 73 20 61 20 6C 69 6D    o 65535,is a lim
006420:  69 74 61 74 69 6F 6E 2E 20 20 46 6F 72 30 78 20    itation.  For0x 
006430:  20 74 68 69 73 20 72 65 61 73 6F 6E 20 74 68 65     this reason the
006440:  72 65 61 72 65 20 61 20 20 77 68 6F 6C 65 20 20    reare a  whole  
006450:  73 65 74 20 6F 66 20 69 6E 73 74 72 75 63 74 69    set of instructi
006460:  6F 6E 73 20 6F 6E 20 74 68 65 5A 38 30 20 20 74    ons on theZ80  t
006470:  68 61 74 20 64 65 61 6C 20 77 69 74 68 20 20 72    hat deal with  r
006480:  65 67 69 73 74 65 72 73 20 69 6E 20 70 61 69 72    egisters in pair
006490:  73 2E 54 68 65 20 70 61 69 72 73 20 61 72 65 20    s.The pairs are 
0064A0:  20 42 43 2C 20 20 44 45 2C 20 61 6E 64 20 20 48     BC,  DE, and  H
0064B0:  4C 20 72 65 67 69 73 74 65 72 70 61 69 72 73 2E    L registerpairs.
0064C0:  A0 A0 20 54 68 65 20 74 77 6F 20 72 65 67 69 73    .. The two regis
0064D0:  74 65 72 73 20 68 6F 6C 64 20 20 64 69 66 66 65    ters hold  diffe
0064E0:  72 65 6E 74 20 70 61 72 74 73 6F 66 20 61 20 6E    rent partsof a n
0064F0:  75 6D 62 65 72 2E 20 43 6F 6E 73 69 64 65 72 20    umber. Consider 
006500:  74 68 65 20 64 65 63 69 6D 61 6C 20 6E 75 6D 62    the decimal numb
006510:  65 72 32 37 2E 20 57 65 20 20 63 61 6E 20 74 68    er27. We  can th
006520:  69 6E 6B 20 6F 66 20 74 68 69 73 20 61 73 20 20    ink of this as  
006530:  58 20 68 61 76 69 6E 67 20 74 77 6F 70 61 72 74    X having twopart
006540:  73 3B 20 74 68 65 20 68 69 67 68 20 70 61 72 74    s; the high part
006550:  20 28 20 6F 72 20 62 79 74 65 29 20 69 73 20 74     ( or byte) is t
006560:  68 65 20 32 73 69 6E 63 65 20 69 74 20 72 65 70    he 2since it rep
006570:  72 65 73 65 6E 74 73 20 20 32 2A 31 30 20 2C 20    resents  2*10 , 
006580:  74 68 65 20 6C 6F 77 20 70 61 72 74 28 20 6F 72    the low part( or
006590:  20 20 62 79 74 65 20 29 20 20 69 73 20 20 74 68      byte )  is  th
0065A0:  65 20 37 2C 20 20 20 73 69 6E 63 65 20 69 74 20    e 7,   since it 
0065B0:  6F 6E 6C 79 72 65 70 6C 65 73 65 6E 74 73 20 20    onlyreplesents  
0065C0:  37 2A 31 20 2E 20 20 54 68 65 20 20 74 6F 74 61    7*1 .  The  tota
0065D0:  6C 20 20 6E 75 6D 62 65 72 20 69 73 32 2A 31 30    l  number is2*10
0065E0:  20 2B 20 37 2A 31 20 3D 20 32 37 2E 20 20 45 61     + 7*1 = 27.  Ea
0065F0:  63 68 20 64 69 67 69 74 20 63 61 6E 20 6F 6E 6C    ch digit can onl
006600:  79 20 62 65 30 20 2D 20 39 20 20 69 2E 65 2E 20    y be0 - 9  i.e. 
006610:  31 30 20 20 64 69 66 66 65 72 65 6E 74 20 6E 75    10  different nu
006620:  6D 62 65 72 73 2E A3 20 41 20 20 73 69 6E 67 6C    mbers.£ A  singl
006630:  65 AF 00 20 72 65 67 69 73 74 65 72 20 63 61 6E    e.. register can
006640:  20 68 6F 6C 64 20 20 30 2D 32 35 35 2C 20 32 35     hold  0-255, 25
006650:  36 64 69 66 66 65 72 65 6E 74 20 20 20 6E 75 6D    6different   num
006660:  62 65 72 73 2E 20 20 20 49 66 20 20 77 65 20 20    bers.   If  we  
006670:  20 70 75 74 20 20 74 77 6F 72 65 67 69 73 74 65     put  tworegiste
006680:  72 73 20 73 69 64 65 20 62 79 20 73 69 64 65 2C    rs side by side,
006690:  20 69 2E 65 2E 20 20 48 4C 20 2C 20 74 68 65 20     i.e.  HL , the 
0066A0:  48 72 65 67 69 73 74 65 72 20 68 6F 6C 64 69 6E    Hregister holdin
0066B0:  67 20 74 68 65 20 48 69 67 68 20 62 79 74 65 20    g the High byte 
0066C0:  61 6E 64 20 74 68 65 20 4C 68 6F 6C 64 69 6E 67    and the Lholding
0066D0:  20 74 68 65 20 20 4C 6F 77 20 20 62 79 74 65 2C     the  Low  byte,
0066E0:  20 74 68 65 6E 20 77 65 20 63 61 6E 20 68 6F 6C     then we can hol
0066F0:  64 69 6E 20 74 68 65 20 72 65 67 69 73 74 65 72    din the register
006700:  20 70 61 69 72 20 20 48 2A 32 35 36 20 2B 20 4C     pair  H*256 + L
006710:  2A 31 20 69 6E 20 74 68 65 73 61 6D 65 20 77 61    *1 in thesame wa
006720:  79 20 61 73 20 32 37 20 3D 20 32 2A 31 30 20 2B    y as 27 = 2*10 +
006730:  20 37 2A E8 4F 31 2E 20 54 68 65 20 6D 61 78 69     7*.O1. The maxi
006740:  6D 75 6D 74 68 61 74 20 63 61 6E 20 20 62 65 20    mumthat can  be 
006750:  20 68 65 6C 64 20 20 69 6E 20 61 20 20 72 65 67     held  in a  reg
006760:  69 73 74 65 72 20 20 70 61 69 72 69 73 20 20 74    ister  pairis  t
006770:  68 65 72 65 66 6F 72 65 20 20 20 32 35 35 20 2A    herefore   255 *
006780:  20 32 35 36 20 2B 20 32 35 35 20 3D 20 36 35 35     256 + 255 = 655
006790:  33 35 2E 42 79 20 63 6F 6E 76 65 6E 74 69 6F 6E    35.By convention
0067A0:  20 20 74 68 65 20 20 68 69 67 68 20 20 62 79 74      the  high  byt
0067B0:  65 20 69 73 20 73 74 6F 72 65 64 69 6E 20 20 74    e is storedin  t
0067C0:  68 65 20 20 66 69 72 73 74 20 20 72 65 67 69 73    he  first  regis
0067D0:  74 65 72 20 69 6E 20 74 68 65 20 72 65 67 69 73    ter in the regis
0067E0:  74 65 72 70 61 69 72 20 6E 61 6D 65 2E A0 A0 20    terpair name... 
0067F0:  57 65 20 20 63 61 6E 20 20 6C 6F 61 64 20 61 6E    We  can  load an
006800:  79 20 6F 66 20 74 68 65 20 72 65 67 69 73 74 65    y of the registe
006810:  72 20 70 61 69 72 73 77 69 74 68 20 61 20 6E 75    r pairswith a nu
006820:  6D 62 65 72 20 62 65 74 77 65 65 6E 20 30 20 2D    mber between 0 -
006830:  20 36 35 35 33 F1 BA 35 20 64 69 72 65 63 74 6C     6553..5 directl
006840:  79 75 73 69 6E 67 20 69 6E 73 74 72 75 63 74 69    yusing instructi
006850:  6F 6E 73 20 6C 69 6B 65 20 4C 44 20 48 4C 2C 6E    ons like LD HL,n
006860:  6E 2E A0 A0 20 4A 75 73 74 20 61 73 20 77 65 20    n... Just as we 
006870:  63 61 6E 20 63 6F 6D 62 69 6E 65 20 74 77 6F 20    can combine two 
006880:  72 65 67 69 73 74 65 72 73 20 74 6F 68 6F 6C 64    registers tohold
006890:  20 6E 75 6D 62 65 72 73 20 75 70 20 74 6F 20 36     numbers up to 6
0068A0:  35 35 33 35 2C 20 77 65 20 63 61 6E 20 63 6F 6D    5535, we can com
0068B0:  62 69 6E 65 61 64 6A 61 63 65 6E 74 20 20 20 20    bineadjacent    
0068C0:  20 6D 65 6D 6F 72 79 20 20 20 20 20 6C 6F 63 61     memory     loca
0068D0:  74 69 6F 6E 73 2E 20 20 20 20 42 79 63 6F 6E 76    tions.    Byconv
0068E0:  65 6E 74 69 6F 6E 20 74 68 65 20 20 4C 6F 77 20    ention the  Low 
0068F0:  20 62 79 74 65 20 69 73 20 68 65 6C 64 20 69 6E     byte is held in
006900:  20 74 68 65 6C 6F 63 61 74 69 6F 6E 20 77 69 74     thelocation wit
006910:  68 20 74 68 65 20 4C 6F 77 65 72 20 61 64 64 72    h the Lower addr
006920:  65 73 73 2E A3 20 57 65 20 20 63 61 6E 20 20 74    ess.£ We  can  t
006930:  68 65 72 65 66 6F 72 19 C9 65 20 6C 6F 61 64 20    herefor..e load 
006940:  61 20 72 65 67 69 73 74 65 72 20 70 61 69 72 77    a register pairw
006950:  69 74 68 20 20 74 68 65 20 20 63 6F 6E 74 65 6E    ith  the  conten
006960:  74 73 20 6F 66 20 61 20 20 70 61 69 72 20 6F 66    ts of a  pair of
006970:  20 6D 65 6D 6F 72 79 6C 6F 63 61 74 69 6F 6E 73     memorylocations
006980:  2C 20 20 20 77 69 74 68 20 20 20 69 6E 73 74 72    ,   with   instr
006990:  75 63 74 69 6F 6E 73 20 20 20 20 6C 69 6B 65 4C    uctions    likeL
0069A0:  44 20 44 45 2C 28 6E 6E 29 20 2E 20 20 20 20 54    D DE,(nn) .    T
0069B0:  68 69 73 20 20 20 69 6E 73 74 72 75 63 74 69 6F    his   instructio
0069C0:  6E 20 20 20 20 69 73 65 71 75 69 76 61 6C 65 6E    n    isequivalen
0069D0:  74 20 74 6F 20 74 68 65 20 6E 6F 6E 2D 76 61 6C    t to the non-val
0069E0:  69 64 20 69 6E 73 74 72 75 63 74 69 6F 6E 73 4C    id instructionsL
0069F0:  44 20 45 2C 28 6E 6E 29 20 61 6E 64 20 20 4C 44    D E,(nn) and  LD
006A00:  20 44 2C 28 6E 6E 2B 31 29 2E A0 A0 20 53 69 6D     D,(nn+1)... Sim
006A10:  69 6C 61 72 6C 79 2C 20 20 77 65 20 63 61 6E 20    ilarly,  we can 
006A20:  6C 6F 61 64 20 74 68 65 20 63 6F 6E 74 65 6E 74    load the content
006A30:  73 20 6F 66 61 20 72 65 67 82 24 69 73 74 65 72    s ofa reg.$ister
006A40:  20 70 61 69 72 20 69 6E 74 6F 20 20 61 20 70 61     pair into  a pa
006A50:  69 72 20 20 6F 66 20 20 6D 65 6D 6F 72 79 6C 6F    ir  of  memorylo
006A60:  63 61 74 69 6F 6E 73 2C 20 20 69 2E 65 2E 20 20    cations,  i.e.  
006A70:  20 4C 44 20 28 6E 6E 29 2C 42 43 20 20 77 68 69     LD (nn),BC  whi
006A80:  63 68 20 20 69 73 65 71 75 69 76 61 6C 65 6E 74    ch  isequivalent
006A90:  20 20 20 74 6F 20 20 20 74 68 65 20 20 20 20 74       to   the    t
006AA0:  77 6F 20 20 20 6E 6F 6E 2D 76 61 6C 69 64 69 6E    wo   non-validin
006AB0:  73 74 72 75 63 74 69 6F 6E 73 20 4C 44 20 28 6E    structions LD (n
006AC0:  6E 29 2C 43 20 61 6E 64 20 20 4C 44 20 28 6E 6E    n),C and  LD (nn
006AD0:  2B 31 29 2C 42 2E 20 54 68 65 72 65 20 20 20 61    +1),B. There   a
006AE0:  72 65 20 20 6E 6F 20 20 69 6E 73 74 72 75 63 74    re  no  instruct
006AF0:  69 6F 6E 73 20 20 74 6F 20 20 6C 6F 61 64 72 65    ions  to  loadre
006B00:  67 69 73 74 65 72 20 20 70 61 69 72 73 20 20 77    gister  pairs  w
006B10:  69 74 68 20 20 74 68 65 20 20 63 6F 6E 74 65 6E    ith  the  conten
006B20:  74 73 20 20 6F 66 61 6E 6F 74 68 65 72 20 72 65    ts  ofanother re
006B30:  67 69 73 74 65 72 20 70 61 69 72 F3 6B 2E 20 20    gister pair.k.  
006B40:  54 77 6F 20 69 6E 73 74 72 75 63 74 69 6F 6E 73    Two instructions
006B50:  74 68 65 20 66 6F 72 6D 20 20 4C 44 20 72 2C 72    the form  LD r,r
006B60:  27 20 20 61 72 65 20 20 75 73 75 61 6C 6C 79 20    '  are  usually 
006B70:  20 75 73 65 64 20 74 6F 70 65 72 66 6F 72 6D 20     used toperform 
006B80:  73 75 63 68 20 61 6E 20 6F 70 65 72 61 74 69 6F    such an operatio
006B90:  6E 2E A0 A0 20 54 68 65 72 65 20 20 69 73 20 20    n... There  is  
006BA0:  6F 6E 65 20 20 69 6E 73 74 72 75 63 74 69 6F 6E    one  instruction
006BB0:  20 20 73 69 6D 69 6C 61 72 20 74 6F 74 68 69 73      similar tothis
006BC0:  20 74 79 70 65 3A 20 20 45 58 20 44 45 2C 48 4C     type:  EX DE,HL
006BD0:  2E 20 20 49 74 20 20 45 58 63 68 61 6E 67 65 73    .  It  EXchanges
006BE0:  20 74 68 65 63 6F 6E 74 65 6E 74 73 20 6F 66 20     thecontents of 
006BF0:  74 68 65 20 20 44 45 20 20 72 65 67 69 73 74 65    the  DE  registe
006C00:  72 20 20 70 61 69 72 20 77 69 74 68 74 68 65 20    r  pair withthe 
006C10:  63 6F 6E 74 65 6E 74 73 20 6F 66 20 74 68 65 20    contents of the 
006C20:  48 4C 20 72 65 67 69 73 74 65 72 20 70 61 69 72    HL register pair
006C30:  2E A3 20 20 53 75 6D 6D 61 72 79 20 2D 87 B9 20    .£  Summary -.. 
006C40:  6C 6F 61 64 69 6E 67 20 72 65 67 69 73 74 65 72    loading register
006C50:  20 70 61 69 72 73 A0 A0 4C 44 20 64 64 2C 6E 6E     pairs..LD dd,nn
006C60:  20 20 20 77 68 65 72 65 20 64 64 20 69 73 20 61       where dd is a
006C70:  6E 79 20 72 65 67 69 73 74 65 72 20 70 61 69 72    ny register pair
006C80:  20 20 20 20 20 20 20 20 20 20 20 42 43 2C 20 44               BC, D
006C90:  45 2C 20 61 6E 64 20 48 4C 2E A0 20 20 20 20 20    E, and HL..     
006CA0:  20 20 20 20 20 20 20 6E 6E 20 20 69 73 20 61 20           nn  is a 
006CB0:  6E 75 6D 62 65 72 20 30 20 2D 20 36 35 35 33 35    number 0 - 65535
006CC0:  A0 A0 4C 44 20 64 64 2C 28 6E 6E 29 A0 A0 4C 44    ..LD dd,(nn)..LD
006CD0:  20 28 6E 6E 29 2C 64 64 A0 A0 45 58 20 44 45 2C     (nn),dd..EX DE,
006CE0:  48 4C 20 20 20 20 65 78 63 68 61 6E 67 65 73 20    HL    exchanges 
006CF0:  72 65 67 69 73 74 65 72 20 63 6F 6E 74 65 6E 74    register content
006D00:  73 A3 20 20 20 20 20 20 20 20 20 49 4E 44 49 52    s£         INDIR
006D10:  45 43 54 20 41 44 44 52 45 53 53 49 4E 47 A0 A0    ECT ADDRESSING..
006D20:  20 55 70 20 20 20 74 6F 20 20 6E 6F 77 20 20 20     Up   to  now   
006D30:  20 77 65 20 20 20 68 61 76 65 20 20 20 6F 6E 46     we   have   onF
006D40:  EF 6C 79 20 20 20 75 73 65 64 69 6E 73 74 72 75    .ly   usedinstru
006D50:  63 74 69 6F 6E 73 20 69 6E 20 77 68 69 63 68 20    ctions in which 
006D60:  20 6D 65 6D 6F 72 79 20 20 6C 6F 63 61 74 69 6F     memory  locatio
006D70:  6E 73 68 61 76 65 20 20 62 65 65 6E 20 20 73 70    nshave  been  sp
006D80:  65 63 69 66 69 65 64 20 20 64 69 72 65 63 74 6C    ecified  directl
006D90:  79 20 20 69 6E 20 20 74 68 65 69 6E 73 74 72 75    y  in  theinstru
006DA0:  63 74 69 6F 6E 2E 20 41 6E 6F 74 68 65 72 20 20    ction. Another  
006DB0:  75 73 65 66 75 6C 20 20 6D 65 74 68 6F 64 20 20    useful  method  
006DC0:  6F 66 73 70 65 63 69 66 79 69 6E 67 20 61 20 6D    ofspecifying a m
006DD0:  65 6D 6F 72 79 20 6C 6F 63 61 74 69 6F 6E 20 69    emory location i
006DE0:  73 20 74 6F 20 75 73 65 20 61 6E 75 6D 62 65 72    s to use anumber
006DF0:  20 68 65 6C 64 20 69 6E 20 61 20 72 65 67 69 73     held in a regis
006E00:  74 65 72 20 20 70 61 69 72 2C 20 20 20 6B 6E 6F    ter  pair,   kno
006E10:  77 6E 61 73 20 69 6E 64 69 72 65 63 74 20 61 64    wnas indirect ad
006E20:  64 72 65 73 73 69 6E 67 2E 20 20 54 68 65 20 69    dressing.  The i
006E30:  6E 73 74 72 75 63 74 69 6F 6E 4C 44 20 42 2C 28    nstructionLD B,(
006E40:  48 C4 4A 4C 29 20 66 6F 72 20 65 78 61 6D 70 6C    H.JL) for exampl
006E50:  65 20 20 61 6C 6C 6F 77 73 20 75 73 20 74 6F 20    e  allows us to 
006E60:  6C 6F 61 64 6F 72 20 63 6F 70 79 20 74 6F 20 74    loador copy to t
006E70:  68 65 20 20 42 20 20 72 65 67 69 73 74 65 72 20    he  B  register 
006E80:  74 68 65 20 63 6F 6E 74 65 6E 74 73 6F 66 20 74    the contentsof t
006E90:  68 65 20 6D 65 6D 6F 72 79 20 6C 6F 63 61 74 69    he memory locati
006EA0:  6F 6E 20 77 68 6F 73 65 20 20 61 64 64 72 65 73    on whose  addres
006EB0:  73 20 69 73 69 6E 20 74 68 65 20 48 4C 20 72 65    s isin the HL re
006EC0:  67 69 73 74 65 72 20 70 61 69 72 2E A0 A0 20 41    gister pair... A
006ED0:  6C 6C 20 20 73 69 6E 67 6C 65 20 20 72 65 67 69    ll  single  regi
006EE0:  73 74 65 72 73 20 20 63 61 6E 20 20 62 65 20 20    sters  can  be  
006EF0:  6C 6F 61 64 65 64 75 73 69 6E 67 20 74 68 65 20    loadedusing the 
006F00:  48 4C 20 72 65 67 69 73 74 65 72 20 70 61 69 72    HL register pair
006F10:  20 61 73 20 61 20 70 6F 69 6E 74 65 72 2E A0 20     as a pointer.. 
006F20:  53 69 6D 69 6C 61 72 6C 79 20 2C 20 20 6D 65 6D    Similarly ,  mem
006F30:  6F 72 79 20 20 6C 6F 63 61 74 69 6F 6E 73 20 20    ory  locations  
006F40:  63 61 6E 45 1B 20 20 62 65 6C 6F 61 64 65 64 20    canE.  beloaded 
006F50:  20 20 69 6E 64 69 72 65 63 74 6C 79 20 20 66 72      indirectly  fr
006F60:  6F 6D 20 20 20 61 6E 79 20 20 20 73 69 6E 67 6C    om   any   singl
006F70:  65 72 65 67 69 73 74 65 72 20 75 73 69 6E 67 20    eregister using 
006F80:  74 68 65 20 63 6F 6E 74 65 6E 74 73 20 20 6F 66    the contents  of
006F90:  20 20 74 68 65 20 20 48 4C 72 65 67 69 73 74 65      the  HLregiste
006FA0:  72 20 70 61 69 72 20 61 73 20 61 64 64 72 65 73    r pair as addres
006FB0:  73 20 69 2E 65 2E 20 4C 44 20 28 48 4C 29 2C 43    s i.e. LD (HL),C
006FC0:  2E A3 20 55 73 65 20 6F 66 20 20 74 68 65 20 20    .£ Use of  the  
006FD0:  42 43 20 20 61 6E 64 20 20 44 45 20 20 72 65 67    BC  and  DE  reg
006FE0:  69 73 74 65 72 73 20 66 6F 72 69 6E 64 69 72 65    isters forindire
006FF0:  63 74 20 61 64 64 72 65 73 73 69 6E 67 20 69 73    ct addressing is
007000:  20 6C 69 6D 69 74 65 64 20 74 6F 20 74 68 65 20     limited to the 
007010:  20 41 72 65 67 69 73 74 65 72 2E 20 69 2E 65 2E     Aregister. i.e.
007020:  20 4C 44 20 28 44 45 29 2C 41 20 3B 4C 44 20 41     LD (DE),A ;LD A
007030:  2C 28 42 43 29 20 65 74 63 2E A3 20 20 20 53 75    ,(BC) etc.£   Su
007040:  6D 6D 61 72 79 13 62 20 2D 20 20 69 6E 64 69 72    mmary.b -  indir
007050:  65 63 74 20 61 64 64 72 65 73 73 69 6E 67 A0 A0    ect addressing..
007060:  4C 44 20 72 2C 28 48 4C 29 20 77 68 65 72 65 20    LD r,(HL) where 
007070:  72 20 69 73 20 61 6E 79 20 73 69 6E 67 6C 65 20    r is any single 
007080:  72 65 67 69 73 74 65 72 20 20 20 20 20 20 20 20    register        
007090:  20 20 41 2C 42 2C 43 2C 44 2C 45 2C 48 2C 20 6F      A,B,C,D,E,H, o
0070A0:  72 20 4C 2E A0 4C 44 20 28 48 4C 29 2C 72 A0 A0    r L..LD (HL),r..
0070B0:  4C 44 20 41 2C 28 42 43 29 A0 4C 44 20 41 2C 28    LD A,(BC).LD A,(
0070C0:  44 45 29 A0 4C 44 20 28 42 43 29 2C 41 A0 4C 44    DE).LD (BC),A.LD
0070D0:  20 28 44 45 29 2C 41 A3 20 20 20 20 20 20 41 44     (DE),A£      AD
0070E0:  44 49 54 49 4F 4E 53 20 41 4E 44 20 54 48 45 20    DITIONS AND THE 
0070F0:  43 41 52 52 59 20 46 4C 41 47 A0 A0 20 42 6F 74    CARRY FLAG.. Bot
007100:  68 20 73 69 6E 67 6C 65 20 20 72 65 67 69 73 74    h single  regist
007110:  65 72 20 61 6E 64 20 72 65 67 69 73 74 65 72 20    er and register 
007120:  70 61 69 72 61 64 64 69 74 69 6F 6E 20 61 72 65    pairaddition are
007130:  20 70 6F 73 73 69 62 6C 65 20 6F 6E 20 74 68 65     possible on the
007140:  20 5A 38 30 2E A0 A0 16 A8 20 41 6C 6C 20 20 20     Z80..... All   
007150:  73 69 6E 67 6C 65 20 20 20 72 65 67 69 73 74 65    single   registe
007160:  72 20 20 61 64 64 69 74 69 6F 6E 73 20 20 61 72    r  additions  ar
007170:  65 70 65 72 66 6F 72 6D 65 64 20 77 69 74 68 20    eperformed with 
007180:  74 68 65 20 41 63 63 75 6D 75 6C 61 74 6F 72 2E    the Accumulator.
007190:  20 41 20 6E 75 6D 62 65 72 28 20 69 2E 65 2E 20     A number( i.e. 
0071A0:  20 41 44 44 20 41 2C 36 20 29 2C 20 20 74 68 65     ADD A,6 ),  the
0071B0:  20 20 63 6F 6E 74 65 6E 74 73 20 20 6F 66 20 20      contents  of  
0071C0:  61 72 65 67 69 73 74 65 72 20 28 69 2E 65 2E 20    aregister (i.e. 
0071D0:  41 44 44 20 41 2C 42 29 2C 20 6F 72 20 74 68 65    ADD A,B), or the
0071E0:  20 63 6F 6E 74 65 6E 74 73 6F 66 20 20 61 6E 20     contentsof  an 
0071F0:  20 20 69 6E 64 69 72 65 63 74 6C 79 20 20 20 61      indirectly   a
007200:  64 64 72 65 73 73 65 64 20 20 20 6D 65 6D 6F 72    ddressed   memor
007210:  79 6C 6F 63 61 74 69 6F 6E 20 20 75 73 69 6E 67    ylocation  using
007220:  20 20 74 68 65 20 20 48 4C 20 20 72 65 67 69 73      the  HL  regis
007230:  74 65 72 20 20 70 61 69 72 28 69 2E 65 2E 20 41    ter  pair(i.e. A
007240:  44 44 20 41 2C 28 48 4C 29 06 1D 20 29 20 63 61    DD A,(HL).. ) ca
007250:  6E 20 62 65 20 61 64 64 65 64 20 20 74 6F 20 20    n be added  to  
007260:  74 68 65 41 63 63 75 6D 75 6C 61 74 6F 72 2E 20    theAccumulator. 
007270:  54 68 65 20 72 65 73 75 6C 74 20 20 69 73 20 20    The result  is  
007280:  68 65 6C 64 20 69 6E 20 74 68 65 41 63 63 75 6D    held in theAccum
007290:  75 6C 61 74 6F 72 2E 20 20 54 68 65 20 73 6F 75    ulator.  The sou
0072A0:  72 63 65 20 6F 66 20 74 68 65 20 61 64 64 69 74    rce of the addit
0072B0:  69 6F 6E 69 73 20 75 6E 61 66 66 65 63 74 65 64    ionis unaffected
0072C0:  2E A0 A0 20 52 65 67 69 73 74 65 72 20 20 70 61    ... Register  pa
0072D0:  69 72 20 61 64 64 69 74 69 6F 6E 20 69 73 20 70    ir addition is p
0072E0:  65 72 66 6F 72 6D 65 64 20 69 6E 63 6F 6E 6A 75    erformed inconju
0072F0:  6E 63 74 69 6F 6E 20 20 77 69 74 68 20 20 74 68    nction  with  th
007300:  65 20 48 4C 20 72 65 67 69 73 74 65 72 20 70 61    e HL register pa
007310:  69 72 2C 61 6E 64 20 20 63 61 6E 20 20 6F 6E 6C    ir,and  can  onl
007320:  79 20 20 69 6E 76 6F 6C 76 65 20 20 42 43 20 6F    y  involve  BC o
007330:  72 20 44 45 20 28 20 69 2E 65 2E 41 44 44 20 48    r DE ( i.e.ADD H
007340:  4C 2C 42 43 20 20 6F 72 20 20 41 1C 87 44 44 20    L,BC  or  A..DD 
007350:  48 4C 2C 44 45 20 29 2E 20 20 20 41 67 61 69 6E    HL,DE ).   Again
007360:  20 20 74 68 65 74 68 65 20 20 72 65 73 75 6C 74      thethe  result
007370:  20 69 73 20 68 65 6C 64 20 69 6E 20 20 74 68 65     is held in  the
007380:  20 20 48 4C 20 72 65 67 69 73 74 65 72 70 61 69      HL registerpai
007390:  72 2C 20 20 61 6E 64 20 20 74 68 65 20 6F 74 68    r,  and  the oth
0073A0:  65 72 20 20 72 65 67 69 73 74 65 72 20 20 70 61    er  register  pa
0073B0:  69 72 20 69 73 75 6E 61 66 66 65 63 74 65 64 2E    ir isunaffected.
0073C0:  A3 20 53 69 6E 67 6C 65 20 20 61 6E 64 20 20 64    £ Single  and  d
0073D0:  6F 75 62 6C 65 20 20 72 65 67 69 73 74 65 72 20    ouble  register 
0073E0:  61 64 64 69 74 69 6F 6E 73 77 69 6C 6C 20 20 6F    additionswill  o
0073F0:  62 76 69 6F 75 73 6C 79 20 20 6F 6E 6C 79 20 20    bviously  only  
007400:  67 69 76 65 20 20 74 68 65 20 63 6F 72 72 65 63    give  the correc
007410:  74 72 65 73 75 6C 74 20 20 69 66 20 20 74 68 65    tresult  if  the
007420:  20 20 61 6E 73 77 65 72 20 69 73 20 6C 65 73 73      answer is less
007430:  20 74 68 61 6E 20 74 68 65 6D 61 78 69 6D 75 6D     than themaximum
007440:  20 6E 75 6D 62 65 72 20 74 68 65 20 72 09 57 65     number the r.We
007450:  67 69 73 74 65 72 28 73 29 20 63 61 6E 20 68 6F    gister(s) can ho
007460:  6C 64 2E 49 66 20 69 74 20 69 73 20 67 72 65 61    ld.If it is grea
007470:  74 65 72 20 74 68 61 6E 20 74 68 69 73 20 20 61    ter than this  a
007480:  20 20 63 61 72 72 79 20 20 69 73 67 65 6E 65 72      carry  isgener
007490:  61 74 65 64 2E 20 20 54 68 65 20 70 72 6F 63 65    ated.  The proce
0074A0:  73 73 6F 72 20 20 20 68 6F 6C 64 73 20 20 20 74    ssor   holds   t
0074B0:  68 69 73 73 69 6E 67 6C 65 20 20 62 69 74 20 20    hissingle  bit  
0074C0:  6F 66 20 20 69 6E 66 6F 72 6D 61 74 69 6F 6E 20    of  information 
0074D0:  6F 72 20 66 6C 61 67 2C 20 73 6F 74 68 61 74 20    or flag, sothat 
0074E0:  20 61 63 74 69 6F 6E 20 20 20 63 61 6E 20 20 62     action   can  b
0074F0:  65 20 20 74 61 6B 65 6E 20 20 6F 76 65 72 20 20    e  taken  over  
007500:  74 68 65 6F 63 63 75 72 72 65 6E 63 65 20 6F 66    theoccurrence of
007510:  20 74 68 65 20 63 61 72 72 79 2E 20 20 20 49 66     the carry.   If
007520:  20 74 68 65 72 65 20 20 68 61 73 62 65 65 6E 20     there  hasbeen 
007530:  20 61 20 20 63 61 72 72 79 20 20 6F 6E 20 20 74     a  carry  on  t
007540:  68 65 20 20 6C 61 73 74 20 61 72 69 74 68 6D 1E    he  last arithm.
007550:  0E 65 74 69 63 6F 70 65 72 61 74 69 6F 6E 20 74    .eticoperation t
007560:  68 65 20 63 61 72 72 79 20 69 73 20 73 61 69 64    he carry is said
007570:  20 74 6F 20 62 65 20 73 65 74 20 74 6F 61 20 20     to be set toa  
007580:  22 31 22 20 2E 20 20 49 66 20 6E 6F 74 20 73 65    "1" .  If not se
007590:  74 20 20 69 74 20 69 73 20 73 61 69 64 20 74 6F    t  it is said to
0075A0:  20 62 65 20 61 22 30 22 2E A0 A0 20 41 20 73 65     be a"0"... A se
0075B0:  63 6F 6E 64 20 66 6F 72 6D 20 6F 66 20 61 64 64    cond form of add
0075C0:  69 74 69 6F 6E 20 69 73 20 20 61 76 61 69 6C 61    ition is  availa
0075D0:  62 6C 65 6F 6E 20 20 74 68 65 20 20 5A 38 30 20    bleon  the  Z80 
0075E0:  2C 20 20 20 66 6F 72 20 20 20 62 6F 74 68 20 20    ,   for   both  
0075F0:  73 69 6E 67 6C 65 20 20 61 6E 64 6D 75 6C 74 69    single  andmulti
007600:  70 6C 65 20 72 65 67 69 73 74 65 72 73 2C 20 20    ple registers,  
007610:  6B 6E 6F 77 6E 20 20 61 73 20 20 61 64 64 20 77    known  as  add w
007620:  69 74 68 63 61 72 72 79 3B 20 20 61 62 62 72 65    ithcarry;  abbre
007630:  76 69 61 74 65 64 20 20 74 6F 20 20 41 44 43 2E    viated  to  ADC.
007640:  20 20 20 54 68 65 79 20 61 72 65 73 69 6D 69 6C       They aresimil
007650:  61 BC 0A 72 20 74 6F 20 41 44 44 20 20 65 78 63    a..r to ADD  exc
007660:  65 70 74 20 74 68 61 74 20 69 66 20 74 68 65 20    ept that if the 
007670:  43 61 72 72 79 66 6C 61 67 20 20 69 73 20 20 73    Carryflag  is  s
007680:  65 74 20 20 62 65 66 6F 72 65 20 20 74 68 65 20    et  before  the 
007690:  20 61 64 64 69 74 69 6F 6E 20 74 68 65 72 65 73     addition theres
0076A0:  75 6C 74 20 69 73 20 20 69 6E 63 72 65 6D 65 6E    ult is  incremen
0076B0:  74 65 64 20 20 20 62 79 20 20 20 6F 6E 65 2E 20    ted   by   one. 
0076C0:  20 20 41 6C 6C 70 72 65 76 69 6F 75 73 6C 79 20      Allpreviously 
0076D0:  6D 65 6E 74 69 6F 6E 65 64 20 20 20 41 44 44 20    mentioned   ADD 
0076E0:  20 69 6E 73 74 72 75 63 74 69 6F 6E 73 63 61 6E     instructionscan
0076F0:  20 62 65 20 70 65 72 66 6F 72 6D 65 64 20 61 73     be performed as
007700:  20 41 44 43 2E A3 20 41 44 43 20 69 6E 73 74 72     ADC.£ ADC instr
007710:  75 63 74 69 6F 6E 73 20 63 61 6E 20 62 65 20 73    uctions can be s
007720:  74 72 75 6E 67 20 74 6F 67 65 74 68 65 72 74 6F    trung togetherto
007730:  20 70 65 72 66 6F 72 6D 20 20 74 68 65 20 20 61     perform  the  a
007740:  64 64 69 74 69 6F 6E 20 6F 66 20 74 77 6F 20 6E    ddition of two n
007750:  75 6D 62 B0 D5 65 72 73 6F 66 20 61 6E 79 20 20    umb..ersof any  
007760:  6C 65 6E 67 74 68 2C 20 20 61 73 20 20 74 68 65    length,  as  the
007770:  20 20 65 78 61 6D 70 6C 65 73 20 20 77 69 6C 6C      examples  will
007780:  73 68 6F 77 2E A3 20 20 20 53 75 6D 6D 61 72 79    show.£   Summary
007790:  20 2D 20 20 61 64 64 69 74 69 6F 6E A0 A0 41 44     -  addition..AD
0077A0:  44 20 41 2C 6E 20 20 20 20 77 68 65 72 65 20 6E    D A,n    where n
0077B0:  20 69 73 20 61 20 6E 75 6D 62 65 72 20 30 20 2D     is a number 0 -
0077C0:  20 32 35 35 A0 A0 41 44 44 20 41 2C 72 20 20 20     255..ADD A,r   
0077D0:  20 77 68 65 72 65 20 20 72 20 20 69 73 20 20 61     where  r  is  a
0077E0:  6E 79 20 20 20 73 69 6E 67 6C 65 A0 20 20 20 20    ny   single.    
0077F0:  20 20 20 20 20 20 20 72 65 67 69 73 74 65 72 A0           register.
007800:  41 44 44 20 41 2C 28 48 4C 29 A0 A0 41 44 44 20    ADD A,(HL)..ADD 
007810:  48 4C 2C 42 43 A0 41 44 44 20 48 4C 2C 44 45 A0    HL,BC.ADD HL,DE.
007820:  A0 A0 41 44 43 20 41 2C 6E A0 A0 41 44 43 20 41    ..ADC A,n..ADC A
007830:  2C 72 A0 A0 41 44 43 20 41 2C 28 48 4C 29 A0 A0    ,r..ADC A,(HL)..
007840:  41 44 43 20 48 4C 2C 42 43 A0 41 44 43 20 48 4C    ADC HL,BC.ADC HL
007850:  2C 44 45 A3 20 D2 AE 20 20 20 53 55 42 54 52 41    ,DE£ ..   SUBTRA
007860:  43 54 49 4F 4E 20 41 4E 44 20 54 48 45 20 43 41    CTION AND THE CA
007870:  52 52 59 20 46 4C 41 47 A0 A0 20 53 69 6E 67 6C    RRY FLAG.. Singl
007880:  65 20 72 65 67 69 73 74 65 72 20 73 75 62 74 72    e register subtr
007890:  61 63 74 69 6F 6E 20 74 61 6B 65 73 20 70 6C 61    action takes pla
0078A0:  63 65 77 69 74 68 20 74 68 65 20 41 63 63 75 6D    cewith the Accum
0078B0:  75 6C 61 74 6F 72 2E 20 20 41 6C 6C 20 20 74 68    ulator.  All  th
0078C0:  65 20 66 6F 72 6D 73 20 6F 66 41 44 44 20 20 63    e forms ofADD  c
0078D0:  61 6E 20 20 62 65 20 20 20 75 73 65 64 20 20 69    an  be   used  i
0078E0:  6E 20 20 20 73 75 62 74 72 61 63 74 2E 20 20 54    n   subtract.  T
0078F0:  68 65 61 62 62 72 65 76 69 61 74 69 6F 6E 20 20    heabbreviation  
007900:  6F 72 20 20 6D 6E 65 6D 6F 6E 69 63 20 53 55 42    or  mnemonic SUB
007910:  20 69 73 20 61 6C 77 61 79 73 77 72 69 74 74 65     is alwayswritte
007920:  6E 20 77 69 74 68 6F 75 74 20 74 68 65 20 41 2C    n without the A,
007930:  20 77 68 69 63 68 20 69 73 20 69 6D 70 6C 69 65     which is implie
007940:  64 2E 48 65 6E 63 65 20 74 68 65 20 69 6E 73 74    d.Hence the inst
007950:  72 75 63 74 69 6F 6E FE 61 73 20 61 72 65 20 53    ruction.as are S
007960:  55 42 20 6E 2C 20 53 55 42 20 72 2C 61 6E 64 20    UB n, SUB r,and 
007970:  53 55 42 20 28 48 4C 29 2E 20 20 20 41 67 61 69    SUB (HL).   Agai
007980:  6E 20 74 68 65 20 72 65 73 75 6C 74 20 69 73 20    n the result is 
007990:  68 65 6C 64 69 6E 20 74 68 65 20 41 63 63 75 6D    heldin the Accum
0079A0:  75 6C 61 74 6F 72 2E 20 20 20 54 68 65 20 20 63    ulator.   The  c
0079B0:  61 72 72 79 20 66 6C 61 67 20 69 73 73 65 74 20    arry flag isset 
0079C0:  74 6F 20 61 20 22 31 22 20 20 69 66 20 74 68 65    to a "1"  if the
0079D0:  20 20 72 65 73 75 6C 74 20 69 73 20 20 6F 75 74      result is  out
0079E0:  73 69 64 65 74 68 65 20 72 61 6E 67 65 20 20 30    sidethe range  0
0079F0:  20 2D 20 32 35 35 2E A0 A0 54 68 65 72 65 20 20     - 255...There  
007A00:  61 72 65 20 20 20 6E 6F 20 20 64 6F 75 62 6C 65    are   no  double
007A10:  20 20 20 72 65 67 69 73 74 65 72 20 20 20 53 55       register   SU
007A20:  42 69 6E 73 74 72 75 63 74 69 6F 6E 73 2E A0 A0    Binstructions...
007A30:  41 6C 6C 20 20 63 6F 6E 66 69 67 75 72 61 74 69    All  configurati
007A40:  6F 6E 73 20 6F 66 20 20 41 44 43 20 69 6E 73 74    ons of  ADC inst
007A50:  72 75 63 74 69 6F 6E 73 63 B4 83 61 6E 20 62 65    ructionsc..an be
007A60:  20 75 73 65 64 20 20 77 69 74 68 20 53 42 43 20     used  with SBC 
007A70:  6F 72 20 20 53 75 42 74 72 61 63 74 20 20 77 69    or  SuBtract  wi
007A80:  74 68 43 61 72 72 79 20 20 69 6E 73 74 72 75 63    thCarry  instruc
007A90:  74 69 6F 6E 73 2E 20 20 54 68 65 20 6F 70 65 72    tions.  The oper
007AA0:  61 74 69 6F 6E 20 20 20 69 73 73 69 6D 69 6C 61    ation   issimila
007AB0:  72 20 74 6F 20 53 55 42 2C 20 20 65 78 63 65 70    r to SUB,  excep
007AC0:  74 20 74 68 61 74 20 74 68 65 20 20 72 65 73 75    t that the  resu
007AD0:  6C 74 69 73 20 64 65 63 72 65 6D 65 6E 74 65 64    ltis decremented
007AE0:  20 20 62 79 20 6F 6E 65 20 69 66 20 74 68 65 20      by one if the 
007AF0:  63 61 72 72 79 20 66 6C 61 67 69 73 20 73 65 74    carry flagis set
007B00:  2E A3 20 4C 69 6B 65 20 20 41 44 43 20 69 6E 73    .£ Like  ADC ins
007B10:  74 72 75 63 74 69 6F 6E 73 20 53 42 43 20 69 6E    tructions SBC in
007B20:  73 74 72 75 63 74 69 6F 6E 73 63 61 6E 20 62 65    structionscan be
007B30:  20 20 73 74 72 75 6E 67 20 74 6F 67 65 74 68 65      strung togethe
007B40:  72 20 74 6F 20 20 73 75 62 74 72 61 63 74 20 61    r to  subtract a
007B50:  6E 79 6C 65 6E 67 74 68 20 6E 75 17 A2 6D 62 65    nylength nu..mbe
007B60:  72 2E A0 A0 20 53 69 6E 63 65 20 20 64 6F 75 62    r... Since  doub
007B70:  6C 65 20 72 65 67 69 73 74 65 72 20 20 73 75 62    le register  sub
007B80:  74 72 61 63 74 69 6F 6E 20 63 61 6E 6F 6E 6C 79    traction canonly
007B90:  20 62 65 20 70 65 72 66 6F 72 6D 65 64 20 77 69     be performed wi
007BA0:  74 68 20 63 61 72 72 79 2C 20 20 74 68 65 20 73    th carry,  the s
007BB0:  74 61 74 65 6F 66 20 74 68 65 20 20 63 61 72 72    tateof the  carr
007BC0:  79 20 66 6C 61 67 20 20 70 72 69 6F 72 20 74 6F    y flag  prior to
007BD0:  20 20 53 42 43 20 48 4C 2C 42 43 2C 61 6E 64 20      SBC HL,BC,and 
007BE0:  53 42 43 20 48 4C 2C 44 45 20 69 73 20 69 6D 70    SBC HL,DE is imp
007BF0:  6F 72 74 61 6E 74 2C 20 20 61 6E 64 20 20 73 68    ortant,  and  sh
007C00:  6F 75 6C 64 62 65 20 22 30 22 2E A0 20 54 68 65    ouldbe "0".. The
007C10:  20 63 61 72 72 79 20 66 6C 61 67 20 63 61 6E 20     carry flag can 
007C20:  62 65 20 73 65 74 20 74 6F 20 61 20 22 31 22 20    be set to a "1" 
007C30:  77 69 74 68 74 68 65 20 69 6E 73 74 72 75 63 74    withthe instruct
007C40:  69 6F 6E 20 20 53 43 46 20 6F 72 20 53 65 74 20    ion  SCF or Set 
007C50:  43 61 72 72 79 20 20 46 6C 61 67 2E 41 97 1B 6C    Carry  Flag.A..l
007C60:  74 68 6F 75 67 68 20 20 20 74 68 65 72 65 20 20    though   there  
007C70:  20 61 72 65 20 20 20 20 6E 6F 20 20 20 20 73 70     are    no    sp
007C80:  65 63 69 66 69 63 69 6E 73 74 72 75 63 74 69 6F    ecificinstructio
007C90:  6E 73 20 20 74 6F 20 63 6C 65 61 72 20 74 68 65    ns  to clear the
007CA0:  20 63 61 72 72 79 20 66 6C 61 67 20 74 6F 22 30     carry flag to"0
007CB0:  22 20 74 68 65 72 65 20 69 73 20 61 6E 20 69 6E    " there is an in
007CC0:  73 74 72 75 63 74 69 6F 6E 20 74 6F 20 69 6E 76    struction to inv
007CD0:  65 72 74 20 69 74 43 43 46 20 6F 72 20 20 43 6F    ert itCCF or  Co
007CE0:  6D 70 6C 69 6D 65 6E 74 20 43 61 72 72 79 20 46    mpliment Carry F
007CF0:  6C 61 67 2E 20 20 57 65 20 73 68 61 6C 6C 73 65    lag.  We shallse
007D00:  65 20 6C 61 74 65 72 20 74 68 61 74 20 61 6C 6C    e later that all
007D10:  20 6C 6F 67 69 63 20 69 6E 73 74 72 75 63 74 69     logic instructi
007D20:  6F 6E 73 20 64 6F 63 6C 65 61 72 20 74 68 65 20    ons doclear the 
007D30:  63 61 72 72 79 20 66 6C 61 67 2E A3 20 53 55 4D    carry flag.£ SUM
007D40:  4D 41 52 59 20 2D 20 73 75 62 74 72 61 63 74 20    MARY - subtract 
007D50:  77 69 74 68 20 63 61 72 72 79 A0 A0 53 55 42 76    with carry..SUBv
007D60:  04 20 6E 20 20 20 20 20 29 A0 53 55 42 20 72 20    . n     ).SUB r 
007D70:  20 20 20 20 29 20 20 53 55 42 74 72 61 63 74 20        )  SUBtract 
007D80:  66 72 6F 6D 20 41 2C 20 6E 2C 20 72 2C 20 6F 72    from A, n, r, or
007D90:  A0 53 55 42 20 28 48 4C 29 20 20 29 20 20 20 20    .SUB (HL)  )    
007DA0:  20 20 20 20 20 20 20 20 20 20 20 20 20 20 28 48                  (H
007DB0:  4C 29 A0 A0 53 42 43 20 41 2C 6E 20 20 20 29 A0    L)..SBC A,n   ).
007DC0:  53 42 43 20 41 2C 72 20 20 20 29 20 20 53 75 42    SBC A,r   )  SuB
007DD0:  74 72 61 63 74 20 66 72 6F 6D 20 41 20 20 77 69    tract from A  wi
007DE0:  74 68 20 63 61 72 72 79 53 42 43 20 41 2C 28 48    th carrySBC A,(H
007DF0:  4C 29 29 A0 A0 53 42 43 20 48 4C 2C 42 43 20 29    L))..SBC HL,BC )
007E00:  20 20 53 75 42 74 72 61 63 74 20 66 72 6F 6D 20      SuBtract from 
007E10:  48 4C 20 77 69 74 68 20 63 61 72 72 79 53 42 43    HL with carrySBC
007E20:  20 48 4C 2C 44 45 20 29 A0 A0 53 43 46 20 20 20     HL,DE )..SCF   
007E30:  20 20 20 20 20 53 65 74 20 43 61 72 72 79 20 46         Set Carry F
007E40:  6C 61 67 A0 43 43 46 20 20 20 20 20 20 20 20 43    lag.CCF        C
007E50:  6F 6D 70 6C 69 6D 65 6E 74 20 43 61 72 72 79 20    ompliment Carry 
007E60:  46 1B 91 6C 61 67 A3 20 20 49 4E 43 52 45 4D 45    F..lag£  INCREME
007E70:  4E 54 20 41 4E 44 20 44 45 43 52 45 4D 45 4E 54    NT AND DECREMENT
007E80:  20 49 4E 53 54 52 55 43 54 49 4F 4E 53 A0 A0 20     INSTRUCTIONS.. 
007E90:  54 68 65 20 6C 61 73 74 20 61 72 69 74 68 6D 65    The last arithme
007EA0:  74 69 63 20 69 6E 73 74 72 75 63 74 69 6F 6E 73    tic instructions
007EB0:  20 74 6F 20 20 62 65 64 69 73 63 75 73 73 65 64     to  bediscussed
007EC0:  20 63 61 6E 20 62 65 20 70 65 72 66 6F 72 6D 65     can be performe
007ED0:  64 20 6F 6E 20 61 6E 79 20 73 69 6E 67 6C 65 6F    d on any singleo
007EE0:  72 20 64 6F 75 62 6C 65 20 72 65 67 69 73 74 65    r double registe
007EF0:  72 28 73 29 2E 20 54 68 65 73 65 20 61 72 65 20    r(s). These are 
007F00:  49 4E 43 20 61 6E 64 44 45 43 2E 20 20 49 4E 43    INC andDEC.  INC
007F10:  20 69 6E 63 72 65 6D 65 6E 74 73 20 28 6F 72 20     increments (or 
007F20:  20 69 6E 63 72 65 61 73 65 73 29 20 74 68 65 63     increases) thec
007F30:  6F 6E 74 65 6E 74 73 20 20 6F 66 20 20 74 68 65    ontents  of  the
007F40:  20 20 72 65 67 69 73 74 65 72 2C 20 20 6F 72 20      register,  or 
007F50:  20 6D 65 6D 6F 72 79 6C 6F 63 61 74 69 6F 6E 20     memorylocation 
007F60:  69 6E 64 85 87 69 72 65 63 74 6C 79 20 20 61 64    ind..irectly  ad
007F70:  64 72 65 73 73 65 64 20 62 79 20 74 68 65 20 48    dressed by the H
007F80:  4C 72 65 67 69 73 74 65 72 20 70 61 69 72 2C 20    Lregister pair, 
007F90:  20 62 79 20 6F 6E 65 2E 20 20 20 44 45 43 20 64     by one.   DEC d
007FA0:  65 63 72 65 6D 65 6E 74 73 28 20 6F 72 20 20 64    ecrements( or  d
007FB0:  65 63 72 65 61 73 65 73 20 29 20 20 74 68 65 20    ecreases )  the 
007FC0:  20 63 6F 6E 74 65 6E 74 73 20 20 6F 66 20 74 68     contents  of th
007FD0:  65 72 65 67 69 73 74 65 72 20 6F 72 20 20 6D 65    eregister or  me
007FE0:  6D 6F 72 79 20 20 6C 6F 63 61 74 69 6F 6E 20 69    mory  location i
007FF0:  6E 64 69 72 65 63 74 6C 79 61 64 64 72 65 73 73    ndirectlyaddress
008000:  65 64 20 62 79 20 74 68 65 20 20 48 4C 20 72 65    ed by the  HL re
008010:  67 69 73 74 65 72 20 20 70 61 69 72 2C 20 20 62    gister  pair,  b
008020:  79 20 54 68 65 20 20 63 61 72 72 79 20 20 66 6C    y The  carry  fl
008030:  61 67 20 20 69 73 20 20 6E 6F 74 20 20 61 66 66    ag  is  not  aff
008040:  65 63 74 65 64 20 20 62 79 65 69 74 68 65 72 20    ected  byeither 
008050:  6F 66 20 74 68 65 73 65 20 69 6E 73 74 72 75 63    of these instruc
008060:  74 69 6F 6E 73 8B 0B 2E A0 A0 20 54 68 65 73 65    tions..... These
008070:  20 69 6E 73 74 72 75 63 74 69 6F 6E 73 20 20 61     instructions  a
008080:  72 65 20 20 70 72 69 6D 61 72 69 6C 79 20 75 73    re  primarily us
008090:  65 64 77 68 65 72 65 20 20 20 63 6F 75 6E 74 65    edwhere   counte
0080A0:  72 73 20 20 20 61 72 65 20 20 20 72 65 71 75 69    rs   are   requi
0080B0:  72 65 64 2E 20 20 20 54 68 65 6F 70 65 72 61 74    red.   Theoperat
0080C0:  69 6F 6E 20 20 6F 6E 20 20 72 65 67 69 73 74 65    ion  on  registe
0080D0:  72 20 20 70 61 69 72 73 20 20 69 73 20 20 61 6C    r  pairs  is  al
0080E0:  73 6F 75 73 65 66 75 6C 20 20 69 6E 20 20 20 73    souseful  in   s
0080F0:  65 71 75 65 6E 74 69 61 6C 20 20 6F 70 65 72 61    equential  opera
008100:  74 69 6F 6E 73 20 20 20 6F 6E 6D 65 6D 6F 72 79    tions   onmemory
008110:  20 20 20 6C 6F 63 61 74 69 6F 6E 73 20 20 75 74       locations  ut
008120:  69 6C 69 73 69 6E 67 20 20 20 69 6E 64 69 72 65    ilising   indire
008130:  63 74 61 64 64 72 65 73 73 69 6E 67 2E A3 20 53    ctaddressing.£ S
008140:  75 6D 6D 61 72 79 20 2D 20 69 6E 63 72 65 6D 65    ummary - increme
008150:  6E 74 20 61 6E 64 20 64 65 63 72 65 6D 65 6E 74    nt and decrement
008160:  A0 A0 49 4E 43 20 72 FD EF A0 49 4E 43 20 28 48    ..INC r...INC (H
008170:  4C 29 A0 49 4E 43 20 64 64 A0 A0 44 45 43 20 72    L).INC dd..DEC r
008180:  A0 44 45 43 20 28 48 4C 29 A0 44 45 43 20 64 64    .DEC (HL).DEC dd
008190:  A3 20 20 20 20 20 20 20 20 20 20 20 54 48 45 20    £           THE 
0081A0:  5A 45 52 4F 20 46 4C 41 47 A0 A0 20 41 6E 6F 74    ZERO FLAG.. Anot
0081B0:  68 65 72 20 20 76 65 72 79 20 20 75 73 65 66 75    her  very  usefu
0081C0:  6C 20 20 66 6C 61 67 20 69 6E 63 6C 75 64 65 64    l  flag included
0081D0:  20 69 6E 61 6C 6C 20 20 70 72 6F 63 65 73 73 6F     inall  processo
0081E0:  72 73 20 69 73 20 20 74 68 65 20 5A 65 72 6F 20    rs is  the Zero 
0081F0:  66 6C 61 67 2E 20 20 54 68 69 73 66 6C 61 67 20    flag.  Thisflag 
008200:  69 73 20 73 65 74 20 74 6F 20 22 31 22 20 20 69    is set to "1"  i
008210:  66 20 74 68 65 20 72 65 73 75 6C 74 20 6F 66 20    f the result of 
008220:  61 6E 79 73 69 6E 67 6C 65 20 72 65 67 69 73 74    anysingle regist
008230:  65 72 20 61 72 69 74 68 6D 65 74 69 63 20 6F 70    er arithmetic op
008240:  65 72 61 74 69 6F 6E 20 20 69 73 7A 65 72 6F 2E    eration  iszero.
008250:  20 4F 74 68 65 72 77 69 73 65 20 69 74 20 69 73     Otherwise it is
008260:  20 63 6C 65 61 72 65 64 20 6E 3A 74 6F 20 22 30     cleared n:to "0
008270:  22 2E A0 A0 20 49 74 20 69 73 20 20 6F 6E 6C 79    "... It is  only
008280:  20 61 66 66 65 63 74 65 64 20 62 79 20 64 6F 75     affected by dou
008290:  62 6C 65 20 72 65 67 69 73 74 65 72 61 72 69 74    ble registerarit
0082A0:  68 6D 65 74 69 63 20 20 20 6F 70 65 72 61 74 69    hmetic   operati
0082B0:  6F 6E 73 20 20 20 69 6E 76 6F 6C 76 69 6E 67 20    ons   involving 
0082C0:  20 74 68 65 63 61 72 72 79 20 20 66 6C 61 67 20     thecarry  flag 
0082D0:  2C 20 20 20 69 2E 65 2E 20 20 6F 6E 6C 79 20 20    ,   i.e.  only  
0082E0:  61 66 66 65 63 74 65 64 20 20 62 79 41 44 43 20    affected  byADC 
0082F0:  48 4C 2C 64 64 20 20 6F 72 20 20 53 42 43 20 48    HL,dd  or  SBC H
008300:  4C 2C 64 64 2E A0 A0 20 54 68 65 20 20 7A 65 72    L,dd... The  zer
008310:  6F 20 66 6C 61 67 2C 20 6C 69 6B 65 20 74 68 65    o flag, like the
008320:  20 63 61 72 72 79 20 66 6C 61 67 2C 20 69 73 75     carry flag, isu
008330:  6E 61 66 66 65 63 74 65 64 20 62 79 20 61 6E 79    naffected by any
008340:  20 4C 44 20 6F 72 20 45 58 20 69 6E 73 74 72 75     LD or EX instru
008350:  63 74 69 6F 6E 73 2E A3 20 53 75 6D 6D 61 72 79    ctions.£ Summary
008360:  20 2D 20 7A 65 72 6F 20 61 6E 64 45 C9 20 63 61     - zero andE. ca
008370:  72 72 79 20 66 6C 61 67 73 A0 A0 69 6E 73 74 72    rry flags..instr
008380:  75 63 74 69 6F 6E 20 20 20 20 20 20 43 61 72 72    uction      Carr
008390:  79 20 20 20 20 20 20 20 20 5A 65 72 6F A0 20 20    y        Zero.  
0083A0:  20 20 20 20 20 20 20 20 20 20 20 20 20 20 72 20                  r 
0083B0:  20 20 20 64 64 20 20 20 20 20 20 72 20 20 20 64       dd      r   d
0083C0:  64 A0 A0 20 20 4C 44 20 20 20 20 20 20 20 20 20    d..  LD         
0083D0:  20 20 20 2E 20 20 20 20 20 2E 20 20 20 20 20 20       .     .      
0083E0:  2E 20 20 20 20 2E A0 20 20 45 58 20 20 20 20 20    .    ..  EX     
0083F0:  20 20 20 20 20 20 6E 2F 76 20 20 20 20 2E 20 20          n/v    .  
008400:  20 20 20 6E 2F 76 20 20 20 2E A0 A0 20 20 41 44       n/v   ...  AD
008410:  44 20 20 20 20 20 20 20 20 20 20 20 2A 20 20 20    D           *   
008420:  20 20 2A 20 20 20 20 20 20 2A 20 20 20 20 2E A0      *      *    ..
008430:  20 20 41 44 43 20 20 20 20 20 20 20 20 20 20 20      ADC           
008440:  2A 20 20 20 20 20 2A 20 20 20 20 20 20 2A 20 20    *     *      *  
008450:  20 20 2A A0 20 20 53 55 42 20 20 20 20 20 20 20      *.  SUB       
008460:  20 20 20 20 2A 20 20 20 20 6E 2F 76 20 7E E1 20        *    n/v ~. 
008470:  20 20 20 2A 20 20 20 6E 2F 76 A0 20 20 53 42 43       *   n/v.  SBC
008480:  20 20 20 20 20 20 20 20 20 20 20 2A 20 20 20 20               *    
008490:  20 2A 20 20 20 20 20 20 2A 20 20 20 20 2A A0 A0     *      *    *..
0084A0:  20 20 49 4E 43 20 20 20 20 20 20 20 20 20 20 20      INC           
0084B0:  2E 20 20 20 20 20 2E 20 20 20 20 20 20 2A 20 20    .     .      *  
0084C0:  20 20 2E A0 20 20 44 45 43 20 20 20 20 20 20 20      ..  DEC       
0084D0:  20 20 20 20 2E 20 20 20 20 20 2E 20 20 20 20 20        .     .     
0084E0:  20 2A 20 20 20 20 2E A0 A0 A0 72 20 73 69 6E 67     *    ....r sing
0084F0:  6C 65 20 72 65 67 69 73 74 65 72 20 20 20 64 64    le register   dd
008500:  20 20 64 6F 75 62 6C 65 20 72 65 67 69 73 74 65      double registe
008510:  72 20 A0 2A 20 66 6C 61 67 20 61 66 66 65 63 74    r .* flag affect
008520:  65 64 20 20 20 20 20 20 2E 20 66 6C 61 67 20 6E    ed      . flag n
008530:  6F 74 20 61 66 66 65 63 74 65 64 A0 20 20 20 20    ot affected.    
008540:  20 6E 2F 76 20 20 20 20 69 6E 73 74 72 75 63 74     n/v    instruct
008550:  69 6F 6E 20 6E 6F 74 20 76 61 6C 69 64 A3 20 20    ion not valid£  
008560:  20 20 20 20 20 20 20 20 20 20 4C 65 73 73 6F 27              Lesso'
008570:  D5 6E 73 20 31 20 2D 20 39 A0 A0 20 31 2E 20 20    .ns 1 - 9.. 1.  
008580:  52 65 67 69 73 74 65 72 73 20 61 6E 64 20 4D 65    Registers and Me
008590:  6D 6F 72 79 A0 20 32 2E 20 20 53 69 6D 70 6C 65    mory. 2.  Simple
0085A0:  20 4C 6F 61 64 20 49 6E 73 74 72 75 63 74 69 6F     Load Instructio
0085B0:  6E 73 A0 20 20 20 20 20 20 20 20 20 45 78 20 2D    ns.         Ex -
0085C0:  20 73 69 6D 70 6C 65 20 6C 6F 61 64 20 69 6E 73     simple load ins
0085D0:  74 72 75 63 74 69 6F 6E 73 A0 20 33 2E 20 20 52    tructions. 3.  R
0085E0:  65 67 69 73 74 65 72 20 50 61 69 72 73 A0 20 20    egister Pairs.  
0085F0:  20 20 20 20 20 20 20 45 78 20 2D 20 72 65 67 69           Ex - regi
008600:  73 74 65 72 20 70 61 69 72 20 6C 6F 61 64 69 6E    ster pair loadin
008610:  67 A0 20 34 2E 20 20 49 6E 64 69 72 65 63 74 20    g. 4.  Indirect 
008620:  41 64 64 72 65 73 73 69 6E 67 A0 20 20 20 20 20    Addressing.     
008630:  20 20 20 20 45 78 20 2D 20 69 6E 64 69 72 65 63        Ex - indirec
008640:  74 20 61 64 64 72 65 73 73 69 6E 67 A0 20 35 2E    t addressing. 5.
008650:  20 20 41 64 64 69 74 69 6F 6E 20 61 6E 64 20 74      Addition and t
008660:  68 65 20 43 61 72 72 79 20 46 6C 61 67 A0 20 20    he Carry Flag.  
008670:  20 E0 A4 20 20 20 20 20 20 45 78 20 2D 20 73 69     ..      Ex - si
008680:  6E 67 6C 65 20 72 65 67 69 73 74 65 72 20 61 64    ngle register ad
008690:  64 69 74 69 6F 6E A0 20 20 20 20 20 20 20 20 20    dition.         
0086A0:  45 78 20 2D 20 72 65 67 69 73 74 65 72 20 70 61    Ex - register pa
0086B0:  69 72 20 61 64 64 69 74 69 6F 6E A0 20 36 2E 20    ir addition. 6. 
0086C0:  20 53 75 62 74 72 61 63 74 69 6F 6E 20 61 6E 64     Subtraction and
0086D0:  20 74 68 65 20 43 61 72 72 79 20 46 6C 61 67 A0     the Carry Flag.
0086E0:  20 20 20 20 20 20 20 20 20 45 78 20 2D 20 72 65             Ex - re
0086F0:  67 69 73 74 65 72 20 73 75 62 74 72 61 63 74 69    gister subtracti
008700:  6F 6E A0 20 20 20 20 20 20 20 20 20 45 78 20 2D    on.         Ex -
008710:  20 72 65 67 69 73 74 65 72 20 70 61 69 72 20 73     register pair s
008720:  75 62 74 72 61 63 74 69 6F 6E A0 20 37 2E 20 20    ubtraction. 7.  
008730:  49 6E 63 72 65 6D 65 6E 74 20 61 6E 64 20 44 65    Increment and De
008740:  63 72 65 6D 65 6E 74 A0 20 20 20 20 20 20 20 20    crement.        
008750:  20 45 78 20 2D 20 69 6E 63 20 61 6E 64 20 64 65     Ex - inc and de
008760:  63 20 69 6E 73 74 72 75 63 74 69 6F 6E 73 A0 20    c instructions. 
008770:  38 2E 20 2C 0F 20 5A 65 72 6F 20 46 6C 61 67 A0    8. ,. Zero Flag.
008780:  20 20 20 20 20 20 20 20 20 45 78 20 2D 20 7A 65             Ex - ze
008790:  72 6F 20 66 6C 61 67 A0 20 39 2E 20 20 43 6F 6D    ro flag. 9.  Com
0087A0:  70 61 72 65 A0 20 20 20 20 20 20 20 45 78 20 2D    pare.       Ex -
0087B0:  20 63 6F 6D 70 61 72 69 73 6F 6E 20 69 6E 73 74     comparison inst
0087C0:  72 75 63 74 69 6F 6E 73 A0 20 4C 6F 61 64 20 66    ructions. Load f
0087D0:  75 72 74 68 65 72 20 6C 65 73 73 6F 6E 73 20 66    urther lessons f
0087E0:  72 6F 6D 20 74 61 70 65 A3 20 20 20 20 20 20 20    rom tape£       
0087F0:  20 20 20 20 49 4E 54 52 4F 44 55 43 54 49 4F 4E        INTRODUCTION
008800:  A0 A0 20 54 68 65 20 20 5A 38 30 20 69 73 20 20    .. The  Z80 is  
008810:  74 68 65 20 6D 69 63 72 6F 70 72 6F 63 65 73 73    the microprocess
008820:  6F 72 20 20 61 74 20 74 68 65 68 65 61 72 74 20    or  at theheart 
008830:  6F 66 20 79 6F 75 72 20 41 6D 73 74 72 61 64 2E    of your Amstrad.
008840:  20 54 68 69 73 20 70 72 6F 67 72 61 6D 20 77 69     This program wi
008850:  6C 6C 74 65 61 63 68 20 20 20 79 6F 75 20 20 20    llteach   you   
008860:  74 68 65 20 20 20 75 73 65 20 20 20 6F 66 20 20    the   use   of  
008870:  20 61 6C 6C 20 86 A3 20 20 74 68 65 69 6E 73 74     all .£  theinst
008880:  72 75 63 74 69 6F 6E 73 20 61 76 61 69 6C 61 62    ructions availab
008890:  6C 65 20 20 6F 6E 20 20 74 68 65 20 5A 38 30 2C    le  on  the Z80,
0088A0:  20 20 69 6E 61 20 73 65 72 69 65 73 20 6F 66 20      ina series of 
0088B0:  73 69 6D 70 6C 65 20 20 70 72 6F 67 72 65 73 73    simple  progress
0088C0:  69 76 65 20 6C 65 73 73 6F 6E 73 2E A0 20 20 41    ive lessons..  A
0088D0:  66 74 65 72 20 20 65 61 63 68 20 20 20 6C 65 73    fter  each   les
0088E0:  73 6F 6E 2C 20 20 20 73 74 65 70 20 20 62 79 20    son,   step  by 
0088F0:  20 73 74 65 70 65 78 61 6D 70 6C 65 73 20 61 72     stepexamples ar
008900:  65 20 67 69 76 65 6E 2E 20 20 54 6F 20 66 75 72    e given.  To fur
008910:  74 68 65 72 20 20 69 6D 70 72 6F 76 65 79 6F 75    ther  improveyou
008920:  72 20 75 6E 64 65 72 73 74 61 6E 64 69 6E 67 20    r understanding 
008930:  6F 66 20 74 68 65 20 74 6F 70 69 63 2C 20 79 6F    of the topic, yo
008940:  75 20 6D 61 79 74 68 65 6E 20 6D 6F 64 69 66 79    u maythen modify
008950:  20 6F 72 20 72 65 77 72 69 74 65 20 74 68 65 20     or rewrite the 
008960:  65 78 61 6D 70 6C 65 73 2C 20 61 6E 64 72 75 6E    examples, andrun
008970:  20 74 68 65 6D 20 20 70 D6 77 69 74 68 6F 75 74     them  p.without
008980:  20 20 66 65 61 72 20 6F 66 20 20 63 72 61 73 68      fear of  crash
008990:  69 6E 67 20 74 68 65 73 79 73 74 65 6D 2E A0 A0    ing thesystem...
0089A0:  20 50 72 6F 63 65 65 64 20 20 74 68 72 6F 75 67     Proceed  throug
0089B0:  68 20 20 74 68 65 20 6D 65 6E 75 20 62 79 20 20    h  the menu by  
0089C0:  70 72 65 73 73 69 6E 67 45 4E 54 45 52 20 74 6F    pressingENTER to
0089D0:  20 62 65 67 69 6E 20 74 68 65 20 68 69 67 68 6C     begin the highl
0089E0:  69 67 68 74 65 64 20 6C 65 73 73 6F 6E 20 6F 72    ighted lesson or
0089F0:  65 78 61 6D 70 6C 65 2C 20 61 6E 64 20 20 53 50    example, and  SP
008A00:  41 43 45 20 74 6F 20 6A 75 6D 70 20 74 6F 20 74    ACE to jump to t
008A10:  68 65 20 6E 65 78 74 2E 41 74 20 61 6E 79 74 69    he next.At anyti
008A20:  6D 65 20 42 52 45 41 4B 20 77 69 6C 6C 20 72 65    me BREAK will re
008A30:  74 75 72 6E 20 79 6F 75 20 20 74 6F 20 74 68 65    turn you  to the
008A40:  6D 65 6E 75 2E A3 20 20 20 20 49 4E 54 52 4F 44    menu.£    INTROD
008A50:  55 43 54 49 4F 4E 20 54 4F 20 52 55 4E 4E 49 4E    UCTION TO RUNNIN
008A60:  47 20 53 49 4D 55 4C 41 54 4F 52 A0 A0 20 41 6C    G SIMULATOR.. Al
008A70:  6C 20 20 20 65 78 61 6D 70 72 6A 6C 65 73 20 20    l   examprjles  
008A80:  20 61 72 65 20 20 20 72 75 6E 20 20 20 75 73 69     are   run   usi
008A90:  6E 67 20 20 74 68 65 53 69 6D 75 6C 61 74 6F 72    ng  theSimulator
008AA0:  2E 20 41 74 20 74 68 69 73 20 73 74 61 67 65 20    . At this stage 
008AB0:  74 68 65 20 6F 6E 6C 79 20 20 61 72 65 61 73 6F    the only  areaso
008AC0:  66 20 74 68 65 20 73 69 6D 75 6C 61 74 6F 72 20    f the simulator 
008AD0:  73 63 72 65 65 6E 20 74 6F 20 63 6F 6E 73 69 64    screen to consid
008AE0:  65 72 20 20 61 72 65 74 68 65 20 53 6F 75 72 63    er  arethe Sourc
008AF0:  65 20 20 43 6F 64 65 20 28 20 74 68 65 20 74 68    e  Code ( the th
008B00:  69 72 64 20 63 6F 6C 75 6D 6E 20 74 68 61 74 68    ird column thath
008B10:  6F 6C 64 73 20 74 68 65 20 69 6E 73 74 72 75 63    olds the instruc
008B20:  74 69 6F 6E 73 20 29 20 61 6E 64 20 74 68 65 20    tions ) and the 
008B30:  61 72 65 61 20 61 74 74 68 65 20 62 6F 74 74 6F    area atthe botto
008B40:  6D 20 6F 66 20 74 68 65 20 73 63 72 65 65 6E 2C    m of the screen,
008B50:  20 77 68 69 63 68 20 64 69 73 70 6C 61 79 73 74     which displayst
008B60:  68 65 20 63 6F 6E 74 65 6E 74 73 20 20 6F 66 20    he contents  of 
008B70:  20 74 68 65 20 20 72 65 67 69 73 76 25 74 65 72     the  regisv%ter
008B80:  73 2E 20 20 4F 74 68 65 72 61 72 65 61 73 20 20    s.  Otherareas  
008B90:  77 69 6C 6C 20 20 62 65 20 20 64 65 73 63 72 69    will  be  descri
008BA0:  62 65 64 20 20 61 73 20 20 74 68 65 79 20 61 72    bed  as  they ar
008BB0:  65 72 65 71 75 69 72 65 64 2E A0 A0 20 54 68 65    erequired... The
008BC0:  20 61 73 73 65 6D 62 6C 65 72 2C 20 74 68 61 74     assembler, that
008BD0:  20 63 6F 6E 76 65 72 74 73 20 20 69 6E 73 74 72     converts  instr
008BE0:  75 63 74 2D 69 6F 6E 73 20 20 69 6E 74 6F 20 20    uct-ions  into  
008BF0:  20 6D 61 63 68 69 6E 65 20 20 63 6F 64 65 2C 20     machine  code, 
008C00:  77 69 6C 6C 20 20 61 63 63 65 70 74 4C 61 62 65    will  acceptLabe
008C10:  6C 73 2E 20 49 6E 73 74 65 61 64 20 20 6F 66 20    ls. Instead  of 
008C20:  20 70 75 74 74 69 6E 67 20 20 61 6E 20 61 64 64     putting  an add
008C30:  72 65 73 73 69 6E 74 6F 20 74 68 65 20 70 72 6F    ressinto the pro
008C40:  67 72 61 6D 2C 20 77 65 20 63 61 6E 20 67 69 76    gram, we can giv
008C50:  65 20 69 74 20 61 20 6E 61 6D 65 2E 54 68 65 20    e it a name.The 
008C60:  20 61 73 73 65 6D 62 6C 65 72 20 20 77 69 6C 6C     assembler  will
008C70:  20 20 20 74 68 65 6E 20 20 61 6C 6C 6F A2 A1 63       then  allo..c
008C80:  61 74 65 20 20 61 6D 65 6D 6F 72 79 20 20 6C 6F    ate  amemory  lo
008C90:  63 61 74 69 6F 6E 20 74 6F 20 69 74 2E 20 54 68    cation to it. Th
008CA0:  65 20 6E 61 6D 65 20 6D 75 73 74 20 62 65 63 61    e name must beca
008CB0:  6C 6C 65 64 20 20 75 70 20 20 69 6E 20 20 74 68    lled  up  in  th
008CC0:  65 20 20 70 72 6F 67 72 61 6D 20 20 77 69 74 68    e  program  with
008CD0:  20 20 20 69 74 73 69 6E 69 74 69 61 6C 20 63 6F       itsinitial co
008CE0:  6E 64 69 74 69 6F 6E 20 75 73 69 6E 67 20 20 74    ndition using  t
008CF0:  68 65 20 69 6E 73 74 72 75 63 74 69 6F 6E 44 45    he instructionDE
008D00:  46 42 2C 20 44 45 46 69 6E 65 20 42 79 74 65 2E    FB, DEFine Byte.
008D10:  A3 20 44 45 46 42 20 69 73 20 61 6E 20 20 61 73    £ DEFB is an  as
008D20:  73 65 6D 62 6C 65 72 20 69 6E 73 74 72 75 63 74    sembler instruct
008D30:  69 6F 6E 20 6E 6F 74 20 61 5A 38 30 20 20 69 6E    ion not aZ80  in
008D40:  73 74 72 75 63 74 69 6F 6E 2E 20 20 54 68 65 20    struction.  The 
008D50:  61 6C 6C 6F 63 61 74 65 64 20 20 6D 65 6D 6F 72    allocated  memor
008D60:  79 61 64 64 72 65 73 73 20 69 73 20 67 69 76 65    yaddress is give
008D70:  6E 20 69 6E 20 74 68 65 20 66 69 72 73 74 20 A9    n in the first .
008D80:  1C 63 6F 6C 75 6D 6E 2E A0 A0 20 54 68 65 20 73    .column... The s
008D90:  69 6D 75 6C 61 74 6F 72 20 77 69 6C 6C 20 64 69    imulator will di
008DA0:  73 70 6C 61 79 20 74 68 65 20 63 6F 6E 74 65 6E    splay the conten
008DB0:  74 73 6F 66 20 74 68 69 73 20 20 6D 65 6D 6F 72    tsof this  memor
008DC0:  79 20 6C 6F 63 61 74 69 6F 6E 2C 20 69 6E 20 64    y location, in d
008DD0:  65 63 69 6D 61 6C 2C 20 69 6E 74 68 65 20 73 65    ecimal, inthe se
008DE0:  63 6F 6E 64 20 63 6F 6C 75 6D 6E 2E A0 A0 20 42    cond column... B
008DF0:  65 66 6F 72 65 20 65 61 63 68 20 69 6E 73 74 72    efore each instr
008E00:  75 63 74 69 6F 6E 20 69 73 20 65 78 65 63 75 74    uction is execut
008E10:  65 64 20 74 68 65 69 6E 73 74 72 75 63 74 69 6F    ed theinstructio
008E20:  6E 20 69 73 20 64 65 73 63 72 69 62 65 64 20 69    n is described i
008E30:  6E 20 45 4E 47 4C 49 53 48 2E 20 54 72 79 74 6F    n ENGLISH. Tryto
008E40:  20 77 6F 72 6B 20 6F 75 74 20 77 68 61 74 20 20     work out what  
008E50:  73 68 6F 75 6C 64 20 20 68 61 70 70 65 6E 20 20    should  happen  
008E60:  62 65 66 6F 72 65 70 72 65 73 73 69 6E 67 20 20    beforepressing  
008E70:  61 6E 79 20 20 6B 65 79 20 20 20 74 6F 20 20 20    any  key   to   
008E80:  70 B9 CB 65 72 66 6F 72 6D 20 20 20 20 74 68 65    p..erform    the
008E90:  69 6E 73 74 72 75 63 74 69 6F 6E 2E A3 20 59 6F    instruction.£ Yo
008EA0:  75 20 6D 61 79 20 67 6F 20 20 74 68 72 6F 75 67    u may go  throug
008EB0:  68 20 74 68 65 20 65 78 61 6D 70 6C 65 20 61 73    h the example as
008EC0:  20 6D 61 6E 79 74 69 6D 65 73 20 61 73 20 79 6F     manytimes as yo
008ED0:  75 20 6C 69 6B 65 2C 20 75 6E 74 69 6C 20 79 6F    u like, until yo
008EE0:  75 20 20 75 6E 64 65 72 73 74 61 6E 64 69 74 2E    u  understandit.
008EF0:  20 49 66 20 79 6F 75 20 73 74 69 6C 6C 20 66 69     If you still fi
008F00:  6E 64 20 20 64 69 66 66 69 63 75 6C 74 79 2C 20    nd  difficulty, 
008F10:  70 72 65 73 73 45 53 43 2C 20 73 6B 69 70 20 20    pressESC, skip  
008F20:  6F 76 65 72 20 74 68 65 20 6C 65 73 73 6F 6E 73    over the lessons
008F30:  20 61 6E 64 20 72 65 2D 45 4E 54 45 52 74 68 65     and re-ENTERthe
008F40:  20 6C 65 73 73 6F 6E 20 20 77 69 74 68 20 77 68     lesson  with wh
008F50:  69 63 68 20 20 79 6F 75 20 20 61 72 65 20 20 68    ich  you  are  h
008F60:  61 76 69 6E 67 64 69 66 66 69 63 75 6C 74 79 2E    avingdifficulty.
008F70:  20 54 68 65 20 6D 61 6E 75 61 6C 20 68 6F 77 65     The manual howe
008F80:  76 65 72 8B D4 20 20 67 69 76 65 73 20 61 6E 6F    ver..  gives ano
008F90:  75 74 6C 69 6E 65 20 6F 66 20 65 61 63 68 20 6C    utline of each l
008FA0:  65 73 73 6F 6E 2E A0 A0 20 57 68 65 6E 20 20 79    esson... When  y
008FB0:  6F 75 20 20 64 6F 20 20 75 6E 64 65 72 73 74 61    ou  do  understa
008FC0:  6E 64 20 20 74 68 65 20 65 78 61 6D 70 6C 65 73    nd  the examples
008FD0:  67 69 76 65 6E 20 20 74 72 79 20 20 6D 6F 64 69    given  try  modi
008FE0:  66 79 69 6E 67 20 20 74 68 65 6D 20 20 20 75 73    fying  them   us
008FF0:  69 6E 67 20 20 74 68 65 65 64 69 74 6F 72 2E 20    ing  theeditor. 
009000:  20 54 68 65 6E 20 20 74 72 79 20 20 65 6E 74 65     Then  try  ente
009010:  72 69 6E 67 20 20 20 79 6F 75 72 20 20 6F 77 6E    ring   your  own
009020:  70 72 6F 67 72 61 6D 73 2E 20 20 41 6C 6C 20 20    programs.  All  
009030:  70 72 6F 67 72 61 6D 73 20 73 68 6F 75 6C 64 20    programs should 
009040:  65 6E 64 20 77 69 74 68 52 45 54 20 28 20 6F 72    end withRET ( or
009050:  20 72 65 74 75 72 6E 20 29 2E 20 20 20 44 6F 6E     return ).   Don
009060:  27 74 20 20 77 6F 72 72 79 20 69 66 20 79 6F 75    't  worry if you
009070:  66 6F 72 67 65 74 2C 20 74 68 65 20 73 69 6D 75    forget, the simu
009080:  6C 61 74 6F 72 9A A7 20 77 69 6C 6C 20 74 65 6C    lator.. will tel
009090:  6C 20 79 6F 75 2E A0 A0 20 52 65 6D 65 6D 62 65    l you... Remembe
0090A0:  72 2C 20 20 69 74 20 20 69 73 20 20 20 69 6D 70    r,  it  is   imp
0090B0:  6F 73 73 69 62 6C 65 20 20 66 6F 72 20 20 20 61    ossible  for   a
0090C0:  70 72 6F 67 72 61 6D 20 74 6F 20 64 65 73 74 72    program to destr
0090D0:  6F 79 20 79 6F 75 72 20 63 6F 6D 70 75 74 65 72    oy your computer
0090E0:  2E 20 59 6F 75 27 6C 6C 6E 65 65 64 20 61 20 68    . You'llneed a h
0090F0:  61 6D 6D 65 72 20 74 6F 20 64 6F 20 74 68 61 74    ammer to do that
009100:  21 A3 20 4C 44 20 41 2C 33 34 A0 20 20 4C 44 20    !£ LD A,34.  LD 
009110:  42 2C 41 A0 20 20 4C 44 20 28 33 38 36 37 29 2C    B,A.  LD (3867),
009120:  41 A0 20 20 4C 44 20 41 2C 28 53 54 4F 52 45 29    A.  LD A,(STORE)
009130:  A0 20 20 4C 44 20 28 33 38 36 37 29 2C 41 A0 20    .  LD (3867),A. 
009140:  20 4C 44 20 41 2C 42 A0 20 20 4C 44 20 28 53 54     LD A,B.  LD (ST
009150:  4F 52 45 29 2C 41 A0 20 20 4C 44 20 43 2C 42 A0    ORE),A.  LD C,B.
009160:  20 20 4C 44 20 41 2C 28 33 38 36 37 29 A0 20 20      LD A,(3867).  
009170:  4C 44 20 41 2C 36 37 A0 20 20 4C 44 20 28 33 38    LD A,67.  LD (38
009180:  36 36 29 2C 41 A0 20 DF 86 20 52 45 54 A0 20 20    66),A. .. RET.  
009190:  A0 20 53 54 4F 52 45 20 44 45 46 42 20 31 32 34    . STORE DEFB 124
0091A0:  A0 20 20 44 45 46 42 20 30 A0 20 20 20 A0 20 20    .  DEFB 0.   .  
0091B0:  20 20 20 20 20 20 20 52 45 47 49 53 54 45 52 20           REGISTER 
0091C0:  50 41 49 52 20 45 58 41 4D 50 4C 45 53 A0 A0 20    PAIR EXAMPLES.. 
0091D0:  54 68 65 20 20 65 78 61 6D 70 6C 65 20 69 6C 6C    The  example ill
0091E0:  75 73 74 72 61 74 65 73 20 20 65 61 63 68 20 20    ustrates  each  
0091F0:  74 79 70 65 20 6F 66 69 6E 73 74 72 75 63 74 69    type ofinstructi
009200:  6F 6E 20 20 74 68 61 74 20 20 6C 6F 61 64 73 20    on  that  loads 
009210:  72 65 67 69 73 74 65 72 20 70 61 69 72 73 2E 49    register pairs.I
009220:  74 20 61 6C 73 6F 20 20 64 65 6D 6F 6E 73 74 72    t also  demonstr
009230:  61 74 65 73 20 20 74 68 61 74 20 61 20 20 72 65    ates  that a  re
009240:  67 69 73 74 65 72 2F 6D 65 6D 6F 72 79 20 20 70    gister/memory  p
009250:  61 69 72 20 20 61 72 65 20 20 73 74 69 6C 6C 20    air  are  still 
009260:  20 74 77 6F 20 69 6E 64 69 76 69 64 75 61 6C 72     two individualr
009270:  65 67 69 73 74 65 72 73 20 6F 72 20 6D 65 6D 6F    egisters or memo
009280:  72 79 20 6C 6F 63 61 74 69 56 30 6F 6E 73 20 61    ry locatiV0ons a
009290:  6E 64 20 63 61 6E 20 62 65 74 72 65 61 74 65 64    nd can betreated
0092A0:  20 61 73 20 73 75 63 68 2E A0 A0 20 41 6E 6F 74     as such... Anot
0092B0:  68 65 72 20 20 20 20 61 73 73 65 6D 62 6C 65 72    her    assembler
0092C0:  20 20 20 20 69 6E 73 74 72 75 63 74 69 6F 6E 20        instruction 
0092D0:  20 69 73 69 6E 74 72 6F 64 75 63 65 64 2C 20 20     isintroduced,  
0092E0:  74 68 65 20 20 44 45 46 57 20 20 69 6E 73 74 72    the  DEFW  instr
0092F0:  75 63 74 69 6F 6E 2E 20 54 68 65 61 73 73 65 6D    uction. Theassem
009300:  62 6C 65 72 20 61 6C 6C 6F 63 61 74 65 73 20 20    bler allocates  
009310:  32 20 20 6D 65 6D 6F 72 79 20 6C 6F 63 61 74 69    2  memory locati
009320:  6F 6E 73 74 6F 20 74 68 65 20 20 61 73 73 6F 63    onsto the  assoc
009330:  69 61 74 65 64 20 20 6C 61 62 65 6C 2E 20 20 54    iated  label.  T
009340:  68 65 20 20 20 6E 75 6D 62 65 72 61 66 74 65 72    he   numberafter
009350:  20 20 74 68 65 20 20 20 44 45 46 57 20 20 20 73      the   DEFW   s
009360:  65 74 73 20 20 20 74 68 65 20 20 20 69 6E 69 74    ets   the   init
009370:  69 61 6C 63 6F 6E 64 69 74 69 6F 6E 73 2E A0 A0    ialconditions...
009380:  20 54 68 65 20 61 64 64 72 65 73 E1 1E 73 20 69     The addres..s i
009390:  6E 20 74 68 65 20 66 69 72 73 74 20 20 63 6F 6C    n the first  col
0093A0:  75 6D 6E 20 69 73 20 74 68 65 6C 6F 77 20 20 62    umn is thelow  b
0093B0:  79 74 65 20 61 64 64 72 65 73 73 2E 20 20 54 68    yte address.  Th
0093C0:  65 20 20 73 65 63 6F 6E 64 20 20 20 63 6F 6C 75    e  second   colu
0093D0:  6D 6E 64 69 73 70 6C 61 79 73 20 20 74 68 65 20    mndisplays  the 
0093E0:  20 63 6F 6E 74 65 6E 74 73 20 20 6F 66 20 20 74     contents  of  t
0093F0:  68 65 20 70 61 69 72 20 6F 66 6D 65 6D 6F 72 79    he pair ofmemory
009400:  20 6C 6F 63 61 74 69 6F 6E 73 20 61 73 20 61 20     locations as a 
009410:  73 69 6E 67 6C 65 20 6E 75 6D 62 65 72 2E A3 20    single number.£ 
009420:  4C 44 20 44 45 2C 32 35 36 A0 20 20 4C 44 20 45    LD DE,256.  LD E
009430:  2C 34 A0 20 20 4C 44 20 28 53 54 4F 52 45 29 2C    ,4.  LD (STORE),
009440:  44 45 A0 20 20 4C 44 20 28 4C 4F 57 29 2C 44 45    DE.  LD (LOW),DE
009450:  A0 20 20 4C 44 20 41 2C 32 A0 20 20 4C 44 20 28    .  LD A,2.  LD (
009460:  48 49 47 48 29 2C 41 A0 20 20 4C 44 20 48 4C 2C    HIGH),A.  LD HL,
009470:  28 4C 4F 57 29 A0 20 20 45 58 20 44 45 2C 48 4C    (LOW).  EX DE,HL
009480:  A0 20 20 4C 44 20 44 2C 30 A0 20 20 52 EC 57 45    .  LD D,0.  R.WE
009490:  54 A0 20 20 A0 20 53 54 4F 52 45 20 44 45 46 57    T.  . STORE DEFW
0094A0:  20 33 32 30 30 30 A0 20 4C 4F 57 20 20 20 44 45     32000. LOW   DE
0094B0:  46 42 20 30 A0 20 48 49 47 48 20 20 44 45 46 42    FB 0. HIGH  DEFB
0094C0:  20 30 A0 20 20 A0 20 20 20 A0 20 20 20 20 20 45     0.  .   .     E
0094D0:  58 41 4D 50 4C 45 53 20 4F 46 20 49 4E 44 49 52    XAMPLES OF INDIR
0094E0:  45 43 54 20 41 44 44 52 45 53 53 49 4E 47 A0 A0    ECT ADDRESSING..
0094F0:  20 20 54 68 65 73 65 20 20 65 78 61 6D 70 6C 65      These  example
009500:  73 20 20 69 6C 6C 75 73 74 72 61 74 65 20 20 20    s  illustrate   
009510:  69 6E 64 69 72 65 63 74 61 64 64 72 65 73 73 69    indirectaddressi
009520:  6E 67 2E 20 20 20 41 74 20 20 20 74 68 69 73 20    ng.   At   this 
009530:  20 20 73 74 61 67 65 20 20 69 74 20 20 20 69 73      stage  it   is
009540:  69 6D 70 6F 73 73 69 62 6C 65 20 74 6F 20 20 64    impossible to  d
009550:  65 6D 6F 6E 73 74 72 61 74 65 20 20 69 74 73 20    emonstrate  its 
009560:  20 75 73 65 66 75 6C 2D 6E 65 73 73 2E 20 20 49     useful-ness.  I
009570:  74 20 69 73 20 65 6D 70 6C 6F 79 65 64 20 65 78    t is employed ex
009580:  74 65 6E 73 69 76 65 20 69 6E 20 6C 61 74 65 0E    tensive in late.
009590:  B5 72 65 78 61 6D 70 6C 65 73 A3 20 4C 44 20 48    .rexamples£ LD H
0095A0:  4C 2C 4C 4F 57 A0 20 20 4C 44 20 43 2C 28 48 4C    L,LOW.  LD C,(HL
0095B0:  29 A0 20 20 4C 44 20 48 4C 2C 48 49 47 48 A0 20    ).  LD HL,HIGH. 
0095C0:  20 4C 44 20 42 2C 28 48 4C 29 A0 20 20 4C 44 20     LD B,(HL).  LD 
0095D0:  41 2C 28 42 43 29 A0 20 20 4C 44 20 44 45 2C 33    A,(BC).  LD DE,3
0095E0:  38 36 30 A0 20 20 4C 44 20 28 44 45 29 2C 41 A0    860.  LD (DE),A.
0095F0:  20 20 4C 44 20 28 48 4C 29 2C 30 A0 20 20 4C 44      LD (HL),0.  LD
009600:  20 42 43 2C 33 38 36 32 A0 20 20 4C 44 20 28 42     BC,3862.  LD (B
009610:  43 29 2C 41 A0 20 20 52 45 54 A0 20 20 A0 20 4C    C),A.  RET.  . L
009620:  4F 57 20 20 20 44 45 46 42 20 32 31 A0 20 48 49    OW   DEFB 21. HI
009630:  47 48 20 20 44 45 46 42 20 31 35 A0 20 20 44 45    GH  DEFB 15.  DE
009640:  46 42 20 30 A0 20 20 20 A0 20 20 20 45 58 41 4D    FB 0.   .   EXAM
009650:  50 4C 45 53 20 4F 46 20 53 49 4E 47 4C 45 20 52    PLES OF SINGLE R
009660:  45 47 49 53 54 45 52 20 41 44 44 49 54 49 4F 4E    EGISTER ADDITION
009670:  A0 A0 20 54 68 65 20 20 65 78 61 6D 70 6C 65 20    .. The  example 
009680:  20 61 64 64 73 20 20 74 6F 67 65 74 68 65 72 20     adds  together 
009690:  20 57 67 20 74 68 65 20 20 74 77 6F 6E 75 6D 62     Wg the  twonumb
0096A0:  65 72 73 20 20 38 37 34 30 20 20 61 6E 64 20 20    ers  8740  and  
0096B0:  31 32 36 30 20 20 20 75 73 69 6E 67 20 20 73 69    1260   using  si
0096C0:  6E 67 6C 65 72 65 67 69 73 74 65 72 20 20 20 61    ngleregister   a
0096D0:  64 64 69 74 69 6F 6E 20 20 6F 6E 6C 79 2E 20 20    ddition  only.  
0096E0:  20 54 68 65 20 20 64 6F 75 62 6C 65 6C 65 6E 67     The  doubleleng
0096F0:  74 68 20 20 6E 75 6D 62 65 72 73 20 61 72 65 20    th  numbers are 
009700:  68 65 6C 64 20 69 6E 20 42 43 20 61 6E 64 20 44    held in BC and D
009710:  45 20 73 6F 74 68 61 74 20 20 74 68 65 20 20 72    E sothat  the  r
009720:  65 73 75 6C 74 73 20 20 63 61 6E 20 20 20 62 65    esults  can   be
009730:  20 20 20 64 69 73 70 6C 61 79 65 64 65 61 73 69       displayedeasi
009740:  6C 79 2E 20 20 20 54 68 69 73 20 6D 65 74 68 6F    ly.   This metho
009750:  64 20 6F 66 20 61 64 64 69 74 69 6F 6E 20 63 61    d of addition ca
009760:  6E 20 62 65 70 65 72 66 6F 72 6D 65 64 20 75 73    n beperformed us
009770:  69 6E 67 20 72 65 67 69 73 74 65 72 20 70 61 69    ing register pai
009780:  72 20 20 61 64 64 69 74 69 6F 6E 2C 61 73 20 77    r  addition,as w
009790:  65 6C 6C E4 44 2C 20 20 74 6F 20 61 64 64 20 74    ell.D,  to add t
0097A0:  6F 67 65 74 68 65 72 20 6E 75 6D 62 65 72 73 20    ogether numbers 
0097B0:  6F 66 20 61 6E 79 6C 65 6E 67 74 68 2E A0 A0 20    of anylength... 
0097C0:  54 68 65 20 73 74 61 74 65 20 20 6F 66 20 20 74    The state  of  t
0097D0:  68 65 20 69 6E 64 69 76 69 64 75 61 6C 20 66 6C    he individual fl
0097E0:  61 67 73 20 61 72 65 64 69 73 70 6C 61 79 65 64    ags aredisplayed
0097F0:  20 74 6F 20 74 68 65 20 6C 65 66 74 20 6F 66 20     to the left of 
009800:  74 68 65 20 72 65 67 69 73 74 65 72 73 2E A3 20    the registers.£ 
009810:  4C 44 20 44 45 2C 38 37 34 30 A0 20 20 4C 44 20    LD DE,8740.  LD 
009820:  42 43 2C 31 32 36 30 A0 20 20 4C 44 20 41 2C 45    BC,1260.  LD A,E
009830:  A0 20 20 41 44 44 20 41 2C 43 A0 20 20 4C 44 20    .  ADD A,C.  LD 
009840:  43 2C 41 A0 20 20 4C 44 20 41 2C 44 A0 20 20 41    C,A.  LD A,D.  A
009850:  44 43 20 41 2C 42 A0 20 20 4C 44 20 42 2C 41 A0    DC A,B.  LD B,A.
009860:  20 20 A0 20 20 4C 44 20 48 4C 2C 53 54 4F 52 45      .  LD HL,STORE
009870:  A0 20 20 4C 44 20 41 2C 31 35 A0 20 20 41 44 44    .  LD A,15.  ADD
009880:  20 41 2C 28 48 4C 29 A0 20 20 52 45 54 A0 20 20     A,(HL).  RET.  
009890:  A0 20 53 54 4F 10 11 52 45 20 44 45 46 42 20 32    . STO..RE DEFB 2
0098A0:  35 A0 20 20 A0 20 20 20 20 45 58 41 4D 50 4C 45    5.  .    EXAMPLE
0098B0:  20 4F 46 20 52 45 47 49 53 54 45 52 20 50 41 49     OF REGISTER PAI
0098C0:  52 20 41 44 44 49 54 49 4F 4E A0 A0 20 54 68 69    R ADDITION.. Thi
0098D0:  73 20 20 65 78 61 6D 70 6C 65 20 20 65 66 66 65    s  example  effe
0098E0:  63 74 69 76 65 6C 79 20 6D 75 6C 74 69 70 6C 69    ctively multipli
0098F0:  65 73 20 61 6E 75 6D 62 65 72 20 20 68 65 6C 64    es anumber  held
009900:  20 69 6E 20 74 68 65 20 20 48 4C 20 72 65 67 69     in the  HL regi
009910:  73 74 65 72 20 70 61 69 72 20 62 79 31 30 20 20    ster pair by10  
009920:  75 73 69 6E 67 20 20 20 61 64 64 69 74 69 6F 6E    using   addition
009930:  20 20 20 74 6F 20 20 20 73 75 63 63 65 73 73 69       to   successi
009940:  76 65 6C 79 6D 75 6C 74 69 70 6C 79 20 62 79 20    velymultiply by 
009950:  32 2E A3 20 4C 44 20 48 4C 2C 28 53 54 4F 52 45    2.£ LD HL,(STORE
009960:  29 A0 20 20 41 44 44 20 48 4C 2C 48 4C A0 20 20    ).  ADD HL,HL.  
009970:  41 44 44 20 48 4C 2C 48 4C A0 20 20 4C 44 20 44    ADD HL,HL.  LD D
009980:  45 2C 28 53 54 4F 52 45 29 A0 20 20 41 44 44 20    E,(STORE).  ADD 
009990:  48 4C 2C 44 45 A0 20 C2 68 20 41 44 44 20 48 4C    HL,DE. .h ADD HL
0099A0:  2C 48 4C A0 20 20 4C 44 20 28 53 54 4F 52 45 29    ,HL.  LD (STORE)
0099B0:  2C 48 4C A0 20 20 A0 20 20 4C 44 20 48 4C 2C 31    ,HL.  .  LD HL,1
0099C0:  30 30 30 A0 20 20 4C 44 20 41 2C 32 35 35 A0 20    000.  LD A,255. 
0099D0:  20 41 44 44 20 41 2C 31 A0 20 20 41 44 43 20 48     ADD A,1.  ADC H
0099E0:  4C 2C 48 4C A0 20 20 52 45 54 A0 20 20 A0 20 53    L,HL.  RET.  . S
0099F0:  54 4F 52 45 20 44 45 46 57 20 36 30 30 30 A0 20    TORE DEFW 6000. 
009A00:  20 A0 20 20 45 58 41 4D 50 4C 45 20 4F 46 20 53     .  EXAMPLE OF S
009A10:  49 4E 47 4C 45 20 52 45 47 49 53 54 45 52 20 53    INGLE REGISTER S
009A20:  55 42 54 52 41 43 54 49 4F 4E A0 A0 20 54 68 69    UBTRACTION.. Thi
009A30:  73 20 65 78 61 6D 70 6C 65 20 73 75 62 74 72 61    s example subtra
009A40:  63 74 73 20 20 31 32 36 30 20 20 66 72 6F 6D 20    cts  1260  from 
009A50:  38 37 34 30 75 73 69 6E 67 20 20 6F 6E 6C 79 20    8740using  only 
009A60:  73 69 6E 67 6C 65 20 72 65 67 69 73 74 65 72 20    single register 
009A70:  73 75 62 74 72 61 63 74 69 6F 6E 2E 54 68 65 20    subtraction.The 
009A80:  20 74 77 6F 20 20 6E 75 6D 62 65 72 73 20 20 61     two  numbers  a
009A90:  72 65 20 68 65 6C 64 20 69 F0 1C 6E 20 61 6C 6C    re held i..n all
009AA0:  6F 63 61 74 65 64 6D 65 6D 6F 72 79 20 6C 6F 63    ocatedmemory loc
009AB0:  61 74 69 6F 6E 73 20 74 68 69 73 20 74 69 6D 65    ations this time
009AC0:  2E A0 A0 20 54 68 69 73 20 20 6D 65 74 68 6F 64    ... This  method
009AD0:  20 20 20 6F 66 20 20 73 75 62 74 72 61 63 74 69       of  subtracti
009AE0:  6F 6E 20 20 63 61 6E 20 20 62 65 65 78 74 65 6E    on  can  beexten
009AF0:  64 65 64 20 20 20 74 6F 20 20 61 6E 79 20 20 6C    ded   to  any  l
009B00:  65 6E 67 74 68 20 20 20 6E 75 6D 62 65 72 20 20    ength   number  
009B10:  61 6E 64 72 65 67 69 73 74 65 72 20 70 61 69 72    andregister pair
009B20:  20 73 75 62 74 72 61 63 74 69 6F 6E 2E A3 20 4C     subtraction.£ L
009B30:  44 20 48 4C 2C 4E 55 4D 31 A0 20 20 4C 44 20 44    D HL,NUM1.  LD D
009B40:  45 2C 4E 55 4D 32 A0 20 20 4C 44 20 41 2C 28 44    E,NUM2.  LD A,(D
009B50:  45 29 A0 20 20 53 55 42 20 28 48 4C 29 A0 20 20    E).  SUB (HL).  
009B60:  4C 44 20 28 44 45 29 2C 41 A0 20 20 4C 44 20 45    LD (DE),A.  LD E
009B70:  2C 31 38 A0 20 20 4C 44 20 4C 2C 32 30 A0 20 20    ,18.  LD L,20.  
009B80:  4C 44 20 41 2C 28 44 45 29 A0 20 20 53 42 43 20    LD A,(DE).  SBC 
009B90:  41 2C 28 48 4C 29 A0 20 20 4C 44 07 80 20 28 44    A,(HL).  LD.. (D
009BA0:  45 29 2C 41 A0 20 20 52 45 54 A0 20 20 A0 20 4E    E),A.  RET.  . N
009BB0:  55 4D 32 20 20 44 45 46 57 20 38 37 34 30 A0 20    UM2  DEFW 8740. 
009BC0:  4E 55 4D 31 20 20 44 45 46 57 20 31 32 36 30 A0    NUM1  DEFW 1260.
009BD0:  20 20 A0 20 20 A0 20 20 45 58 41 4D 50 4C 45 20      .  .  EXAMPLE 
009BE0:  55 53 49 4E 47 20 52 45 47 49 53 54 45 52 20 50    USING REGISTER P
009BF0:  41 49 52 20 53 55 42 54 52 41 43 54 49 4F 4E A0    AIR SUBTRACTION.
009C00:  A0 20 54 68 69 73 20 65 78 61 6D 70 6C 65 20 69    . This example i
009C10:  6C 6C 75 73 74 72 61 74 65 73 20 73 75 62 74 72    llustrates subtr
009C20:  61 63 74 69 6F 6E 20 6F 66 72 65 67 69 73 74 65    action ofregiste
009C30:  72 20 70 61 69 72 73 2E 20 20 49 74 20 73 75 62    r pairs.  It sub
009C40:  74 72 61 63 74 73 20 20 31 35 33 36 20 66 72 6F    tracts  1536 fro
009C50:  6D 36 35 35 33 36 2E 20 20 20 41 74 20 20 6C 65    m65536.   At  le
009C60:  61 73 74 20 33 20 62 79 74 65 73 20 6F 66 20 6D    ast 3 bytes of m
009C70:  65 6D 6F 72 79 20 61 72 65 72 65 71 75 69 72 65    emory arerequire
009C80:  64 20 20 74 6F 20 20 68 6F 6C 64 20 20 74 68 65    d  to  hold  the
009C90:  20 20 6C 61 74 74 65 72 20 20 6E 75 6D B7 D9 62      latter  num..b
009CA0:  65 72 2C 74 68 65 20 68 69 67 68 65 73 74 20 62    er,the highest b
009CB0:  79 74 65 20 20 72 65 70 72 65 73 65 6E 74 69 6E    yte  representin
009CC0:  67 20 36 35 35 33 36 2E A0 A0 20 41 6C 74 68 6F    g 65536... Altho
009CD0:  75 67 68 20 20 41 44 43 20 61 6E 64 20 20 53 42    ugh  ADC and  SB
009CE0:  43 20 20 6D 61 79 20 72 65 71 75 69 72 65 20 74    C  may require t
009CF0:  68 65 43 61 72 72 79 20 20 66 6C 61 67 20 74 6F    heCarry  flag to
009D00:  20 20 62 65 20 63 6C 65 61 72 65 64 20 66 69 72      be cleared fir
009D10:  73 74 2C 20 69 66 20 74 68 65 70 72 65 76 69 6F    st, if theprevio
009D20:  75 73 20 63 61 6C 63 75 6C 61 74 69 6F 6E 20 20    us calculation  
009D30:  4E 45 56 45 52 20 72 65 73 75 6C 74 73 20 69 6E    NEVER results in
009D40:  20 61 63 61 72 72 79 20 62 65 69 6E 67 20 20 67     acarry being  g
009D50:  65 6E 65 72 61 74 65 64 2C 20 74 68 69 73 20 73    enerated, this s
009D60:  74 65 70 20 6D 61 79 20 62 65 6F 6D 69 74 74 65    tep may beomitte
009D70:  64 2E 20 20 48 6F 77 65 76 65 72 20 69 74 20 69    d.  However it i
009D80:  73 20 6F 66 74 65 6E 20 20 62 65 74 74 65 72 20    s often  better 
009D90:  74 6F 62 65 20 73 61 66 65 20 61 6E 64 20 69 18    tobe safe and i.
009DA0:  D3 6E 63 6C 75 64 65 20 69 74 2C 20 20 74 68 61    .nclude it,  tha
009DB0:  6E 20 20 6C 6F 6F 6B 20 20 66 6F 72 74 68 65 20    n  look  forthe 
009DC0:  72 61 6E 64 6F 6D 6C 79 20 6F 63 63 75 72 72 69    randomly occurri
009DD0:  6E 67 20 66 61 75 6C 74 20 74 68 61 74 20 69 74    ng fault that it
009DE0:  20 63 61 6E 67 65 6E 65 72 61 74 65 2E A3 20 4C     cangenerate.£ L
009DF0:  44 20 48 4C 2C 28 4E 55 4D 31 4C 29 A0 20 20 4C    D HL,(NUM1L).  L
009E00:  44 20 44 45 2C 28 4E 55 4D 32 4C 29 A0 20 20 53    D DE,(NUM2L).  S
009E10:  42 43 20 48 4C 2C 44 45 A0 20 20 4C 44 20 28 41    BC HL,DE.  LD (A
009E20:  4E 53 4C 29 2C 48 4C A0 20 20 4C 44 20 48 4C 2C    NSL),HL.  LD HL,
009E30:  28 4E 55 4D 31 48 29 A0 20 20 4C 44 20 44 45 2C    (NUM1H).  LD DE,
009E40:  30 A0 20 20 53 42 43 20 48 4C 2C 44 45 A0 20 20    0.  SBC HL,DE.  
009E50:  4C 44 20 28 41 4E 53 48 29 2C 48 4C A0 20 20 52    LD (ANSH),HL.  R
009E60:  45 54 A0 20 20 A0 20 4E 55 4D 31 4C 20 44 45 46    ET.  . NUM1L DEF
009E70:  57 20 30 A0 20 4E 55 4D 31 48 20 44 45 46 57 20    W 0. NUM1H DEFW 
009E80:  31 20 2A 36 35 35 33 36 A0 20 4E 55 4D 32 4C 20    1 *65536. NUM2L 
009E90:  44 45 46 57 20 31 35 33 36 A0 20 41 4E 53 4C 20    DEFW 1536. ANSL 
009EA0:  20 B9 84 44 45 46 57 20 30 A0 20 41 4E 53 48 20     ..DEFW 0. ANSH 
009EB0:  20 44 45 46 57 20 30 A0 20 20 A0 20 20 20 20 45     DEFW 0.  .    E
009EC0:  58 41 4D 50 4C 45 20 4F 46 20 49 4E 43 52 45 4D    XAMPLE OF INCREM
009ED0:  45 4E 54 20 41 4E 44 20 44 45 43 52 45 4D 45 4E    ENT AND DECREMEN
009EE0:  54 A0 A0 20 41 74 20 20 70 72 65 73 65 6E 74 20    T.. At  present 
009EF0:  20 74 68 65 20 20 70 72 6F 67 72 61 6D 73 20 74     the  programs t
009F00:  68 61 74 20 63 61 6E 20 20 62 65 77 72 69 74 74    hat can  bewritt
009F10:  65 6E 20 61 72 65 20 73 6F 6D 65 77 68 61 74 20    en are somewhat 
009F20:  6C 69 6D 69 74 65 64 2E A0 20 49 4E 43 20 20 61    limited.. INC  a
009F30:  6E 64 20 20 44 45 43 20 72 65 61 6C 6C 79 20 6F    nd  DEC really o
009F40:  6E 6C 79 20 62 65 63 6F 6D 65 20 75 73 65 66 75    nly become usefu
009F50:  6C 69 6E 20 63 6F 6E 6A 75 6E 63 74 69 6F 6E 20    lin conjunction 
009F60:  77 69 74 68 20 69 6E 73 74 72 75 63 74 69 6F 6E    with instruction
009F70:  73 20 20 74 6F 20 20 62 65 69 6E 74 72 6F 64 75    s  to  beintrodu
009F80:  63 65 64 20 73 68 6F 72 74 6C 79 2E A3 20 4C 44    ced shortly.£ LD
009F90:  20 43 2C 35 A0 20 20 4C 44 20 48 4C 2C 53 54 4F     C,5.  LD HL,STO
009FA0:  52 45 A0 B4 A6 20 20 4C 44 20 28 48 4C 29 2C 43    RE...  LD (HL),C
009FB0:  A0 20 20 49 4E 43 20 43 A0 20 20 49 4E 43 20 48    .  INC C.  INC H
009FC0:  4C A0 20 20 4C 44 20 28 48 4C 29 2C 43 A0 20 20    L.  LD (HL),C.  
009FD0:  44 45 43 20 43 A0 20 20 49 4E 43 20 4C A0 20 20    DEC C.  INC L.  
009FE0:  4C 44 20 28 48 4C 29 2C 43 A0 20 20 49 4E 43 20    LD (HL),C.  INC 
009FF0:  48 A0 20 20 52 45 54 A0 20 20 A0 20 53 54 4F 52    H.  RET.  . STOR
00A000:  45 20 44 45 46 42 20 30 A0 20 20 44 45 46 42 20    E DEFB 0.  DEFB 
00A010:  30 A0 20 20 44 45 46 42 20 30 A0 20 20 A0 20 20    0.  DEFB 0.  .  
00A020:  20 20 20 20 20 20 20 45 58 41 4D 50 4C 45 53 20           EXAMPLES 
00A030:  4F 46 20 5A 45 52 4F 20 46 4C 41 47 A0 A0 20 57    OF ZERO FLAG.. W
00A040:  68 69 6C 65 20 20 20 72 75 6E 6E 69 6E 67 20 20    hile   running  
00A050:  74 68 69 73 20 20 65 78 61 6D 70 6C 65 20 20 74    this  example  t
00A060:  72 79 20 20 74 6F 70 72 65 64 69 63 74 20 74 68    ry  topredict th
00A070:  65 20 73 74 61 74 65 20 6F 66 20 74 68 65 20 5A    e state of the Z
00A080:  65 72 6F 20 66 6C 61 67 20 61 66 74 65 72 74 68    ero flag afterth
00A090:  65 20 69 6E 73 74 72 75 63 74 69 6F 6E 20 68 61    e instruction ha
00A0A0:  73 20 62 65 65 C5 1C 6E 20 70 65 72 66 6F 72 6D    s bee..n perform
00A0B0:  65 64 2E A3 20 4C 44 20 48 4C 2C 32 35 37 A0 20    ed.£ LD HL,257. 
00A0C0:  20 44 45 43 20 4C A0 20 20 4C 44 20 41 2C 32 33     DEC L.  LD A,23
00A0D0:  A0 20 20 53 55 42 20 32 33 A0 20 20 4C 44 20 44    .  SUB 23.  LD D
00A0E0:  45 2C 32 35 36 A0 20 20 49 4E 43 20 41 A0 20 20    E,256.  INC A.  
00A0F0:  53 42 43 20 48 4C 2C 44 45 A0 20 20 49 4E 43 20    SBC HL,DE.  INC 
00A100:  48 A0 20 20 53 55 42 20 32 A0 20 20 53 42 43 20    H.  SUB 2.  SBC 
00A110:  48 4C 2C 44 45 A0 20 20 4C 44 20 48 4C 2C 31 A0    HL,DE.  LD HL,1.
00A120:  20 20 44 45 43 20 48 4C A0 20 20 52 45 54 A0 20      DEC HL.  RET. 
00A130:  20 A0 20 20 A0 20 20 20 A0 20 20 20 20 20 20 20     .  .   .       
00A140:  20 20 20 20 20 20 20 20 43 4F 4D 50 41 52 45 A0            COMPARE.
00A150:  A0 20 20 53 6F 20 20 66 61 72 20 20 20 61 6C 6C    .  So  far   all
00A160:  20 20 69 6E 73 74 72 75 63 74 69 6F 6E 73 20 20      instructions  
00A170:  77 65 20 20 20 68 61 76 65 64 69 73 63 75 73 73    we   havediscuss
00A180:  65 64 20 20 74 68 61 74 20 20 61 66 66 65 63 74    ed  that  affect
00A190:  20 20 74 68 65 20 20 43 61 72 72 79 20 20 20 6F      the  Carry   o
00A1A0:  72 5A 65 72 6F 20 66 50 AF 6C 61 67 73 20 20 61    rZero fP.lags  a
00A1B0:  6C 73 6F 20 20 61 66 66 65 63 74 20 20 74 68 65    lso  affect  the
00A1C0:  20 20 20 72 65 67 69 73 74 65 72 63 6F 6E 63 65       registerconce
00A1D0:  72 6E 65 64 2E 20 54 68 65 72 65 20 61 72 65 20    rned. There are 
00A1E0:  61 20 6E 75 6D 62 65 72 20 20 6F 66 20 75 73 65    a number  of use
00A1F0:  66 75 6C 69 6E 73 74 72 75 63 74 69 6F 6E 73 20    fulinstructions 
00A200:  74 68 61 74 20 6F 6E 6C 79 20 61 66 66 65 63 74    that only affect
00A210:  20 66 6C 61 67 73 2E 20 54 68 65 63 6F 6D 70 61     flags. Thecompa
00A220:  72 65 20 6F 72 20 20 43 50 20 20 69 6E 73 74 72    re or  CP  instr
00A230:  75 63 74 69 6F 6E 20 20 69 73 20 20 6F 6E 65 20    uction  is  one 
00A240:  20 6F 66 74 68 65 73 65 2E A0 A0 20 43 50 20 20     ofthese... CP  
00A250:  20 63 6F 6D 70 61 72 65 73 20 20 74 68 65 20 20     compares  the  
00A260:  63 6F 6E 74 65 6E 74 73 20 20 6F 66 20 74 68 65    contents  of the
00A270:  20 20 41 72 65 67 69 73 74 65 72 20 77 69 74 68      Aregister with
00A280:  20 20 61 20 6E 75 6D 62 65 72 20 20 28 43 50 20      a number  (CP 
00A290:  6E 29 2C 20 61 6E 6F 74 68 65 72 72 65 67 69 73    n), anotherregis
00A2A0:  74 65 72 20 20 28 43 50 20 82 88 72 29 2C 20 6F    ter  (CP ..r), o
00A2B0:  72 20 61 6E 79 20 6D 65 6D 6F 72 79 20 6C 6F 63    r any memory loc
00A2C0:  61 74 69 6F 6E 69 6E 64 69 72 65 63 74 6C 79 20    ationindirectly 
00A2D0:  20 61 64 64 72 65 73 73 65 64 20 20 74 68 72 6F     addressed  thro
00A2E0:  75 67 68 20 20 74 68 65 20 20 20 48 4C 72 65 67    ugh  the   HLreg
00A2F0:  69 73 74 65 72 20 20 70 61 69 72 20 20 28 20 43    ister  pair  ( C
00A300:  50 20 28 48 4C 29 20 29 2E 20 54 68 65 20 63 6F    P (HL) ). The co
00A310:  6D 70 61 72 65 69 6E 73 74 72 75 63 74 69 6F 6E    mpareinstruction
00A320:  20 69 73 20 65 66 66 65 63 74 69 76 65 6C 79 20     is effectively 
00A330:  20 53 55 42 20 20 62 75 74 20 74 68 65 72 65 73     SUB  but theres
00A340:  75 6C 74 20 20 64 6F 65 73 20 6E 6F 74 20 61 66    ult  does not af
00A350:  66 65 63 74 20 20 74 68 65 20 63 6F 6E 74 65 6E    fect  the conten
00A360:  74 73 20 6F 66 74 68 65 20 41 20 72 65 67 69 73    ts ofthe A regis
00A370:  74 65 72 2E A3 20 49 66 20 20 6E 20 20 69 73 20    ter.£ If  n  is 
00A380:  20 74 68 65 20 20 6E 75 6D 62 65 72 20 20 77 69     the  number  wi
00A390:  74 68 20 77 68 69 63 68 20 41 20 69 73 63 6F 6D    th which A iscom
00A3A0:  70 61 72 65 64 2C 20 74 68 65 6E 3D E0 20 74 68    pared, then=. th
00A3B0:  65 20 66 6F 6C 6C 6F 77 69 6E 67 20 72 65 73 75    e following resu
00A3C0:  6C 74 73 20 3A 2D 20 A0 20 20 20 20 20 20 20 20    lts :- .        
00A3D0:  20 20 20 20 20 20 20 20 20 20 20 20 43 61 72 72                Carr
00A3E0:  79 20 20 20 20 20 20 5A 65 72 6F A0 20 20 41 20    y      Zero.  A 
00A3F0:  3E 20 6E 20 20 20 20 20 20 20 20 20 20 20 20 20    > n             
00A400:  20 20 30 20 20 20 20 20 20 20 20 20 20 30 A0 20      0          0. 
00A410:  20 41 20 3D 20 6E 20 20 20 20 20 20 20 20 20 20     A = n          
00A420:  20 20 20 20 20 30 20 20 20 20 20 20 20 20 20 20         0          
00A430:  31 A0 20 20 41 20 3C 20 6E 20 20 20 20 20 20 20    1.  A < n       
00A440:  20 20 20 20 20 20 20 20 31 20 20 20 20 20 20 20            1       
00A450:  20 20 20 30 A3 20 53 75 6D 6D 61 72 79 20 2D 20       0£ Summary - 
00A460:  63 6F 6D 70 61 72 69 73 6F 6E 73 A0 A0 43 50 20    comparisons..CP 
00A470:  6E 20 20 20 20 20 43 6F 6D 70 61 72 65 73 20 41    n     Compares A
00A480:  20 77 69 74 68 20 6E 20 28 20 30 20 2D 20 32 35     with n ( 0 - 25
00A490:  35 29 A0 A0 43 50 20 72 20 20 20 20 20 43 6F 6D    5)..CP r     Com
00A4A0:  70 61 72 65 73 20 41 20 77 69 74 68 20 3F D4 72    pares A with ?.r
00A4B0:  65 67 69 73 74 65 72 20 72 A0 A0 43 50 20 28 48    egister r..CP (H
00A4C0:  4C 29 20 20 43 6F 6D 70 61 72 65 73 20 41 20 77    L)  Compares A w
00A4D0:  69 74 68 20 6D 65 6D 6F 72 79 20 6C 6F 63 61 74    ith memory locat
00A4E0:  69 6F 6E 20 20 20 20 20 20 20 20 20 20 20 20 20    ion             
00A4F0:  20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                    
00A500:  20 20 20 20 20 20 20 28 48 4C 29 A3 20 20 20 20           (HL)£    
00A510:  20 20 20 20 20 20 45 58 41 4D 50 4C 45 53 20 4F          EXAMPLES O
00A520:  46 20 43 4F 4D 50 41 52 45 A0 A0 20 54 72 79 20    F COMPARE.. Try 
00A530:  20 74 6F 20 20 70 72 65 64 69 63 74 20 20 74 68     to  predict  th
00A540:  65 20 73 74 61 74 65 20 6F 66 20 74 68 65 20 5A    e state of the Z
00A550:  65 72 6F 61 6E 64 20 43 61 72 72 79 20 20 66 6C    eroand Carry  fl
00A560:  61 67 73 20 62 65 66 6F 72 65 20 20 70 65 72 66    ags before  perf
00A570:  6F 72 6D 69 6E 67 20 20 74 68 65 63 6F 6D 70 61    orming  thecompa
00A580:  72 69 73 6F 6E 2E 20 20 49 6E 20 74 68 65 20 6E    rison.  In the n
00A590:  65 78 74 20 6C 65 73 73 6F 6E 73 20 77 65 20 77    ext lessons we w
00A5A0:  69 6C 6C 62 65 20 20 75 73 69 6E 67 20 20 74 57    illbe  using  tW
00A5B0:  35 68 65 73 65 20 20 66 6C 61 67 73 20 20 65 78    5hese  flags  ex
00A5C0:  74 65 6E 73 69 76 65 6C 79 2C 20 74 6F 70 72 6F    tensively, topro
00A5D0:  64 75 63 65 20 6D 6F 72 65 20 69 6E 74 65 72 65    duce more intere
00A5E0:  73 74 69 6E 67 20 65 78 61 6D 70 6C 65 73 2E A3    sting examples.£
00A5F0:  20 4C 44 20 41 2C 35 A0 20 20 43 50 20 34 A0 20     LD A,5.  CP 4. 
00A600:  20 43 50 20 35 A0 20 20 43 50 20 36 A0 20 20 4C     CP 5.  CP 6.  L
00A610:  44 20 42 2C 33 A0 20 20 43 50 20 42 A0 20 20 4C    D B,3.  CP B.  L
00A620:  44 20 48 4C 2C 53 54 4F 52 45 A0 20 20 43 50 20    D HL,STORE.  CP 
00A630:  28 48 4C 29 A0 20 20 44 45 43 20 28 48 4C 29 A0    (HL).  DEC (HL).
00A640:  20 20 43 50 20 28 48 4C 29 A0 20 20 41 44 44 20      CP (HL).  ADD 
00A650:  41 2C 32 33 30 A0 20 20 43 50 20 28 48 4C 29 A0    A,230.  CP (HL).
00A660:  20 20 52 45 54 A0 20 20 A0 20 53 54 4F 52 45 20      RET.  . STORE 
00A670:  44 45 46 42 20 36 A0 20 20 A0 20 00 00 00 00 00    DEFB 6.  . .....
00A680:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A690:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A6A0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A6B0:  00 B9 E1 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A6C0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A6D0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A6E0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A6F0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A700:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A710:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A720:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A730:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A740:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A750:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A760:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A770:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A780:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A790:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A7A0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A7B0:  00 00 00 BE 17 00 00 00 00 00 00 00 00 00 00 00    ................
00A7C0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A7D0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A7E0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A7F0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A800:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A810:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A820:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A830:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A840:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A850:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A860:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A870:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A880:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A890:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A8A0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A8B0:  00 00 00 00 00 BE 17 00 00 00 00 00 00 00 00 00    ................
00A8C0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A8D0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A8E0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A8F0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A900:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A910:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A920:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A930:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A940:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A950:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A960:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A970:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A980:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A990:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A9A0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A9B0:  00 00 00 00 00 00 00 BE 17 00 00 00 00 00 00 00    ................
00A9C0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A9D0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A9E0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00A9F0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00AA00:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00AA10:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00AA20:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00AA30:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00AA40:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00AA50:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00AA60:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00AA70:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00AA80:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00AA90:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00AAA0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00AAB0:  00 00 00 00 00 00 00 00 00 BE 17 00 00 00 00 00    ................
00AAC0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00AAD0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00AAE0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00AAF0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00AB00:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00AB10:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00AB20:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00AB30:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00AB40:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00AB50:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00AB60:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00AB70:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00AB80:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00AB90:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00ABA0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00ABB0:  00 00 00 00 00 00 00 00 00 00 00 BE 17 00 00 00    ................
00ABC0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00ABD0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00ABE0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00ABF0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00AC00:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00AC10:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00AC20:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00AC30:  00 00 00 00 00 00 00 00 00 00 00 00 00 18 3C 7E    ..............<~
00AC40:  FF 18 18 18 18 18 18 18 18 FF 7E 3C 18 10 30 70    ..........~<..0p
00AC50:  FF FF 70 30 10 08 0C 0E FF FF 0E 0C 08 00 00 18    ..p0............
00AC60:  3C 7E FF FF 00 00 00 FF FF 7E 3C 18 00 80 E0 F8    <~.......~<.....
00AC70:  FE F8 E0 80 00 02 0E 3E FE 3E 0E 02 00 38 38 92    .......>.>...88.
00AC80:  7C 10 28 28 28 38 38 10 FE 10 28 44 82 38 38 12    |.(((88...(D.88.
00AC90:  7C 90 28 24 22 38 38 90 7C 12 28 48 88 00 3C 18    |.($"88.|.(H..<.
00ACA0:  3C 3C 3C 18 00 3C FF FF 18 0C 18 30 18 18 3C 7E    <<<..<.....0..<~
00ACB0:  18 18 7E 3C 18 00 24 66 FF 66 24 00 00 9E 32 00    ..~<..$f.f$...2.
00ACC0:  C9 C9 C9 C9 C9 C9 C9 C9 C9 C9 C9 C9 C9 C9 C9 C9    ................
00ACD0:  C9 C9 C9 C9 C9 C9 C9 C9 C9 C9 C9 00 FF 00 00 FF    ................
00ACE0:  00 00 00 84 FF FF 00 00 00 3F 88 80 03 00 00 FF    .........?......
00ACF0:  FF 00 00 00 00 00 00 FF FF 00 08 79 C8 FD 00 FF    ...........y....
00AD00:  FF 00 00 FF FF 00 08 79 C8 FD 00 FF FF 00 00 FF    .......y........
00AD10:  FF 00 08 79 C8 FD 00 FF FF 00 00 FF FF 00 00 FF    ...y............
00AD20:  FF 00 00 00 02 79 C8 FD FF 00 00 FF FF 00 00 FF    .....y..........
00AD30:  FF 00 00 FF FF 00 04 79 C8 FD 00 FF FF 00 00 FF    .......y........
00AD40:  FF 00 00 FF DF 00 00 00 08 79 C8 FD FF 00 00 FF    .........y......
00AD50:  FF 00 00 FF FF 00 00 FF FF 00 10 79 C8 FD 00 FF    ...........y....
00AD60:  FF 00 00 30 00 76 65 20 22 54 45 58 54 30 22 2C    ...0.ve "TEXT0",
00AD70:  42 2C 26 35 38 30 30 2C 26 35 35 30 30 00 30 00    B,&5800,&5500.0.
00AD80:  54 45 52 22 00 61 00 64 00 30 30 31 00 00 37 39    TER".a.d.001..79
00AD90:  2C 26 65 64 2C 26 37 38 2C 26 63 62 2C 26 34 37    ,&ed,&78,&cb,&47
00ADA0:  00 26 31 62 2C 26 37 61 2C 26 42 33 20 00 66 2C    .&1b,&7a,&B3 .f,
00ADB0:  26 30 00 FF FF 00 00 FF FF 00 00 FF FF 00 00 8B    &0..............
00ADC0:  51 FF FF FF FF                                     Q....
RESULT OF SEARCH :
PRO=55   CHEA=0   COD=5   MUSI=0   COP=11   GRA=19   WRIT=6   198=0   199=1   STARTER=0   KBI=0   CAAV=0   L.TOURNIER=0  
 9WUX(X(X,X9XXDXKXXXXcXsXzXXXXXXXXZaacd+eghjkmop$rtwxiyz(S£dkGM1             IND
EX REGISTERS We now introduce two new register.s, theindex registers  IX and  IY
.   These tworegisters  are  identical in  every way.What  applies  to  one  app
lies  to  theother. They  can  take  the place  of  the  HLregister  in  most  i
nstructions.  It issimpler  to  list the  instructions thatcan be performed by t
he HL register  butnot index registers-ADC  HL,dd   SBC HL,dd  and EX DE,HL aret
he only exceptions. They cannot be exchanged for HL if thatregister  pair is  on
ly  implied  in theinstruction, i.e. RRD.£ The   great   advantage  of  kthe  in
dexregisters   however   is  that  indirectaddressing  is  not   simply  (HL)   
but(IX+d).    The   indirect   address   iscalculated as the  sum  of the  conte
ntsof the  IX/IY register and the offset  dspecified   in  the  instruction. It 
is easiEer to use the index registersto  interrogate  tables than  using  HL.The
 offset  can define the column in thetable  and  IX/IY  register point to thebeg
inning  of  the  line.  A  subroutinecould  manipulate  the  data  within thelin
e,  using  a  constant IX/IY pointer.Subsequent lines can then be manipulatedsim
ply  by using the same subroutine andchanging the  IX/IY register to point toa d
ifferent line.£ The  only instruction  for  which  (HL)cannot  be  substituted  
by  (IX+d)   or(IY+d) is JP (HL).  JP (IF(X) and  JP (IY)are available however. 
The  summary   lists   all instructionsavailable  using  the  IX register. Thisl
ist   can   be  repeated  for  the   IYregister.£ Summary - index registersLD r,
(IX+d)   LD IX,nn     LD SP,IXLD (IX+d),r   LD IX,(nn)LD (IX+d),n   LD (nn),IX  
 EX (SP),IXADD A,(IX+d)  INC (IX+d)   AND (IX+d)ADC A,(IX+d)  DEC (IX+d)   OR (I
X+d)SUB (IX+d)                 XOR (IX+d)SBC A,(IX+d)  CP (IX+d)ADD IX,dd     IN
C IX       DEC IXSLA (IX+d)    SRA (IX+d)   SRL (IX+d)RLC N(IX+d)    RL (IX+d)  
  RRC (IX+d)RR  (IX+d)SET N (IX+d)  RES N,(IX+d) BIT N,(IX+d)JP (IX)With an iden
tical set for IY£     EXAMPLE OF USE OF INDEX REGISTER The example  uses  the IX
 register as apointer to a table of two  byte numbers.Each number is to be divid
ed by 2.£ LD B,6  LD IX,ITEM1 LOOP  SRL (IX+1)  RR (IX+0)  INC IX  INC IX  DJNZ 
LOOP  RET   ITEM1 DEFW 560  DEFW 16  DEFW 9634  DEFW 187  DEFW 884  DEFW 5937   
   THE ALTERNATIVE SET OF REGISTERS The   Z80   has   within  the  chip  analter
native set of the primary registersAF, BC, DE  and HL.  These  are normallydesig
nated as  AF',  BC',  DE' and  HL'.Although  no operations can be performedon th
ese registers,  they can be used asa fast method of storage. There   are   on-ly
   two   instructionsinvolving the alternative registers. EX AF,AF'  exchanges t
he contents of AF            and AF' EXX        exchanges BC,DE and HL, with    
        BC', DE' and HL' resp.£    EXAMPLE USING THE ALTERNATIVE SET The  exampl
e loads all registers,  thenswops  them  with  the alternative  set.Having re-lo
aded the registers a furtherswop returns the original numbers.£ LD A,30  LD BC,1
024  LD DE,8000  LD HL,64000  EXX  EX AF,AF'  LD A,60  LD BC,1280  LD DE,200  LD
 HL,32100 LOOP  EXX  EX AF,AF'  DJNZ LOOP  RET           INPUT AND OUTPUT INSTRU
CTIONS So far we have  manipulated data withinthe processor and its associated m
emory. If a  memory location is used  directlyby  a  external  device,  the  dev
ice istermed  memory a,ddress mapped.  The  Z80also supports  256  output and 25
6 inputports, or   8  bit information  sources,external to memory. We  can  inpu
t  data  directly into theaccumulator with IN A,(n) where n is thenumber  of  th
e input port between 0 and255.   Similarly we can output data fromthe Accumulato
r  to  port  n  using  theinstruction   OUT (n),A.  No  flags  areaffected by th
ese instructions£ We can also  input  data to any  8  bitregister  using  the  B
 and C registers.The instruction  IN r,(C), transmitsp thecontents  of  the B re
gister to the portwhose  number  is in the C register. Theport  may   or  may  n
ot  act  upon thisinformation.  The returned data from theport is  loaded into r
egister r.£ IN r, (C)  affect the  Zero,  Sign, andParity flags.  The Eeinstruct
ion IN F, (C)is the only instruction that  deals withthe Flag register separatel
y.  Only  theflags are affected by  this  instructionand  no  data  is  transfer
red  into theprocessor. OUT (C), r is a  similar instruction toIN r,(C),  but   
the   .contents  of  theregister r is loaded into port (C). The AMSTRAD  CPC 464
  uses the IN r,(C)and OUT (C),r forms of I/O instructions,because  of  the  con
figuration  of  theinterfaces  I/O instructions of the formIN A,(n) or  OUT (n),
A cannot be used.£ Su!ammary - simple input/outputIN A,(n)    where n is the num
ber of the                      input port (0-255)IN r,(C)IN F,(n)OUT (n),AOUT (
C),r£  EXAMPLES OF INPUT/OUTPUT INSTRUCTIONS On the AMSTRAD all useful I/O addre
ssesare    allocated    to   drive   variousperipheral devices, such as the Para
llelInput/Output    chip   ( PIO )  or   CRTController  chip  etc.  The  driving
  ofthese chips is outside the scope of thisTUTOR.   Since erroneous output to t
hesedevices can result in system crash, thisSIMULATOR   cannot  safely support m
ean-ingful I/O  instructions.   If the pupilwishes  to  proceed   further  in   
thisdirection, it is recommended to read theCPC464  FIRMWARE   Manual  published
  byAMSOFT.£           BLOCK INSTRUCTIONS There are four groQups of  four types 
ofinstructions  that perform operations onblocks    of    memory.    Since   the
seinstructions have similarities, they areintroduced together. All block instruc
tions use  register(s)as a pointer(s)  to  scan though a blockof memory andW ano
ther as a counter. All  block  instructions  have  similarmnemonics.    I   indi
cates   that   thepointer(s)  are  Incremented,   D   thatthe  pointer(s) are  D
ecremented, and  Rthat  the instruction is to be  repeateduntil the counter is z
ero.£ The %total list is Transfers LD .....LDI,LDIR,LDD,LDDR Compare   CP .....C
PI,CPIR,CPD,CPDR Input     IN .....INI,INIR,IND,INDR Output    OUT/OT..OUTI,OTDR
,OUTD,OTDR The  U  in OUT is dropped  to keep  themnemonic to a maximum of 4 let
ters.£      BLOCK  TRANSFER INSTRUCTIONS Block  transfer  instructions  transfer
the  contents  of  an area  of memory toanother area. Two pointers are used. The
HL register holds the source address andthe DE register the destination address.
The size of the block to be  traoinsferredis held in the BC register.£ LDI  tran
sfers (HL) to (DE), incrementsboth  pointers,  and  decrements BC.  IfBC0 the P/
V flag is 0  (i.e. equivalentto parity being odd ). If  BC  does  notequal 0 the
 P/V flag is 1 (parity even).LDI therefore performs only  one step ofthe transfe
r   of  the  block,  allowingintermediate  operations to be performedbefore the 
instruction is repeated. LDIR  is similar to  LDI,  transferringdata from (HL) t
o (DE) and  incrementingthe pointers,   but   this   instructiobnautomatically  
 repeats   the  operationuntil  BC0   and  the  whole  block  istransferred.£ LD
D  is similar to  LDI except that thepointers are Decremented. Thus HL and DEsta
rt  at  the  top  of  the  respectiveblocks of memory. LDDR  Repeats  LDD untDil
 BC0 as in theLDIR instruction. Both  pairs  of instructions  (LDIR andLDDR)  ar
e  required. Take the example of an LDIR instructionwith the registers initially
 set to-HL  1000  DE  1500  and  BC  1000.The   instruction  should  transfer  t
hecontents of the  block of  memory  1000-2000   to  memory  locations  1500-250
0.Unfortunately  the first step  transfersthe  contents  of  1000 to 1500.  By t
hetime it is the turn of location  1500 tobe transferred    it  has  already  be
enoverwritten in th3e first step.£ Taking the initial conditions -HL 1999   DE  
2499 and  BC  1000  andusing  the  LDDR  instruction,  the sameblock will  be  t
ransferred  to the samememory locations without this problem. In  general,  if t
he two blocks overlapuse the  instruction  that  ensures  theinitial  figure in 
the  HL register lieswithin the  block to which data is to betransferred.£ Summa
ry - block transferLDI     pointer incrementedLDIR    pointer incremented and re
peated        until number found or BC0LDD     pointer decrementedLDDR    pointe
r decremented and repeated        until number found or BC0£       EXAMPLE OF BL
OCK TRANSFER The example uses the  LDIR  instructionto  transfer  the  program  
 down  to  amemory area. The power of these insVutructions is wellillustrated by
 the simple operation. These instructions can  be used also tofill  a  block  of
  memory with a singlenumber.£ LD HL,F00H  LD DE,ST1  LD BC,BH  LDIR  RET ST1   
DEFB 0  DEFB 0  DEFB 0  DEFB 0  DEFB 0  DEFB 0  DEFB 0  DEFB 0  DEFB 0  DEFB 0  
DEFB 0               BLOCK SEARCH As you may now be able to infer, the CPgroup  
Compares  the content  of  memorylocations in a  block of  memory  with apredete
rmined   number.   HL  holds  thepointer and  the  BC register the lengthof  the
   block  to  be  searched.   TheAccumulator  holds the number for  whichthe  in
struction  will  search.  If  thenumber  is  found  then the Zero flag isset.  A
s  before  the P/V flag indicateswhether BC0. The  block instructions stopv, not
  withthe pointer(s) pointing at the addressesjust operated on,  but to those ab
out tobe processed. Hence if equality is foundthey  point to the  next address a
nd notthe  memory  location  in  which  it wasfound.£ Summary - block searchCPI 
    pointer incrementedCPIR    pointer incremented and repeated        until num
ber found or BC0CPD     pointer decrementedCPDR    pointer decremented and repea
ted        until number found or BC0£       EXAMPLE OF BLOCK SEARCH In this exam
ple the  program itself  issearched through until the number C9H isfound (C9H co
rresponds to RET)£ LD A,C9H START LD BC,100  LD HL,START  CPIR  DEC HL  LD A,FFH
  CPIR  DEC HL  LD A,(HL)  RET    DEFB 6H  DEFB 0H  DEFB FFH  DEFB 88H       BLO
CK INPUT/OUTPUT,g INSTRUCTIONS The  IN   group  of  block instructionsinput data
 from the input port specifiedby the  contents of the C  register intoa  block  
of   memory  starting  at  theaddress  held  in  the  HL register, thelength  of
  which  is in the B register.All forms of IN apply- i.e.  INI incrementing     
   INIR incrementing and repeating       IND  decrementing       INDR decrementi
ng and repeating£ The  OUT   group is identical to the INgroup, but data from me
mory is output toport   (C)  in  sequence   from   memorybeginning at location (
HL) The  B register is used as a counter asthe IN group. OUTI     incrementing O
TIR     incrementing and repeating OUTD     decrementing OTDR     decrementing a
nd repeating The  Zero  flag indicates  B0 in thesecases Since  the  AMSTRAD  us
es the data sentout from the  B register as Port addressin  I/O  instructions, i
t cannot supportthese block I/O instructions.£     PROCESSOR CONTROL INSTRUCTION
S This  group  of  instructions, togetherwith the interru2pt instructions, contr
olthe action of the processor. NOP   or   No  OPeration   causes   theprocessor 
 to  do  nothing for one step.Since its code is  0 ,  a cleared memoryarea will 
be sequenced  through until  anon-zero instruction is found. HALT   st8ops   the
   sequencing  of theprocessor until an interrupt is received( see next lesson )
. After the interrupthas  been  dealt  with,  the instructionafter the  HALT  is
  performed. Thus theprogram   can   be   synchronised   withoperations outside 
the processor.£ As   well   as   the   standard    CALLinstructions  incorporati
ng  the addressto which  the processor  is to jump, theZ80   has  instructions  
in  which   theaddress  of  the  CALL  is  implied. Theinstructions   RST n ( wh
ere n00H, 08H,10H, 18H6, 20H, 28H, 30H, 38H ) calls theroutine at 00n H  directl
y. i.e. RST 28His  equivalent to CALL 0028H Their  prime  use  on  some  systems
 isto  allow  external  hardware  to  forcethe  single  byte  instructions into 
theprocessor,  thus  making  it  think  itsnext   instruction   is  an  RST n.  
 Ittherefore forms a method of interruptingthe  processor.   ( see  the  lesson 
 oninterrupts).£ All but one RST call are  specified  onthe AMSTRAD ( the CPC464
 FIRMWARE manualdefines  them  all  in  detail ).   Mostaffect  the  system  con
figuration  etc.i.e. RST 00H  is equivalent to NEW, thatclears  out   all  the  
memory  and  re-establishes  the  system.   Needless  tosay  the simulator does 
not perform  RSTinstructions. There  are only  two  more registers Pinthe Z80 to
 discuss, the  I or  Interruptregister (see next lesson), and the R orRefresh re
gister.£ The  Refresh  register is used  by someforms  of  Random  Access  Memor
y  whichrequire  continuous  writing to maintainits  information.   The  R  regi
ster  isincremented automatically every time theprocessor   fetches   each   par
t  of aninstruction  from  memory. This providesthe programmer  with  a  registe
r  whosecontents may be  considered  random  forsome applications. The  R  and  
I  registers can be loadedfrom  the  Accumulator. The instructionsinvolved are s
imply  LD A,R   LD R,A  LD A,I and LD I,A.£Summary - processor control instructi
onsNOP HALTRST n  where n 00H, 08H, 10H, 18H, 20H,                28H, 30H, or 3
8H.LD A,RLD R,ALD A,I7LD I,A£   EXAMPLE OF USE OF REFRESH REGISTER Most of the i
nstruction in this and thelast  lesson  involve  steps that changethe environmen
t in which the   processoroperates.  It is  therefore difficult tosimulate these
 instructions.  Little canbe learnt from  single stepping  throughan  example.  
However changing interruptetc. ( see next lesson )  on  a PersonalComputer is  a
dvanced  programming.  Trygaining   experience   on  machine  codeprogramming  b
efore  venturing into thisfield. The  example  shows  the  use  of   theRefresh 
 register  as a source of randomnumbers.£ NOP LOOP  LD A,R  JR LOOP             
                            INTERRUPTS An  interrupt  originates from  outsideth
e processor,  requesting  it  to breakoff its cu9rrent  sequence of  operationsa
nd deal with some other function. Interrupts  fall into  two types,  Non-Maskabl
e Interrupts (NMI)  and  MaskableInterrupts (MI).  Maskable interrupt canbe  ign
ored  by  the  software, but NMIscannot. One Non-Maskable Interrupt is available
on  the   Z80   chip.    The   interruptautomatically performs an RST or CALL to
address  0066H  on  completion  of   thecurrent  instructions.  The  routine  at
0066H is performed. The instruction RETNor RETurn from   Non-maskable  interrupt
returns  control back to the interruptedroutine at its next instruction .£The pr
ogrammer can arrange that maskableinterrupts  (MI) are ignored. Within theZ80  t
here  is  a  flag,  the  interruptenable  flag,   that  can  be  set   andcleare
d.   Depending  upon  the state ofthis  flag   MIs  will  be  accepted  orignore
d. The  two  instructions  that manipulatethis flag are EI   Enable Interrupts. 
 After one more      single  byte  instruction, further      interrupts are acce
pted. DI   Disable Intevrrupts immediately. Entry   into   a   maskable   interr
uptautomatically disables interrupt.£Three   types,  or  modes,  of  maskableint
errupts are available. MODE 0 is set by the instruction  IM 0.This   mode   is  
 the   one   describedpreviously,  where the RST n instructionis forced onto the
 data highway to  foolthe  processor   into   performing   therestart. MODE 1 is
 the  one  used by the AMSTRADsystem ROM. It is set by the instructionIM 1.  Thi
s mode is similar in operationto  the  Non MaskablMe  Interrupt  exceptthat  pro
cessor is  restarted  at  0038Hinstead of 0066H as in the NMI.£ MODE 2  is  the 
 most   flexible,   theaddress to which the processor is forcedis the indirect a
ddress held in a memorylocation.   The address  of this  memorylocation  is comp
uted from  the  contentof the  I register,  which  provides thehigh  byte and  t
he  interrupting devicewhich  provides  the  low   byte.  Sincethe  interrupt  r
outine   is   addressedindirectly  the  interrupts  are  termedvectored interrup
ts. An  interrupt  can  occur at any  time.It   follows   therefore  that   if  
theinterrupted  program is to be  continued( i.e. be re-entered ),  the contents
 ofany register that the  interrupt routineuses  must  be stored or pushed onto 
thestack, and rel,oaded or POPped  from  thestack before returning£ To  ensure  
that   no  other  interruptoccurs during this period and  thereforecorrupts  the
  register  contents beforethey   are  safe,  the  interrupts   arediabled durin
g these operations.£ We  must   refturn  from  an   interruptroutine  with   the
  instruction    RETI( RETurn from Interrupt ) and not RET. Hence interrupt rout
ine take the form-(1) Enter maskable interrupt, interrupts    are disabled at th
is time.(2) PUSH or EXchange required register)ed(3) Enables interrupt if requir
ed.(4) Do interrupt routine.(5) Disable interrupt if required.(6) POP or EXchang
e registers.(7) Enables interrupts(8) Return from interrupt (RETI).£ This   comp
letes  a  study  of  all theinstructions available on the !Z80 chip. You  should
  now  be  able to use otherassemblers  to  write your own programs.You  will  f
ind  that  most  are  not souser friendly,  and  that  you  will notbe  able  to
  one  step  easily  throughinstructions.   Don't  despair.  You canalways  retu
rn to this Tutor to simulateyour problem. Since the  AMSTRAD CPC 464 processor i
ssurrounded  with interface chips  AMSOFTrecommend  the  machine  code programme
rto  address  these  devices  through thesoftware  resident  within the ROMs. Th
eAMSTRAD JCPC464 FIRMWARE MANUAL publishedby AMSOFT defines in detail not only t
hevarious CALLs  available  but  the totalsystem structure.£   GOOD  LUCK  and H
APPY  PROGRAMMING£             INTRODUCTION The  final  set  of  lessons introdu
cesmore speciablised registers and instruct-ions,  and  looks at the way the Z80
 cantalk with the outside world. The last lessons deal with instructionsthat   a
llow   the   outside  world   tointerrupt the processor.£            LESSONS  26
 - 35 26.  The index registbwers             Ex - use of index registers 27.  Th
e alternative set of registers             Ex - using alternative set 28.  Input
/Output instructions             Ex - I/O instructions 29.  Block instructions -
 introduction 30.  Block tranfer instructions             Ex - block transfer 31
.  Block search instructions             Ex - block search 32.  Block I/O instru
ctions 33.  Processor control instructions             Ex - control instructions
 34.  Interrupts 35.  Finale      Load earlier lessons for revision£A  veryimpor
tant point. The largest positive number we can holdin  a   single   register,  u
sing   thisnotation is  01111111   or  127  and thelargest  negative   number  1
0000000  or-128.£ The  Z80  has two instructions that maybe used for these opera
tions CPL   complements    or   inverts   the       contents of the Accumulator.
 NEG   negates,  or makes  negative, the       contents  of  the  Accumulator by
       complementing and adding 1 in one       operation. A Sign flag FR(S) is p
rovided on the Z80.It duplicates  the sign ( bit 7 ) of theanswer after any arit
hmetic operation onthe Accumulator.  The  sign  flag is "0"for  a  positive  res
ult  and  "1" for anegative result.£ When performing  arithmetic  operationswhic
h  we  wish  to interpret within therange  -128 to +127, the Carry  flag  nolong
er  signals  an out of range result.However another flag, the overflow (P/V)flag
  does.  It  is  a  "1" whenever theanswer is outside the range -128 to +127and 
 "0"  within   the   range.   It  iseffectively  a  carry  into  bit 7 whichwoul
d make the sign bit incorrect.£ There  is  no  reason for sticking to 8bits  usi
ng this method.  So long as thenumber of  bits is  sufficient  and  themost  sig
nificant  bit  is  taken as thesign  bit  any size positive or negativenumber ca
n be represented. Performing a similar calculation to theabove  we can  show tha
t a register paircan  represent  a  number  in the  range+32767 to -32768. The  
Sign and  overflow  flags are alsooperative after  AvDC and SBC instructionon th
e HL register. It reflects the 15thbit (or bit 7 of H register) .£ It is importa
nt  to  remember  that theZero,  Carry,  Sign, and  overflow flagsare always ope
rative  after  an   8  bitarithmetic  instruction   or  a  16  bitaddition   inv
olving   the  Carry.  Yourinterpretation of the  result determinesin   which   f
lag(s)   you   should   beinterested in.£    EXAMPLES OF +VE AND -VE NOTATION Al
though  these  examples  appear to beall positive, they can be viewed equallyas 
 nee%gative  where appropriate and  theSign   and   overflow   flags   observedo
perating. Remember  a   number   above   128   isnegative. Since all the negativ
e numbersin the examples are small,  they  can beseen quickly and simply be conv
erted  bysubtractinSg the number from 256. i.e.  -2  is equivalent to 254 etc.£ 
LD A,254  NEG  NEG  ADD A,2  INC A  LD HL,2  LD DE,FFFEH  ADD HL,DE  CPL  LD HL,
STORE  LD (HL),7FH  INC (HL)  RET   STORE BIN 0   88($"88(H0$ff$/ yyyyyyy3ve "TE
XT3",B,&5800,&5500TER"ad00179,&ed,&78,&cb,&47&1b,&7a,&B3 f,&0M W UX.X/X3X7XDXQXX
eXoXvXXXXXXXXXXXXtXwNavbWcehk&loo ptsv1wzwzjM(z £         REGISTERS and MEMORY R
egisters E are  like  pigeon  holes  inwhich  numbers  can be stored.  A singler
egister can store  any  number  between0 and  255.  The  Z80  has   many   suchr
egisters.  Initially  we shall consideronly the more  general ones  designatedA,
B,C,D,E,H and L.  The A  register ( orAccumulator )  is  the  most  important,si
nce  more  instructions  involve  thisregister than any other. The step by step 
instructions making upa program are stored in memory, a seriesof   similar    re
gisters    or   memorylocations  external  to  the  Z80  chip.65536 memory locat
ions can be  accessed.They  are  designated  by  their  numberbetween 0 and 6553
5.  It  takes  the Z80longer  to  access  memory  than its owninternal registers
.£       SIMPLE LOAD INSTRUCTIONS Perhaps  a  better ' description of loadthan t
he conventional one is copy, sincea load  instruction  copies  the  numberheld i
n a register  or  memory  locationinto   another    register   or   memorylocati
on.   As   with  all  copying  theoriginal remains unchanged. The   Kload  instr
uction   is   normallyabbreviated to LD.  The simplest form ofload  copies data 
from  one  register toanother, i.e. LD A,B  . In  these  abbreviationed  instruc
tions( mnemonics ), it is conventional to putthe register affected first, follow
ed bythe register from which  the informationis  copied.   Hence  LD A,B  copies
  thecontents of B into A or Accumulator.£ We  can  also load any of the registe
rswith  a  number,  n, between  0  and 255directly ,   with    instructions   li
keLD C,123. We  shaRll  discuss later  fromwhere  the number  is copied. Suffice
 tosay at this  stage,   that  instructionsare stored as  numbers.  i.e.  LD A,B
 isstored as  78.  Some  instructions  likeLD A,B are stored as one number,  oth
erstake up to four. The two types  of instructions discussed( LD r,r' and  LD r,
n )  can involve anyof the  registers considered.  Only  theA  register   can  b
e  loaded  with  thecontents  of  a  memory  location.   Theinstructions of the 
form LD A,(nn) loadsor  copies  the   contents   of   memorylocation nn  ( a  nu
mber  between  0 and65535 ) into the A register.£ We can also load a memory loca
tion withthe  contents  of  the  Accumulator withLD (nn),A   where  nn  is  the 
number oraddress of the memory location. All  other single  regis ters  cannot b
eloaded  directly from a memory location.Two   instructions   involving   the   
Aregister are required.£   Summary - Loading single registersLD r,r'    where r 
and r' are any of the           following A,B,C,D,E,H and L.LD r,n     where n i
s a number 0 - 255LD A,(nn)  where nn is a number   0 to           65535LD (nn),
A£            REGISTER PAIRS The fact that  a  single  register  canonly hold  n
umbers  up  to 255  and  thetotal memory  available  is up to 65535,is a limitat
ion.  For0x  this reason thereare a  whole  set of instructions on theZ80  that 
deal with  registers in pairs.The pairs are  BC,  DE, and  HL registerpairs. The
 two registers hold  different partsof a number. Consider the decimal number27. 
We  can think of this as  X having twoparts the high part ( or byte) is the 2sin
ce it represents  2*10 , the low part( or  byte )  is  the 7,   since it onlyrep
lesents  7*1 .  The  total  number is2*10 + 7*1  27.  Each digit can only be0 - 
9  i.e. 10  different numbers.£ A  single register can hold  0-255, 256different
   numbers.   If  we   put  tworegisters side by side, i.e.  HL , the Hregister 
holding the High byte and the Lholding the  Low  byte, then we can holdin the re
gister pair  H*256 + L*1 in thesame way as 27  2*10 + 7*O1. The maximumthat can 
 be  held  in a  register  pairis  therefore   255 * 256 + 255  65535.By convent
ion  the  high  byte is storedin  the  first  register in the registerpair name.
 We  can  load any of the register pairswith a number between 0 - 65535 directly
using instructions like LD HL,nn. Just as we can combine two registers tohold nu
mbers up to 65535, we can combineadjacent     memory     locations.    Byconvent
ion the  Low  byte is held in thelocation with the Lower address.£ We  can  ther
efore load a register pairwith  the  contents of a  pair of memorylocations,   w
ith   instructions    likeLD DE,(nn) .    This   instruction    isequivalent to 
the non-valid instructionsLD E,(nn) and  LD D,(nn+1). Similarly,  we can load th
e contents ofa reg$ister pair into  a pair  of  memorylocations,  i.e.   LD (nn)
,BC  which  isequivalent   to   the    two   non-validinstructions LD (nn),C and
  LD (nn+1),B. There   are  no  instructions  to  loadregister  pairs  with  the
  contents  ofanother register pairk.  Two instructionsthe form  LD r,r'  are  u
sually  used toperform such an operation. There  is  one  instruction  similar t
othis type  EX DE,HL.  It  EXchanges thecontents of the  DE  register  pair with
the contents of the HL register pair.£  Summary - loading register pairsLD dd,nn
   where dd is any register pair           BC, DE, and HL.            nn  is a n
umber 0 - 65535LD dd,(nn)LD (nn),ddEX DE,HL    exchanges register contents£     
    INDIRECT ADDRESSING Up   to  now    we   have   onFly   usedinstructions in 
which  memory  locationshave  been  specified  directly  in  theinstruction. Ano
ther  useful  method  ofspecifying a memory location is to use anumber held in a
 register  pair,   knownas indirect addressing.  The instructionLD B,(HJL) for e
xample  allows us to loador copy to the  B  register the contentsof the memory l
ocation whose  address isin the HL register pair. All  single  registers  can  b
e  loadedusing the HL register pair as a pointer. Similarly ,  memory  locations
  canE  beloaded   indirectly  from   any   singleregister using the contents  o
f  the  HLregister pair as address i.e. LD (HL),C.£ Use of  the  BC  and  DE  re
gisters forindirect addressing is limited to the  Aregister. i.e. LD (DE),A LD A
,(BC) etc.£   Summaryb -  indirect addressingLD r,(HL) where r is any single reg
ister          A,B,C,D,E,H, or L.LD (HL),rLD A,(BC)LD A,(DE)LD (BC),ALD (DE),A£ 
     ADDITIONS AND THE CARRY FLAG Both single  register and register pairadditio
n are possible on the Z80. All   single   register  additions  areperformed with
 the Accumulator. A number( i.e.  ADD A,6 ),  the  contents  of  aregister (i.e.
 ADD A,B), or the contentsof  an   indirectly   addressed   memorylocation  usin
g  the  HL  register  pair(i.e. ADD A,(HL) ) can be added  to  theAccumulator. T
he result  is  held in theAccumulator.  The source of the additionis unaffected.
 Register  pair addition is performed inconjunction  with  the HL register pair,
and  can  only  involve  BC or DE ( i.e.ADD HL,BC  or  ADD HL,DE ).   Again  the
the  result is held in  the  HL registerpair,  and  the other  register  pair is
unaffected.£ Single  and  double  register additionswill  obviously  only  give 
 the correctresult  if  the  answer is less than themaximum number the rWegister
(s) can hold.If it is greater than this  a  carry  isgenerated.  The processor  
 holds   thissingle  bit  of  information or flag, sothat  action   can  be  tak
en  over  theoccurrence of the carry.   If there  hasbeen  a  carry  on  the  la
st arithmeticoperation the carry is said to be set toa  "1" .  If not set  it is
 said to be a"0". A second form of addition is  availableon  the  Z80 ,   for   
both  single  andmultiple registers,  known  as  add withcarry  abbreviated  to 
 ADC.   They aresimila r to ADD  except that if the Carryflag  is  set  before  
the  addition theresult is  incremented   by   one.   Allpreviously mentioned   
ADD  instructionscan be performed as ADC.£ ADC instructions can be strung togeth
erto perform  the  addition of two numbersof any  length,  as  the  examples  wi
llshow.£   Summary -  additionADD A,n    where n is a number 0 - 255ADD A,r    w
here  r  is  any   single           registerADD A,(HL)ADD HL,BCADD HL,DEADC A,nA
DC A,rADC A,(HL)ADC HL,BCADC HL,DE£    SUBTRACTION AND THE CARRY FLAG Single reg
ister subtraction takes placewith the Accumulator.  All  the forms ofADD  can  b
e   used  in   subtract.  Theabbreviation  or  mnemonic SUB is alwayswritten wit
hout the A, which is implied.Hence the instructionas are SUB n, SUB r,and SUB (H
L).   Again the result is heldin the Accumulator.   The  carry flag isset to a "
1"  if the  result is  outsidethe range  0 - 255.There  are   no  double   regis
ter   SUBinstructions.All  configurations of  ADC instructionscan be used  with 
SBC or  SuBtract  withCarry  instructions.  The operation   issimilar to SUB,  e
xcept that the  resultis decremented  by one if the carry flagis set.£ Like  ADC
 instructions SBC instructionscan be  strung together to  subtract anylength num
ber. Since  double register  subtraction canonly be performed with carry,  the s
tateof the  carry flag  prior to  SBC HL,BC,and SBC HL,DE is important,  and  sh
ouldbe "0". The carry flag can be set to a "1" withthe instruction  SCF or Set C
arry  Flag.Although   there   are    no    specificinstructions  to clear the ca
rry flag to"0" there is an instruction to invert itCCF or  Compliment Carry Flag
.  We shallsee later that all logic instructions doclear the carry flag.£ SUMMAR
Y - subtract with carrySUBv n     )SUB r     )  SUBtract from A, n, r, orSUB (HL
)  )                  (HL)SBC A,n   )SBC A,r   )  SuBtract from A  with carrySBC
 A,(HL))SBC HL,BC )  SuBtract from HL with carrySBC HL,DE )SCF        Set Carry 
FlagCCF        Compliment Carry Flag£  INCREMENT AND DECREMENT INSTRUCTIONS The 
last arithmetic instructions to  bediscussed can be performed on any singleor do
uble register(s). These are INC andDEC.  INC increments (or  increases) theconte
nts  of  the  register,  or  memorylocation indirectly  addressed by the HLregis
ter pair,  by one.   DEC decrements( or  decreases )  the  contents  of theregis
ter or  memory  location indirectlyaddressed by the  HL register  pair,  by The 
 carry  flag  is  not  affected  byeither of these instructions. These instructi
ons  are  primarily usedwhere   counters   are   required.   Theoperation  on  r
egister  pairs  is  alsouseful  in   sequential  operations   onmemory   locatio
ns  utilising   indirectaddressing.£ Summary - increment and decrementINC rINC (
HL)INC ddDEC rDEC (HL)DEC dd£           THE ZERO FLAG Another  very  useful  fla
g included inall  processors is  the Zero flag.  Thisflag is set to "1"  if the 
result of anysingle register arithmetic operation  iszero. Otherwise it is clear
ed nto "0". It is  only affected by double registerarithmetic   operations   inv
olving  thecarry  flag ,   i.e.  only  affected  byADC HL,dd  or  SBC HL,dd. The
  zero flag, like the carry flag, isunaffected by any LD or EX instructions.£ Su
mmary - zero andE carry flagsinstruction      Carry        Zero                r
    dd      r   dd  LD            .     .      .    .  EX           n/v    .    
 n/v   .  ADD           *     *      *    .  ADC           *     *      *    *  
SUB           *    n/v     *   n/v  SBC           *     *      *    *  INC      
     .     .      *    .  DEC           .     .      *    .r single register   d
d  double register * flag affected      . flag not affected     n/v    instructi
on not valid£            Lesso'ns 1 - 9 1.  Registers and Memory 2.  Simple Load
 Instructions         Ex - simple load instructions 3.  Register Pairs         E
x - register pair loading 4.  Indirect Addressing         Ex - indirect addressi
ng 5.  Addition and the Carry Flag         Ex - single register addition        
 Ex - register pair addition 6.  Subtraction and the Carry Flag         Ex - reg
ister subtraction         Ex - register pair subtraction 7.  Increment and Decre
ment         Ex - inc and dec instructions 8. , Zero Flag         Ex - zero flag
 9.  Compare       Ex - comparison instructions Load further lessons from tape£ 
          INTRODUCTION The  Z80 is  the microprocessor  at theheart of your Amst
rad. This program willteach   you   the   use   of   all £  theinstructions avai
lable  on  the Z80,  ina series of simple  progressive lessons.  After  each   l
esson,   step  by  stepexamples are given.  To further  improveyour understandin
g of the topic, you maythen modify or rewrite the examples, andrun them  pwithou
t  fear of  crashing thesystem. Proceed  through  the menu by  pressingENTER to 
begin the highlighted lesson orexample, and  SPACE to jump to the next.At anytim
e BREAK will return you  to themenu.£    INTRODUCTION TO RUNNING SIMULATOR All  
 examprjles   are   run   using  theSimulator. At this stage the only  areasof t
he simulator screen to consider  arethe Source  Code ( the third column thathold
s the instructions ) and the area atthe bottom of the screen, which displaysthe 
contents  of  the  regisv%ters.  Otherareas  will  be  described  as  they arere
quired. The assembler, that converts  instruct-ions  into   machine  code, will 
 acceptLabels. Instead  of  putting  an addressinto the program, we can give it 
a name.The  assembler  will   then  allocate  amemory  location to it. The name 
must becalled  up  in  the  program  with   itsinitial condition using  the inst
ructionDEFB, DEFine Byte.£ DEFB is an  assembler instruction not aZ80  instructi
on.  The allocated  memoryaddress is given in the first column. The simulator wi
ll display the contentsof this  memory location, in decimal, inthe second column
. Before each instruction is executed theinstruction is described in ENGLISH. Tr
yto work out what  should  happen  beforepressing  any  key   to   perform    th
einstruction.£ You may go  through the example as manytimes as you like, until y
ou  understandit. If you still find  difficulty, pressESC, skip  over the lesson
s and re-ENTERthe lesson  with which  you  are  havingdifficulty. The manual how
ever  gives anoutline of each lesson. When  you  do  understand  the examplesgiv
en  try  modifying  them   using  theeditor.  Then  try  entering   your  ownpro
grams.  All  programs should end withRET ( or return ).   Don't  worry if youfor
get, the simulator will tell you. Remember,  it  is   impossible  for   aprogram
 to destroy your computer. You'llneed a hammer to do that!£ LD A,34  LD B,A  LD 
(3867),A  LD A,(STORE)  LD (3867),A  LD A,B  LD (STORE),A  LD C,B  LD A,(3867)  
LD A,67  LD (3866),A  RET   STORE DEFB 124  DEFB 0            REGISTER PAIR EXAM
PLES The  example illustrates  each  type ofinstruction  that  loads register pa
irs.It also  demonstrates  that a  register/memory  pair  are  still  two indivi
dualregisters or memory locatiV0ons and can betreated as such. Another    assemb
ler    instruction  isintroduced,  the  DEFW  instruction. Theassembler allocate
s  2  memory locationsto the  associated  label.  The   numberafter  the   DEFW 
  sets   the   initialconditions. The address in the first  column is thelow  by
te address.  The  second   columndisplays  the  contents  of  the pair ofmemory 
locations as a single number.£ LD DE,256  LD E,4  LD (STORE),DE  LD (LOW),DE  LD
 A,2  LD (HIGH),A  LD HL,(LOW)  EX DE,HL  LD D,0  RWET   STORE DEFW 32000 LOW   
DEFB 0 HIGH  DEFB 0          EXAMPLES OF INDIRECT ADDRESSING  These  examples  i
llustrate   indirectaddressing.   At   this   stage  it   isimpossible to  demon
strate  its  useful-ness.  It is employed extensive in laterexamples£ LD HL,LOW 
 LD C,(HL)  LD HL,HIGH  LD B,(HL)  LD A,(BC)  LD DE,3860  LD (DE),A  LD (HL),0  
LD BC,3862  LD (BC),A  RET   LOW   DEFB 21 HIGH  DEFB 15  DEFB 0      EXAMPLES O
F SINGLE REGISTER ADDITION The  example  adds  together  Wg the  twonumbers  874
0  and  1260   using  singleregister   addition  only.   The  doublelength  numb
ers are held in BC and DE sothat  the  results  can   be   displayedeasily.   Th
is method of addition can beperformed using register pair  addition,as wellD,  t
o add together numbers of anylength. The state  of  the individual flags aredisp
layed to the left of the registers.£ LD DE,8740  LD BC,1260  LD A,E  ADD A,C  LD
 C,A  LD A,D  ADC A,B  LD B,A    LD HL,STORE  LD A,15  ADD A,(HL)  RET   STORE D
EFB 25      EXAMPLE OF REGISTER PAIR ADDITION This  example  effectively multipl
ies anumber  held in the  HL register pair by10  using   addition   to   success
ivelymultiply by 2.£ LD HL,(STORE)  ADD HL,HL  ADD HL,HL  LD DE,(STORE)  ADD HL,
DE h ADD HL,HL  LD (STORE),HL    LD HL,1000  LD A,255  ADD A,1  ADC HL,HL  RET  
 STORE DEFW 6000    EXAMPLE OF SINGLE REGISTER SUBTRACTION This example subtract
s  1260  from 8740using  only single register subtraction.The  two  numbers  are
 held in allocatedmemory locations this time. This  method   of  subtraction  ca
n  beextended   to  any  length   number  andregister pair subtraction.£ LD HL,N
UM1  LD DE,NUM2  LD A,(DE)  SUB (HL)  LD (DE),A  LD E,18  LD L,20  LD A,(DE)  SB
C A,(HL)  LD (DE),A  RET   NUM2  DEFW 8740 NUM1  DEFW 1260      EXAMPLE USING RE
GISTER PAIR SUBTRACTION This example illustrates subtraction ofregister pairs.  
It subtracts  1536 from65536.   At  least 3 bytes of memory arerequired  to  hol
d  the  latter  number,the highest byte  representing 65536. Although  ADC and  
SBC  may require theCarry  flag to  be cleared first, if theprevious calculation
  NEVER results in acarry being  generated, this step may beomitted.  However it
 is often  better tobe safe and include it,  than  look  forthe randomly occurri
ng fault that it cangenerate.£ LD HL,(NUM1L)  LD DE,(NUM2L)  SBC HL,DE  LD (ANSL
),HL  LD HL,(NUM1H)  LD DE,0  SBC HL,DE  LD (ANSH),HL  RET   NUM1L DEFW 0 NUM1H 
DEFW 1 *65536 NUM2L DEFW 1536 ANSL  DEFW 0 ANSH  DEFW 0      EXAMPLE OF INCREMEN
T AND DECREMENT At  present  the  programs that can  bewritten are somewhat limi
ted. INC  and  DEC really only become usefulin conjunction with instructions  to
  beintroduced shortly.£ LD C,5  LD HL,STORE  LD (HL),C  INC C  INC HL  LD (HL),
C  DEC C  INC L  LD (HL),C  INC H  RET   STORE DEFB 0  DEFB 0  DEFB 0           
EXAMPLES OF ZERO FLAG While   running  this  example  try  topredict the state o
f the Zero flag afterthe instruction has been performed.£ LD HL,257  DEC L  LD A
,23  SUB 23  LD DE,256  INC A  SBC HL,DE  INC H  SUB 2  SBC HL,DE  LD HL,1  DEC 
HL  RET                      COMPARE  So  far   all  instructions  we   havedisc
ussed  that  affect  the  Carry   orZero fPlags  also  affect  the   registercon
cerned. There are a number  of usefulinstructions that only affect flags. Thecom
pare or  CP  instruction  is  one  ofthese. CP   compares  the  contents  of the
  Aregister with  a number  (CP n), anotherregister  (CP r), or any memory locat
ionindirectly  addressed  through  the   HLregister  pair  ( CP (HL) ). The comp
areinstruction is effectively  SUB  but theresult  does not affect  the contents
 ofthe A register.£ If  n  is  the  number  with which A iscompared, then the fo
llowing results -                     Carry      Zero  A  n               0     
     0  A  n               0          1  A  n               1          0£ Summar
y - comparisonsCP n     Compares A with n ( 0 - 255)CP r     Compares A with reg
ister rCP (HL)  Compares A with memory location                                 
   (HL)£          EXAMPLES OF COMPARE Try  to  predict  the state of the Zeroand
 Carry  flags before  performing  thecomparison.  In the next lessons we willbe 
 using  tW5hese  flags  extensively, toproduce more interesting examples.£ LD A,
5  CP 4  CP 5  CP 6  LD B,3  CP B  LD HL,STORE  CP (HL)  DEC (HL)  CP (HL)  ADD 
A,230  CP (HL)  RET   STORE DEFB 6   0pp088(((88(D88($"88(H0$ff$2yyyyyyy0ve "TEX
T0",B,&5800,&55000TER"ad00179,&ed,&78,&cb,&47&1b,&7a,&B3 f,&0Q
Tous droits réservés. Reproduction sans autorisation interdite. © Kukulcan