home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / MBUG / MBUG085.ARC / MCT10-17 < prev    next >
Text File  |  1979-12-31  |  21KB  |  542 lines

  1. Lesson≤ 1░ - 1╖ 
  2.  
  3. 10«á Conditiona∞ anΣ unconditiona∞áJP≤      E°á- jump≤
  4. 11«á Relativσ jump≤                         E° - relativσ jump≤ ▒
  5.                                             E°á- relativσájump≤ ▓
  6. 12«á Thσ Stacδ                              E° - pushe≤ anΣ pop≤
  7. 13«á Call≤át∩ subroutine≤                   E° - unconditiona∞ call≤ ª ret≤
  8.                                             E° - conditiona∞ call≤
  9. 14«á Binar∙ánotatioε                        E° - binar∙ánotatioε
  10. 15«á Hexadecima∞ notatioεá                  E°á- he°ánotatioε
  11. 16«á Binar∙áCodeΣáDecima∞ánotatioε          E° - BC─ notatioε
  12. 17«á Positivσ anΣ negativσ notatioε         E° - +vσ anΣ -vσ number≤
  13.  
  14.  
  15.                                INTRODUCTIO╬
  16.  
  17. Thσ processor¼á unde≥ thσ programmer'≤ direction¼á ha≤ thσ capacit∙ t∩ makσ ì
  18. decisions«á Iεá thσá followinτ lesson≤ wσ shal∞ discus≤ thesσá instruction≤ ì
  19. tha⌠á makσ ß compute≥ morσ thaε jus⌠ ß calculator«á Wσ  shal∞ theε looδá a⌠ ì
  20. number≤ helΣ iε register≤ iε morσ detail.
  21.  
  22.  
  23. JUMP╙
  24.  
  25. Thσá aspec⌠á oµá ß compute≥ tha⌠ make≤ i⌠ morσ thaεá ßá calculato≥á i≤á it≤ ì
  26. abilit∙á t∩á changσá it≤á sequencσ oµ operation≤ a≤á ßá resul⌠á oµá earlie≥ ì
  27. instructions«á Withiε thσ Z8░ therσ i≤ ß counte≥ calleΣ thσ Prograφ Counte≥ ì
  28. o≥á PC«á Thi≤ counte≥ keep≤ tracδ oµ whicΦ instructioε thσ processo≥ i≤á t∩ ì
  29. perforφá next«á B∙ modifyinτ it≤ contents¼á thσ  processo≥ caε bσ jumpeΣ t∩ ì
  30. an∙á instructioε iε memory«á Thσ simples⌠ jum≡ i≤ J╨ nn¼á wherσ nεá i≤á thσ ì
  31. addres≤á t∩ whicΦ thσ  prograφ i≤ t∩ jump«á Thi≤ i≤ aε unconditiona∞á jump¼ ì
  32. thσá Prograφá Counte≥ alway≤ jumpinτ t∩ thσ addres≤ nn«á Thσ morσá powerfu∞ ì
  33. jum≡á i≤á thσ conditiona∞ jump«á Thσ processo≥ test≤ thσ statσ oµá ßá flag¼ ì
  34. beforσá eithe≥á jumpinτ o≥ continuinτ iε sequence«á Thσá conditiona∞á jump≤ ì
  35. involvinτ thσ carr∙ anΣ zer∩ flag≤ are:-
  36.  
  37.            J╨ NC,nε  jum≡ iµ carr∙ flaτ no⌠ se⌠
  38.            J╨ C,nε   jum≡ iµ carr∙áflaτ set
  39.          á J╨áNZ,nεá jum≡áiµ zer∩ flaτ no⌠ se⌠
  40.            J╨ Z,nε   jum≡áiµázer∩áflaτáse⌠
  41. ì
  42. Indirec⌠á jump≤ arσ als∩ availablσ oε thσ Z8░ usinτ thσ H╠á registe≥á pair« ì
  43. Thσá instructioε J╨ (HL⌐ load≤ thσ prograφ counte≥ witΦ thσ content≤ oµ thσ ì
  44. H╠á register«á Thu≤ thσ addres≤ oµ thσ nex⌠ instructioε t∩ bσ performeΣá i≤ ì
  45. containeΣá withiε thσ H╠ register«á Sincσ thσ content≤ oµ thσá H╠á registe≥ ì
  46. pai≥ caε bσ thσ resul⌠ oµ somσ calculatioε thσ jum≡ caε bσ conditional.
  47.  
  48. Summar∙ - jump≤
  49. J╨ nε
  50. J╨ (HL⌐
  51. J╨ NC,nε  jum≡ oε n∩ carr∙
  52. J╨ C,nε   jum≡ oε carr∙
  53. J╨ NZ,nε  jum≡ oε no⌠ zer∩
  54. J╨ Z,nε   jum≡áoε zero
  55.  
  56. EXAMPLE╙áO╞áJUMP╙
  57.  
  58. AlthougΦá yo⌡ caε ente≥ thσ addres≤ withiε thσ jum≡ iε numbe≥ form¼á iµá i⌠ ì
  59. doe≤á no⌠ equa∞ thσ addres≤ oµ  thσ star⌠ oµ aε instruction¼á thσ assemble≥ ìèwil∞á sto≡á a⌠ thσ JUMP«á Thi≤ i≤ becausσ thσ processo≥ woulΣá perforφá thσ ì
  60. instructioε i⌠ find≤ a⌠ tha⌠ addres≤ anΣ anythinτ coulΣ happeε anΣá usuall∙ ì
  61. does«á T∩á ge⌠ rounΣ thi≤ probleφ  usσ ß label¼á declarinτ i⌠ iε thσá labe∞ ì
  62. columε iε fron⌠ oµ thσ instructioε t∩ whicΦ yo⌡ wisΦ t∩ jump.
  63.  
  64.       L─ HL,STOR┼
  65.       L─ A,│
  66. LOOP▒ L─ (HL),┴
  67.       IN├ ┴
  68.       C╨ ╕
  69.       J╨ NZ,LOOP▒
  70. LOOP▓ DE├ (HL⌐
  71.       J╨ NZ,LOOP▓
  72.       RE╘
  73. STOR┼ DEF┬ ░
  74.  
  75.  
  76. RELATIV┼ JUMP╙
  77.  
  78. Onσ difficult∙ witΦ thσ abovσ type≤ oµ jum≡ i≤ that¼á iµ thσ star⌠á addres≤ ì
  79. oµá thσá prograφá werσá changed¼á al∞á thσá jum≡á addresse≤á woulΣá requirσ ì
  80. modification«á Relativσá jump≤á d∩ no⌠ havσ thi≤ difficulty«á Thσá absolutσ ì
  81. addres≤á i≤ no⌠ storeΣ witΦ thσ instruction«á I⌠ i≤ thσ differencσá betweeε ì
  82. thσá curren⌠á content≤ oµ thσ prograφ counte≥ anΣ thσ addres≤ t∩á whicΦá wσ ì
  83. wisΦá t∩ jum≡ tha⌠ i≤ storeΣ withiε thσ instruction«á  Relativσá jump≤á arσ ì
  84. limiteΣ t∩ jumpinτ backward≤ 12╕ location≤ anΣ forward≤ 12╖ locations«á Thσ ì
  85. mnemoniπá fo≥  relativσ jump≤ i≤ J╥ anΣ caε takσ al∞ thσ form≤ discusseΣ s∩ ì
  86. fa≥ fo≥ JP¼á i.e« JR¼ J╥ NC¼ J╥ C¼ J╥ N┌ anΣ J╥ Z« Therσ  i≤ onσ particula≥ ì
  87. relativσ jum≡ instructioε tha⌠ i≤ particularl∙ useful¼ namel∙ Decremen⌠ anΣ ì
  88. Jum≡ oε Non-Zero¼ o≥ DJNZ« Thσ ┬ registe≥ i≤ decrementeΣ and¼ iµ thσ resul⌠ ì
  89. i≤á no⌠ zero¼á thσ processo≥ perform≤ ß relativσ jum≡ t∩ thσá computeΣá ne≈ ì
  90. address«á Iµá thσá resul⌠ i≤ zer∩ theε thσ nex⌠ instructioε iε sequencσá i≤ ì
  91. taken« DJN┌ allow≤ u≤ t∩ repea⌠ ß serie≤ oµ instruction≤ ß prese⌠ numbe≥ oµ ì
  92. times«á Thσá numbe≥ oµ repeat≤ i≤ equa∞  t∩ thσ content≤ oµ thσ ┬á registe≥ ì
  93. wheε thσ loo≡ i≤ entered¼á s∩ lonτ a≤ thσ ┬ registe≥ doe≤ no⌠ forφ par⌠á oµ ì
  94. thσ serie≤ oµ inst-ructions« N∩ flag≤ arσ affecteΣ b∙ an∙ jum≡ instruction≤ ì
  95. includinτ DJNZ.
  96.  
  97. Summar∙á - relativσájump≤
  98. J╥ σ      wherσ σ i≤ thσ displacemen⌠ in 
  99. J╥ NC,σ   thσárangσ 12╖ t∩ -12╕
  100. J╥ C,σ
  101. J╥ NZ,σ
  102. J╥ Z,σ
  103. DJN┌ σ    decremen⌠ B anΣ jum≡ oε noεázero
  104.  
  105.  
  106. EXAMPL┼áO╞áRELATIV┼ JUMP╙
  107.  
  108. Al∞á assembler≤á calculatσ thσ displacemen⌠ fo≥á relativσá jumps«á Relativσ ì
  109. jump≤ shoulΣ bσ entereΣ witΦ labels.
  110.  
  111.       L─  HL,STOR┼
  112.       L─  B,(HL⌐
  113.       IN├ H╠
  114.       L─  E,(HL⌐
  115.       L─  HL,░
  116.       L─  D,░
  117. LOO╨  AD─ HL,D┼è      DJN┌á LOO╨
  118.       L─  (ANS),H╠
  119.       RE╘
  120. STOR┼áDEF┬ ╢
  121.       DEF┬ 5╕
  122. AN╙   DEF╫ ░
  123.  
  124.  
  125. EXAMPL┼áO╞ RELATIV┼ JUMP╙
  126.  
  127. Thi≤ examplσ illustrate≤ ß methoΣ oµ multiplication« Therσ arσ othe≥ faste≥ ì
  128. method≤ tha⌠ wil∞ bσ showε later.
  129.  
  130.       L─  A,▒
  131. LOOP▒ AD─ A,┴
  132.       L─  (STORE),┴
  133.       J╥  NC,LOOP▒
  134.       IN├ ┴
  135.       L─  B,╖
  136. LOOP▓ AD─ A,┴
  137.       L─  (STORE),┴
  138.       IN├ ┴
  139.       L─  (STORE),┴
  140.       DJN┌ LOOP▓
  141.       RE╘
  142. STOR┼ DEF┬ ░
  143.  
  144.  
  145. TH┼ STAC╦
  146.  
  147. Thσá Stacδ i≤ aε areß oµ externa∞ Randoφ Acces≤ Memory¼á tha⌠ i≤ useΣ a≤á ß ì
  148. serie≤á oµ registe≥ pairs¼á iε conjunctioε witΦ ß Stacδ Pointer«á Thσ Stacδ ì
  149. Pointe≥ (SP⌐ i≤ ß singlσ doublσ lengtΦ registe≥ withiε thσ Z80¼á capablσ oµ ì
  150. holdinτá u≡ t∩ 65335«á Beforσ loadinτ thσ Stacδ froφ an∙ interna∞á registe≥ ì
  151. pair¼á thσ Stacδ Pointe≥ i≤ decrementeΣ twice¼á ¿ thu≤ pointinτ t∩ thσ nex⌠ ì
  152. pai≥ oµ memor∙ locations)« Thσ content≤ oµ thσ registe≥ i≤ theε loadeΣ int∩ ì
  153. thσ Stacδ indirectl∙ usinτ thσ S╨ registe≥ a≤ thσ address«á Thσ instructioε ì
  154. i≤á PUS╚ dd«á Continuinτ t∩ PUS╚ datß oε t∩ thσ Stacδ result≤ iεá thσá datß ì
  155. beinτá pusheΣ iε a⌠ thσ bottoφ oµ thσ Stacδ anΣ  thσ Stacδ Pointe≥á workinτ ì
  156. it≤ wa∙ dowε througΦ memory«á PO╨ dΣ retrieve≤ datß froφ thσ Stacδ int∩ thσ ì
  157. defineΣá registe≥ pair«á  Thσ registe≥ pai≥ i≤ loadeΣ witΦ thσ content≤á oµ ì
  158. thσá memor∙ locatioε pointeΣ t∩ b∙ S╨ register«á Theε thσ S╨ i≤ incrementeΣ ì
  159. twice«á Continuinτ t∩ PO╨ datß froφ thσ Stacδ result≤ iε informatioεá beinτ ì
  160. POPpeΣá froφ thσ bottoφ oµ thσ Stacδ anΣ thσ Stacδ Pointe≥ workinτ it≤á wa∙ ì
  161. bacδá u≡ througΦ thσ memory«á Iµ ß  serie≤ oµ register≤ i≤ PUSHeΣ ont∩á thσ ì
  162. Stack¼á anΣ subsequentl∙ POPpeΣ ofµ thσ Stack¼ the∙ reappea≥ iε thσ reversσ ì
  163. order« Thσ BC¼ D┼ anΣ H╠  register≤ ma∙ bσ PUSHeΣ oε t∩ anΣ POPpeΣ froφ thσ ì
  164. Stack« Thσ Accumulato≥ ma∙ als∩ bσ PUSHeΣ oε t∩ thσ Stack¼ bu⌠ thi≤ i≤ donσ ì
  165. witΦ thσ flaτ registe≥ F¼á whicΦ wil∞ bσ discusseΣ later« Thσ Stacδ Pointe≥ ì
  166. caεá takσá par⌠á iε ß numbe≥ oµ instruction≤ alread∙á discussed«á The∙á arσ ì
  167. simpl∙ thosσ iε  whicΦ DE¼á o≥ B├ caε takσ part« Thσ instructioε equivalen⌠ ì
  168. t∩á E╪á DE,H╠ i≤ howeve≥ E╪ (SP),HL¼á tha⌠ EXchange≤ thσá content≤á oµá thσ ì
  169. bottoφ oµ thσ Stacδ witΦ thσ H╠ register.
  170.  
  171. Summar∙ - thσ Stacδ anΣ S╨ registe≥
  172. PUS╚ D─  wherσ D─ i≤ AF¼áBC¼áDE¼ o≥ HL« 
  173.          Froφ no≈ oε dΣ caε bσ considereΣáa≤ representinτ BC¼áDE¼áHL o≥ SP«á
  174. PO╨  D─
  175. L─   SP,nεèL─   SP,(nn⌐
  176. L─   (nn),S╨
  177. L─   SP,H╠
  178. AD─  HL,S╨
  179. AD├  HL,S╨
  180. SB├  HL,S╨
  181. IN├  S╨
  182. DE├  S╨
  183. E╪   (SP),HL
  184.  
  185.  
  186. EXAMPLE╙ USIN╟ TH┼ STAC╦
  187.  
  188. Thσ Stacδ Pointe≥ i≤ initiall∙ se⌠ to¼á fo≥ example¼ 409┤ anΣ work≤ it≤ wa∙ ì
  189. dowεá toward≤ thσ prograφ area«á Kee≡ thσ S╨ a⌠ thσ to≡ enΣ oµ thi≤ areß oµ ì
  190. memor∙ t∩ ensurσ tha⌠ thσ assemble≥ doe≤ no⌠ stop«á Thσ actua∞ valuσ iε thσ ì
  191. S╨ registe≥ i≤ immateria∞ fo≥ mos⌠ oµ it≤ applications.
  192.  
  193.      L─   HL,5678╣
  194.      L─   DE,3456╖
  195.      L─   BC,1234╡
  196.      PUS╚ H╠
  197.      PUS╚ B├
  198.      PUS╚áD┼
  199.      E╪á  (SP),H╠
  200.      L─   BC,░
  201.      PO╨  D┼
  202.      PO╨  B├
  203.      PO╨  H╠
  204.      RE╘
  205.  
  206.  
  207. CALL╙áT╧ SUBROUTINE╙
  208.  
  209. ┴á subroutinσ i≤ ß par⌠ oµ ß prograφ tha⌠ i≤ calleΣ froφ thσá maiεá prograφ ì
  210. anΣá oncσá completeΣ return≤ bacδ t∩ thσ maiε program«á  Thσ subroutinσá i≤ ì
  211. usuall∙ calleΣ froφ ß numbe≥ oµ place≤ iε thσ program«á Thσ Z8░ allow≤ thi≤ ì
  212. featurσ b∙ thσ instructioε CALL«á Thσ CAL╠ instructioε i≤ simila≥ t∩ thσ J╨ ì
  213. instructioεá excep⌠á tha⌠ thσ addres≤ oµ thσ nex⌠á sequentia∞á instruction¼ ì
  214. helΣ iε thσ P├ register¼á i≤ PUSHeΣ ont∩ thσ Stack¼á prio≥ t∩ thσ jump« Thσ ì
  215. returε instructioε RET¼á POP≤ thσ returε addres≤ froφ thσ Stack¼á bacδ int∩ ì
  216. thσá P├á register¼á t∩ continuσ wherσ  thσ maiε prograφ lef⌠á off«á Iµá thσ ì
  217. numbe≥á oµ PUSHe≤ anΣ CALL≤ iε thσ subroutinσ doe≤ no⌠ equa∞ thσ numbe≥á oµ ì
  218. POP≤á anΣ RETurns¼á obviousl∙ thi≤ wil∞ no⌠ happen«á BotΦá conditiona∞á anΣ ì
  219. unconditiona∞ CALL≤ anΣ RETurn≤ arσ availablσ oε thσ Z80« Al∞ fou≥ type≤ oµ ì
  220. condition≤á alread∙ considereΣ ¿ NC¼á C¼á N┌ anΣ ┌ ⌐ caε bσ useΣ witΦ CALL≤ ì
  221. anΣ RETurns.
  222.  
  223. Summar∙ - call≤ anΣáreturn≤
  224.      CAL╠á NC,nε
  225.      RE╘   N├á      N∩áCarr∙
  226.  á   CAL╠á C,nε
  227.      RE╘á  ├á       Carr∙áse⌠
  228.      CAL╠  NZ,nε
  229.      RE╘   N┌á      No⌠áZer∩
  230.  á   CAL╠á Z,nε
  231.      RE╘á  ┌        Zer∩ se⌠ 
  232.  
  233. Iµá thσ conditioε i≤ no⌠ met¼á thσ prograφ wil∞ no⌠ CAL╠ thσ subroutinσá o≥ ìèRETurε froφ it.
  234.  
  235.  
  236. EXAMPL┼ O╞ CALL╙ T╧áSUBROUTIN┼
  237.  
  238. I⌠á mus⌠ bσ remembereΣ tha⌠ ß subroutinσ ma∙ requirσ thσ usσ oµ ßá registe≥ ì
  239. whosσá content≤ arσ stil∞ requireΣ iε thσ maiε program«á It≤ content≤á mus⌠ ì
  240. thereforσá bσá PUSHeΣ ont∩ thσ stacδ o≥á otherwisσá storeΣá elsewhere¼á anΣ ì
  241. retrieveΣ a⌠ thσ enΣ oµ thσ subroutine« Thσ followinτ examplσ add≤ togethe≥ ì
  242. thσ firs⌠ 3▓ pair≤ oµ memor∙ locations« Thσ resul⌠ i≤ lef⌠ iε HL« Thσ stacδ ì
  243. anΣá thσ H╠ register≤ arσ botΦ useΣ a≤ storagσ inspitσ oµ thσá interferencσ ì
  244. oµ thσ CALL¼ b∙ usinτ thσ E╪ (SP),H╠ instruction:
  245.  
  246.        L─   HL,░
  247.        L─   B,3▓
  248.        PUS╚ H╠
  249. LOOP▒á L─á  E,(HL⌐
  250.        IN├  H╠
  251.        L─   D,(HL⌐
  252.        IN├  H╠
  253.        E╪á  (SP),H╠
  254.        CAL╠ SUB╥
  255.        E╪   (SP),H╠
  256.        DJN┌ LOOP▒
  257.        PO╨  H╠
  258.        RE╘
  259. SUB╥   AD─  HL,D┼
  260.        RE╘
  261.  
  262.  
  263. EXAMPL┼áO╞ CONDITIONA╠ CALL╙
  264.  
  265. Thi≤á simplσá examplσá count≤ u≡ thσ numbe≥ oµ memor∙ location≤á holdinτá ß ì
  266. numbe≥ abovσ 19▓ anΣ belo≈ 6┤ iε thσ firs⌠ 3▓ memor∙ locations.
  267.  
  268.       L─   HL,░
  269.       L─   DE,░
  270.       L─   B,3▓
  271. LOO╨  L─   A,(HL⌐
  272.       C╨   19│
  273.       CAL╠ NC,ABOV┼
  274.       C╨á  6┤
  275.       CAL╠ C,BELO╫
  276.       IN├  H╠
  277.       DJN┌ LOO╨
  278.       RE╘
  279. ABOV┼ IN├  ┼
  280.       RE╘
  281. BELO╫áIN├ á─
  282.       RE╘
  283.  
  284.  
  285.  
  286.  
  287.  
  288. BINAR┘ NOTATIO╬
  289.  
  290. Iµ wσ werσ t∩ takσ thσ to≡ ofµ ß Z8░ chi≡ and¼ usinτ ß powerfu∞ microscope¼ ì
  291. looδ a⌠ ß register¼á wσ woulΣ seσ tha⌠ i⌠ consist≤ oµ ╕ cells«á Thesσ cell≤ ìèarσ capablσ oµ beinτ switcheΣ betweeε tw∩ differen⌠ states«á Conventionall∙ ì
  292. wσ designatσ onσ statσ a≤ "1ó anΣ thσ othe≥ a≤ "0"«á Thσ patterε oµ 1'≤ anΣ ì
  293. 0'≤ coulΣ bσ 1011100░ say« Ho≈ d∩ wσ interpre⌠ thi≤ pattern┐ Thσ answe≥ is¼ ì
  294. anywa∙ wσ like« Iε thi≤ lessoε wσ sho≈ tha⌠ thi≤  patterε coulΣ bσ 184,-72¼ ì
  295. B8╚á anΣá eveε C╨ B«á Thσ onl∙ onσ thσ processo≥ ha≤ buil⌠ int∩ i⌠á i≤á thσ ì
  296. latter«á EacΦ digi⌠ iε ß numbe≥ caε bσ considereΣ t∩ havσ ß weighting«á Fo≥ ì
  297. decima∞ number≤ thesσ weighting≤ arσ Digi⌠ -
  298.  
  299.                 │    ▓    ▒    ░
  300.              100░  10░   1░    ▒
  301.  
  302. sincσá eacΦá digi⌠á caε havσ onσ oµ teε states¼á designateΣá ░á - 9«á Iεá ß ì
  303. registe≥ eacΦ digi⌠ o≥ bi⌠ ha≤ onl∙ tw∩ states«á Thereforσ wσ caε interpre⌠ ì
  304. thσ digit≤ a≤ havinτ weighting≤ oµ bi⌠ -
  305.  
  306.              ╖    ╢   ╡    ┤   │   ▓   ▒   ░
  307.            12╕á  6┤  3▓á  1╢   ╕   ┤   ▓   ▒
  308.  
  309. Takinτá ou≥ numbe≥ 1011100░ fo≥ examplσ anΣ notinτ tha⌠ bit≤ tha⌠á arσá "0ó ì
  310. contributσá nothinτá t∩ thσ number¼á thσ decima∞ equivalen⌠ oµ 1011100░á i≤ ì
  311. giveε b∙ -
  312.  
  313.                   128+32+16+8=184
  314.  
  315. Thσ maximuφ numbe≥ tha⌠ caε bσ helΣ iε aε ╕ bi⌠ registe≥ i≤ -
  316. ì
  317.                   128+64+32+16+8+4+2+1=25╡
  318.  
  319. Thi≤á i≤á thσá numbe≥á wσá originall∙á assumeΣá a⌠á thσá beginninτá oµá ou≥ ì
  320. discussion«á Jus⌠á a≤á wσ adΣ tw∩ decima∞ number≤á together¼á carryinτá onσ ì
  321. forwarΣ iµ thσ suφ oµ tw∩ digit≤ i≤ greate≥ thaε 9¼á wσ caε adΣ tw∩á binar∙ ì
  322. numbers« Iµ thσ suφ i≤ abovσ one¼ ß onσ i≤ carrieΣ forward« ie.-
  323.  
  324.                   ░ ▒ ▒ ░ ▒ ▒ ▒ ░
  325.               ½á  ░á░á▒á░ ░ ▒ ░ ▒
  326.                 ------------------
  327.        give≤      ▒ ░ ░ ▒ ░ ░ ▒ ▒
  328.  
  329. Simila≥ wσ caε perforφ subtraction« i.e.
  330.  
  331.                   ░ ▒ ▒ ░ ░á▒á▒á░
  332.                -  ░á░á▒á░ ▒ ▒ ░ ▒
  333.                 -------------------
  334.        give≤      ░ ░ ▒ ▒ ▒ ░ ░ 1
  335.  
  336.  
  337. EXAMPLE╙áO╞áBINAR┘ NOTATIO╬
  338.  
  339. Somσá assembler≤á havσ onσ instructioε no⌠ normall∙ founΣ iεá most¼á namel∙ ì
  340. BIN«á Thσ assemble≥ allocate≤ onσ memor∙ locatioε t∩ thσ line¼á whicΦ woulΣ ì
  341. normall∙ bσ labelled«á I⌠ constantl∙ display≤ thi≤ locatioε iε binar∙ form« ì
  342. Thσá numbe≥ afte≥ BI╬ i≤ thσ numbe≥ initiall∙ inserteΣ int∩á thσá location« ì
  343. Afte≥ goinτ througΦ thσ   followinτ examplσ tr∙ modifyinτ thσ displayinτ oµ ì
  344. STOR┼ iε examplσ 11B.
  345.  
  346.       L─  HL,STOR┼
  347. LOO╨  DE├ (HL⌐
  348.       J╥  NZ,LOO╨
  349.       L─  A,(NUM1⌐è      L─  HL,NUM▓
  350.       AD─ A,(HL⌐
  351.       L─  (ANS),┴
  352.       RE╘
  353. STOR┼áBI╬á 1╡
  354. NUM▒  BI╬  8▒
  355. NUM▓á BI╬á 9╡
  356. AN╙á  BI╬á ░
  357.  
  358.  
  359. HEXADECIMA╠áNOTATIO╬
  360.  
  361. Binar∙á number≤ arσ to∩ cumbersomσ anΣ decima∞ to∩ inconvenien⌠ t∩á displa∙ ì
  362. multiplσá registe≥ numbers«á ┴ methoΣ oµ presentinτ binar∙ number≤ ha≤ beeε ì
  363. developeΣ t∩ ge⌠ rounΣ thesσ problems«á InsteaΣ oµ basinτ thσ numbe≥ oεá 1░ ì
  364. a≤ iε decima∞ o≥ ▓ a≤ iε binary¼á wσ basσ i⌠ oε 16«á  Thi≤ numberinτ systeφ ì
  365. i≤á calleΣá Hexadecimal«á Wσ requirσ 1╢ differen⌠  symbol≤ t∩á represen⌠á ß ì
  366. digit«á 0-╣á give≤ u≤ thσ firs⌠ 1░ anΣ A-╞ thσ fina∞ 6«á ┴ lis⌠ oµ decimal¼ ì
  367. binary¼ anΣ hexadecima∞ equivalent≤ arσ giveε below:-
  368.  
  369.               Decima∞   Binar∙á    Hexadecima∞
  370.          á       ░       000░á         ░
  371.          á       ▒       000▒          ▒
  372.                  ▓á      001░á         ▓
  373.                  │á      001▒á         │
  374.          á       ┤       010░á         ┤
  375.          á       ╡á      010▒          ╡
  376.         áá       ╢á      011░á         ╢
  377.          á       ╖á      011▒á         ╖
  378.         áá       ╕       100░á         ╕
  379.          á       ╣       100▒          ╣
  380.                 1░á      101░á         ┴
  381.                 1▒á      101▒á         ┬
  382.         á       1▓       110░á         ├
  383.         á       1│á      110▒          ─
  384.                 1┤       111░          ┼
  385.                 1╡       111▒          F
  386.  
  387. Al∞á 1╢ state≤ oµ thσ ┤ binar∙ bit≤ arσ covereΣ b∙ 0-F«á Hencσ onl∙ ▓á hex-ì
  388. adecima∞ digit≤ arσ requireΣ t∩ displa∙ thσ content≤ oµ aε ╕ bi⌠á register« ì
  389. Ou≥ examplσ -
  390.  
  391.           1011100░áá divide≤áu≡áinto  101▒á100░á o≥áB╕áHex«
  392.  
  393. ┴ doublσ registe≥ holdinτ sa∙ 1100100▒ 1011100░ wil∞ bσ representeΣ b∙ C9B╕ ì
  394. hex«á Conversioεá oµá ßá he° numbe≥ t∩ it≤ decima∞ equivalen⌠á follow≤á thσ ì
  395. standarΣ calculation« i.e.
  396.  
  397. á  B╕á he°á ╜ (┬ hex) ¬ 16 ½á(8) ¬á▒
  398. á           ╜ 11*16 + 8
  399.             = 18┤
  400.  
  401. Alway≤á remembe≥á tha⌠ ß he° numbe≥ ha≤ ß basσ oµá 1╢á decimal¼á ßá decima∞ ì
  402. numbe≥ ha≤ ß basσ oµ 1░ anΣ ß binar∙ numbe≥ ß basσ oµ 2.
  403.  
  404. EXAMPLE╙áO╞áHEXADECIMA╠ NOTATIO╬
  405.  
  406. No≈á tha⌠ he° notatioε ha≤ beeε introduceΣ wσ caε discus≤ ho≈ thσá compute≥ ì
  407. store≤ program≤ iε morσ detail«á A≤ alread∙ mentioned¼á i⌠ storeΣ memor∙ a≤ ìènumbers«á Somσá instruction≤ onl∙ requirσ ß singlσ number¼á other≤á requirσ ì
  408. more.
  409.  
  410.      L─  A,25╚
  411.      AD─ A,┴
  412.      DA┴
  413.      L─  HL,4589╚
  414.      L─  DE,3812╚
  415.      L─  A,╠
  416.      SU┬ ┼
  417.      DA┴
  418.      L─  L,┴
  419.      L─  A,╚
  420.      SB├ A,─
  421.      DA┴
  422.      L─  H,┴
  423.      RE╘
  424.  
  425.  
  426. BINAR┘ CODE─áDECIMA╠áNOTATIO╬
  427.  
  428. Wσá woulΣ stil∞ likσ t∩ bσ ablσ t∩ perforφ calculation≤ oε decima∞á number≤ ì
  429. withou⌠á havinτ t∩ conver⌠ t∩ binar∙ o≥ hexadecima∞ form«á Hexidecima∞ forφ ì
  430. hold≤á ßá ke∙á t∩á ß methoΣ oµá achievinτá this«á Thσá he°á digi⌠á require≤ ì
  431. adjustmen⌠ t∩ avoiΣ thσ digit≤ A-F« Addinτ ╢ t∩ thσ digit¼ iµ thesσ symbol≤ ì
  432. appear¼á result≤ iε correc⌠ adjustment« Takσ  thσ he° numbe≥ ├ (╜ 1▓ dec.)« ì
  433. Addinτá ╢ give≤ 1╕ decima∞ o≥ 1▓ hex«á Hencσ thσ he° numbe≥ look≤ identica∞ ì
  434. t∩á thσá decima∞á answe≥ required«á EacΦ digi⌠ i≤ helΣ iεá ┤á bit≤á oµá thσ ì
  435. register«á Thesσ ┤ bit≤ arσ calleΣ ß nibble¼ thσ wholσ ╕ bi⌠ worΣ i≤ termeΣ ì
  436. ß byte«á Wh∩ saiΣ programmer≤ havσ n∩ sensσ oµ humour┐ Thi≤ presentatioε i≤ ì
  437. termeΣá Binar∙á CodeΣá Decima∞á o≥ BCD«á Thσá Z8░á accommodate≤á thσá abovσ ì
  438. adjustment¼ witΦ thσ instructioε   DAA¼ o≥ Decima∞ Adjus⌠ Accumulator« Thi≤ ì
  439. instructioεá i≤ useΣ afte≥ aε ╕ bi⌠ ADD¼á ADC¼á SUB¼á o≥ SB├ t∩ adjus⌠á thσ ì
  440. Accumulato≥á content≤á b∙ addinτ ╢ t∩ thσ nibble¼á iµ eithe≥ nibblσ iεá thσ ì
  441. answe≥á i≤á abovσ 9«á T∩ perforφ thi≤ operatioε thσ Z8░á use≤á tw∩á furthe≥ ì
  442. flags¼á thσ ╚ flaτ ¿ ß Halµ carr∙  betweeε nibble≤ )¼á anΣ ╬ flaτ (subtrac⌠ ì
  443. instructioε performeΣ last)«á Sincσ thesσ flag≤ canno⌠ bσ testeΣ a≤ par⌠ oµ ì
  444. ß conditiona∞ jum≡ etc« the∙ arσ oµ littlσ use.
  445.  
  446.  
  447. EXAMPLE╙ O╞ B.C.D« NOTATIO╬
  448.  
  449. Thesσ example≤ sho≈ simplσ additioε anΣ subtractioε iε BC─ format« Remembe≥ ì
  450. t∩ kee≡ iε He° displa∙ modσ o≥ thσ illustration≤ wil∞ no⌠ appea≥ iε BCD.
  451.  
  452.       L─  A,25╚
  453.       L─  HL,STOR┼
  454.       L─  DE,2468╚
  455.       IN├ (HL⌐
  456.       RE╘
  457.       BI╬ 65╚
  458.       BI╬ 87╚
  459.       BI╬á9A╚
  460.       BI╬ DF╚
  461.       BI╬áFF╚
  462.       BI╬ 64╚
  463. STOR┼ DEF┬ 6┤
  464.  
  465. èPOSITIV┼ AN─áNEGATIV┼áNUMBE╥ NOTATIO╬
  466.  
  467. S∩á fa≥ wσ havσ onl∙ deal⌠ witΦ positivσ numbers«á Iµ wσ haΣ takeε ╢ froφ ╡ ì
  468. wσá woulΣá enΣá u≡á witΦá thσ answe≥á 25╡á witΦá carr∙á set«á Therσá i≤á aε ì
  469. interpretatioεá oµá number≤ tha⌠ allow≤ u≤ t∩ conside≥ thi≤ answe≥á a≤á thσ ì
  470. negativσá numbe≥ -1«á Iε thi≤ interpretatioε -▒ mus⌠ equa∞ 25╡ o≥ 11111111¼ ì
  471. o≥á thσá processo≥á woulΣ no⌠ bσ ablσ t∩ takσ ╢ froφ ╡ anΣá ge⌠á thσá righ⌠ ì
  472. answer«á Furthe≥ 5-╖ ╜ -▓ o≥ 25┤ o≥ 11111110«á Bi⌠ 7¼á thσ mos⌠ significan⌠ ì
  473. bit¼á represent≤ thσ sigε ¿ ½ o≥ - ⌐ oµ thσ number«á Wheε bi⌠ ╖ i≤ "1óá thσ ì
  474. numbe≥á i≤á negative¼á anΣá wheεá "0ó thσ numbe≥á i≤á positive«á ┴á  usefu∞ ì
  475. operatioε woulΣ bσ t∩ makσ ß positivσ numbe≥ negative«á Changinτ bi⌠ ╖ doe≤ ì
  476. no⌠á d∩á this«á Takσá thσ positivσ numbe≥ ▓ o≥ 0000001░á anΣá it≤á negativσ ì
  477. equivalen⌠á -▓á o≥ 1111111░ fo≥ example«á Invertinτ al∞ bit≤ oµ thσá binar∙ ì
  478. numbe≥ oµ +▓  give≤ 11111101¼á whicΦ i≤ ▒ les≤ thaε tha⌠ fo≥ -2«á Hencσá t∩ ì
  479. makσá ßá positivσ numbe≥ negativσ wσ inver⌠ al∞ it≤ binar∙ bits¼á knowεá a≤ ì
  480. Complimenting¼á anΣ adΣ 1«á Thσ notatioε i≤ generall∙ termeΣ 2≤ complement«  ì
  481. i.e.
  482.  
  483.                    ░ ░ ░ ░ ░ ▒ ░ ▒    = +╡    
  484.           inver⌠   ▒ ▒ ▒ ▒ ▒ ░ ▒ ░
  485.         adΣ ▒      ▒ ▒ ▒ ▒ ▒ ░ ▒ ▒    = -╡
  486.           inver⌠á  ░á░ ░ ░ ░ ▒ ░ ░
  487.         adΣ ▒      ░ ░ ░ ░ ░ ▒ ░ ▒    = +╡
  488.  
  489. Thσ operatioε luckil∙ als∩ make≤ ß negativσ numbe≥ positive« ┴ ver∙ importì
  490. an⌠á point«á Thσ larges⌠ positivσ numbe≥ wσ caε holΣ iε ß singlσá register¼  ì
  491. usinτá thi≤á notatioε i≤ 0111111▒ o≥ 12╖ anΣ thσá larges⌠á negativσá numbe≥ ì
  492. 1000000░á o≥ -128«á Thσ Z8░ ha≤ tw∩ instruction≤ tha⌠ ma∙ bσ useΣ fo≥ thesσ ì
  493. operation≤ CP╠ complement≤ o≥ invert≤ thσ content≤ oµ thσ Accumulator«á NE╟ ì
  494. negates¼áá o≥áá make≤á negative¼áá thσá content≤á oµá thσá Accumulato≥áá b∙ ì
  495. complementinτ anΣ addinτ ▒ iε onσ operation« ┴ Sigε flaτ (S⌐ i≤ provideΣ oε ì
  496. thσá Z80«á I⌠á duplicate≤á thσá sigε ¿ bi⌠ ╖ ⌐á oµá thσá answe≥á afte≥á an∙ ì
  497. arithmetiπá operatioεá oεá thσá Accumulator«á Thσ sigε flaτ i≤á "0óá fo≥á ß ì
  498. positivσ resul⌠ anΣ "1ó fo≥ ß negativσ result«á Wheε performinτá arithmetiπ ì
  499. operation≤á whicΦ wσ wisΦ t∩ interpre⌠ withiε thσ rangσ -12╕ t∩á +127¼á thσ ì
  500. Carr∙ flaτ n∩ longe≥ signal≤ aε ou⌠ oµ rangσ result«á Howeve≥ anothe≥ flag¼ ì
  501. thσá overflo≈ (P/V⌐ flaτ does«á I⌠ i≤ ß "1ó wheneve≥ thσ answe≥ i≤á outsidσ ì
  502. thσá rangσá -12╕ t∩ +12╖ anΣ "0ó withiε thσ   range«á I⌠ i≤á effectivel∙á ß ì
  503. carr∙á int∩á bi⌠á ╖ whicΦ woulΣ makσ thσ sigε bi⌠ incorrect«á Therσá i≤á n∩ ì
  504. reasoε fo≥ stickinτ t∩ ╕ bit≤ usinτ thi≤ method«á S∩ lonτ a≤ thσ numbe≥á oµ ì
  505. bit≤á i≤á sufficien⌠ anΣ thσ mos⌠ significan⌠ bi⌠ i≤ takeε a≤ thσ sigεá bi⌠ ì
  506. an∙á sizσá positivσ o≥ negativσ numbe≥ caεá bσá represented«á Performinτá ß ì
  507. simila≥á calculatioεá t∩á thσ abovσ wσ caε sho≈ tha⌠ ßá registe≥á pai≥á caε ì
  508. represen⌠á ß numbe≥ iε thσ  rangσ +3276╖ t∩ -32768«á Thσ Sigε anΣá overflo≈ ì
  509. flag≤á arσ als∩ operativσ afte≥ AD├ anΣ SB├ instructioε oε thσ H╠ register« ì
  510. I⌠á reflect≤á thσ 15tΦ bi⌠ (o≥ bi⌠ ╖ oµ ╚ register)«á I⌠á i≤á importan⌠á t∩ ì
  511. remembe≥á tha⌠á thσá Zero¼á Carry¼á Sign¼á anΣ overflo≈á flag≤á arσá alway≤ ì
  512. operativσá afte≥á aεá ╕  bi⌠ arithmetiπ instructioε o≥ ßá 1╢á bi⌠á additioε ì
  513. involvinτ thσ Carry«á You≥ interpretatioε oµ thσ resul⌠ determine≤ iε whicΦ ì
  514. flag(s⌐ yo⌡ shoulΣ bσ interesteΣ in.
  515.  
  516.  
  517.  
  518.  
  519.  
  520. EXAMPLE╙ O╞á+V┼áAN─á-V┼áNOTATIO╬
  521.  
  522. AlthougΦá thesσá example≤á appea≥ t∩ bσ al∞ positive¼á the∙ caεá bσá vieweΣ ì
  523. equall∙á a≤á negativσá wherσ appropriatσ anΣ thσ Sigεá anΣá overflo≈á flag≤ ìèobserveΣ operating«á Remembe≥ ß numbe≥ abovσ 12╕ i≤ negative« Sincσ al∞ thσ ì
  524. negativσá number≤ iε thσ example≤ arσ small¼á the∙ caε bσ seeε quickl∙á anΣ ì
  525. simpl∙á bσá converteΣá b∙ subtractinτ thσá numbe≥á froφá 256«á i.e«á -▓á i≤ ì
  526. equivalen⌠ t∩ 25┤ etc.
  527.  
  528.       L─  A,25┤
  529.       NE╟
  530.       NE╟
  531.       AD─ A,▓
  532.       IN├ ┴á  
  533.       L─á HL,▓
  534.       L─  DE,FFFE╚
  535.       AD─áHL,D┼
  536.       CP╠ L─ HL,STOR┼
  537.       L─  (HL),7F╚
  538.       IN├ (HL)
  539.       RE╘
  540. STOR┼ BI╬ 0
  541.  
  542.