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 >
Wrap
Text File
|
1979-12-31
|
21KB
|
542 lines
Lesson≤ 1░ - 1╖
10«á Conditiona∞ anΣ unconditiona∞áJP≤ E°á- jump≤
11«á Relativσ jump≤ E° - relativσ jump≤ ▒
E°á- relativσájump≤ ▓
12«á Thσ Stacδ E° - pushe≤ anΣ pop≤
13«á Call≤át∩ subroutine≤ E° - unconditiona∞ call≤ ª ret≤
E° - conditiona∞ call≤
14«á Binar∙ánotatioε E° - binar∙ánotatioε
15«á Hexadecima∞ notatioεá E°á- he°ánotatioε
16«á Binar∙áCodeΣáDecima∞ánotatioε E° - BC─ notatioε
17«á Positivσ anΣ negativσ notatioε E° - +vσ anΣ -vσ number≤
INTRODUCTIO╬
Thσ processor¼á unde≥ thσ programmer'≤ direction¼á ha≤ thσ capacit∙ t∩ makσ ì
decisions«á Iεá thσá followinτ lesson≤ wσ shal∞ discus≤ thesσá instruction≤ ì
tha⌠á makσ ß compute≥ morσ thaε jus⌠ ß calculator«á Wσ shal∞ theε looδá a⌠ ì
number≤ helΣ iε register≤ iε morσ detail.
JUMP╙
Thσá aspec⌠á oµá ß compute≥ tha⌠ make≤ i⌠ morσ thaεá ßá calculato≥á i≤á it≤ ì
abilit∙á t∩á changσá it≤á sequencσ oµ operation≤ a≤á ßá resul⌠á oµá earlie≥ ì
instructions«á Withiε thσ Z8░ therσ i≤ ß counte≥ calleΣ thσ Prograφ Counte≥ ì
o≥á PC«á Thi≤ counte≥ keep≤ tracδ oµ whicΦ instructioε thσ processo≥ i≤á t∩ ì
perforφá next«á B∙ modifyinτ it≤ contents¼á thσ processo≥ caε bσ jumpeΣ t∩ ì
an∙á instructioε iε memory«á Thσ simples⌠ jum≡ i≤ J╨ nn¼á wherσ nεá i≤á thσ ì
addres≤á t∩ whicΦ thσ prograφ i≤ t∩ jump«á Thi≤ i≤ aε unconditiona∞á jump¼ ì
thσá Prograφá Counte≥ alway≤ jumpinτ t∩ thσ addres≤ nn«á Thσ morσá powerfu∞ ì
jum≡á i≤á thσ conditiona∞ jump«á Thσ processo≥ test≤ thσ statσ oµá ßá flag¼ ì
beforσá eithe≥á jumpinτ o≥ continuinτ iε sequence«á Thσá conditiona∞á jump≤ ì
involvinτ thσ carr∙ anΣ zer∩ flag≤ are:-
J╨ NC,nε jum≡ iµ carr∙ flaτ no⌠ se⌠
J╨ C,nε jum≡ iµ carr∙áflaτ set
á J╨áNZ,nεá jum≡áiµ zer∩ flaτ no⌠ se⌠
J╨ Z,nε jum≡áiµázer∩áflaτáse⌠
ì
Indirec⌠á jump≤ arσ als∩ availablσ oε thσ Z8░ usinτ thσ H╠á registe≥á pair« ì
Thσá instructioε J╨ (HL⌐ load≤ thσ prograφ counte≥ witΦ thσ content≤ oµ thσ ì
H╠á register«á Thu≤ thσ addres≤ oµ thσ nex⌠ instructioε t∩ bσ performeΣá i≤ ì
containeΣá withiε thσ H╠ register«á Sincσ thσ content≤ oµ thσá H╠á registe≥ ì
pai≥ caε bσ thσ resul⌠ oµ somσ calculatioε thσ jum≡ caε bσ conditional.
Summar∙ - jump≤
J╨ nε
J╨ (HL⌐
J╨ NC,nε jum≡ oε n∩ carr∙
J╨ C,nε jum≡ oε carr∙
J╨ NZ,nε jum≡ oε no⌠ zer∩
J╨ Z,nε jum≡áoε zero
EXAMPLE╙áO╞áJUMP╙
AlthougΦá yo⌡ caε ente≥ thσ addres≤ withiε thσ jum≡ iε numbe≥ form¼á iµá i⌠ ì
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σ ì
instructioε i⌠ find≤ a⌠ tha⌠ addres≤ anΣ anythinτ coulΣ happeε anΣá usuall∙ ì
does«á T∩á ge⌠ rounΣ thi≤ probleφ usσ ß label¼á declarinτ i⌠ iε thσá labe∞ ì
columε iε fron⌠ oµ thσ instructioε t∩ whicΦ yo⌡ wisΦ t∩ jump.
L─ HL,STOR┼
L─ A,│
LOOP▒ L─ (HL),┴
IN├ ┴
C╨ ╕
J╨ NZ,LOOP▒
LOOP▓ DE├ (HL⌐
J╨ NZ,LOOP▓
RE╘
STOR┼ DEF┬ ░
RELATIV┼ JUMP╙
Onσ difficult∙ witΦ thσ abovσ type≤ oµ jum≡ i≤ that¼á iµ thσ star⌠á addres≤ ì
oµá thσá prograφá werσá changed¼á al∞á thσá jum≡á addresse≤á woulΣá requirσ ì
modification«á Relativσá jump≤á d∩ no⌠ havσ thi≤ difficulty«á Thσá absolutσ ì
addres≤á i≤ no⌠ storeΣ witΦ thσ instruction«á I⌠ i≤ thσ differencσá betweeε ì
thσá curren⌠á content≤ oµ thσ prograφ counte≥ anΣ thσ addres≤ t∩á whicΦá wσ ì
wisΦá t∩ jum≡ tha⌠ i≤ storeΣ withiε thσ instruction«á Relativσá jump≤á arσ ì
limiteΣ t∩ jumpinτ backward≤ 12╕ location≤ anΣ forward≤ 12╖ locations«á Thσ ì
mnemoniπá fo≥ relativσ jump≤ i≤ J╥ anΣ caε takσ al∞ thσ form≤ discusseΣ s∩ ì
fa≥ fo≥ JP¼á i.e« JR¼ J╥ NC¼ J╥ C¼ J╥ N┌ anΣ J╥ Z« Therσ i≤ onσ particula≥ ì
relativσ jum≡ instructioε tha⌠ i≤ particularl∙ useful¼ namel∙ Decremen⌠ anΣ ì
Jum≡ oε Non-Zero¼ o≥ DJNZ« Thσ ┬ registe≥ i≤ decrementeΣ and¼ iµ thσ resul⌠ ì
i≤á no⌠ zero¼á thσ processo≥ perform≤ ß relativσ jum≡ t∩ thσá computeΣá ne≈ ì
address«á Iµá thσá resul⌠ i≤ zer∩ theε thσ nex⌠ instructioε iε sequencσá i≤ ì
taken« DJN┌ allow≤ u≤ t∩ repea⌠ ß serie≤ oµ instruction≤ ß prese⌠ numbe≥ oµ ì
times«á Thσá numbe≥ oµ repeat≤ i≤ equa∞ t∩ thσ content≤ oµ thσ ┬á registe≥ ì
wheε thσ loo≡ i≤ entered¼á s∩ lonτ a≤ thσ ┬ registe≥ doe≤ no⌠ forφ par⌠á oµ ì
thσ serie≤ oµ inst-ructions« N∩ flag≤ arσ affecteΣ b∙ an∙ jum≡ instruction≤ ì
includinτ DJNZ.
Summar∙á - relativσájump≤
J╥ σ wherσ σ i≤ thσ displacemen⌠ in
J╥ NC,σ thσárangσ 12╖ t∩ -12╕
J╥ C,σ
J╥ NZ,σ
J╥ Z,σ
DJN┌ σ decremen⌠ B anΣ jum≡ oε noεázero
EXAMPL┼áO╞áRELATIV┼ JUMP╙
Al∞á assembler≤á calculatσ thσ displacemen⌠ fo≥á relativσá jumps«á Relativσ ì
jump≤ shoulΣ bσ entereΣ witΦ labels.
L─ HL,STOR┼
L─ B,(HL⌐
IN├ H╠
L─ E,(HL⌐
L─ HL,░
L─ D,░
LOO╨ AD─ HL,D┼è DJN┌á LOO╨
L─ (ANS),H╠
RE╘
STOR┼áDEF┬ ╢
DEF┬ 5╕
AN╙ DEF╫ ░
EXAMPL┼áO╞ RELATIV┼ JUMP╙
Thi≤ examplσ illustrate≤ ß methoΣ oµ multiplication« Therσ arσ othe≥ faste≥ ì
method≤ tha⌠ wil∞ bσ showε later.
L─ A,▒
LOOP▒ AD─ A,┴
L─ (STORE),┴
J╥ NC,LOOP▒
IN├ ┴
L─ B,╖
LOOP▓ AD─ A,┴
L─ (STORE),┴
IN├ ┴
L─ (STORE),┴
DJN┌ LOOP▓
RE╘
STOR┼ DEF┬ ░
TH┼ STAC╦
Thσá Stacδ i≤ aε areß oµ externa∞ Randoφ Acces≤ Memory¼á tha⌠ i≤ useΣ a≤á ß ì
serie≤á oµ registe≥ pairs¼á iε conjunctioε witΦ ß Stacδ Pointer«á Thσ Stacδ ì
Pointe≥ (SP⌐ i≤ ß singlσ doublσ lengtΦ registe≥ withiε thσ Z80¼á capablσ oµ ì
holdinτá u≡ t∩ 65335«á Beforσ loadinτ thσ Stacδ froφ an∙ interna∞á registe≥ ì
pair¼á thσ Stacδ Pointe≥ i≤ decrementeΣ twice¼á ¿ thu≤ pointinτ t∩ thσ nex⌠ ì
pai≥ oµ memor∙ locations)« Thσ content≤ oµ thσ registe≥ i≤ theε loadeΣ int∩ ì
thσ Stacδ indirectl∙ usinτ thσ S╨ registe≥ a≤ thσ address«á Thσ instructioε ì
i≤á PUS╚ dd«á Continuinτ t∩ PUS╚ datß oε t∩ thσ Stacδ result≤ iεá thσá datß ì
beinτá pusheΣ iε a⌠ thσ bottoφ oµ thσ Stacδ anΣ thσ Stacδ Pointe≥á workinτ ì
it≤ wa∙ dowε througΦ memory«á PO╨ dΣ retrieve≤ datß froφ thσ Stacδ int∩ thσ ì
defineΣá registe≥ pair«á Thσ registe≥ pai≥ i≤ loadeΣ witΦ thσ content≤á oµ ì
thσá memor∙ locatioε pointeΣ t∩ b∙ S╨ register«á Theε thσ S╨ i≤ incrementeΣ ì
twice«á Continuinτ t∩ PO╨ datß froφ thσ Stacδ result≤ iε informatioεá beinτ ì
POPpeΣá froφ thσ bottoφ oµ thσ Stacδ anΣ thσ Stacδ Pointe≥ workinτ it≤á wa∙ ì
bacδá u≡ througΦ thσ memory«á Iµ ß serie≤ oµ register≤ i≤ PUSHeΣ ont∩á thσ ì
Stack¼á anΣ subsequentl∙ POPpeΣ ofµ thσ Stack¼ the∙ reappea≥ iε thσ reversσ ì
order« Thσ BC¼ D┼ anΣ H╠ register≤ ma∙ bσ PUSHeΣ oε t∩ anΣ POPpeΣ froφ thσ ì
Stack« Thσ Accumulato≥ ma∙ als∩ bσ PUSHeΣ oε t∩ thσ Stack¼ bu⌠ thi≤ i≤ donσ ì
witΦ thσ flaτ registe≥ F¼á whicΦ wil∞ bσ discusseΣ later« Thσ Stacδ Pointe≥ ì
caεá takσá par⌠á iε ß numbe≥ oµ instruction≤ alread∙á discussed«á The∙á arσ ì
simpl∙ thosσ iε whicΦ DE¼á o≥ B├ caε takσ part« Thσ instructioε equivalen⌠ ì
t∩á E╪á DE,H╠ i≤ howeve≥ E╪ (SP),HL¼á tha⌠ EXchange≤ thσá content≤á oµá thσ ì
bottoφ oµ thσ Stacδ witΦ thσ H╠ register.
Summar∙ - thσ Stacδ anΣ S╨ registe≥
PUS╚ D─ wherσ D─ i≤ AF¼áBC¼áDE¼ o≥ HL«
Froφ no≈ oε dΣ caε bσ considereΣáa≤ representinτ BC¼áDE¼áHL o≥ SP«á
PO╨ D─
L─ SP,nεèL─ SP,(nn⌐
L─ (nn),S╨
L─ SP,H╠
AD─ HL,S╨
AD├ HL,S╨
SB├ HL,S╨
IN├ S╨
DE├ S╨
E╪ (SP),HL
EXAMPLE╙ USIN╟ TH┼ STAC╦
Thσ Stacδ Pointe≥ i≤ initiall∙ se⌠ to¼á fo≥ example¼ 409┤ anΣ work≤ it≤ wa∙ ì
dowεá toward≤ thσ prograφ area«á Kee≡ thσ S╨ a⌠ thσ to≡ enΣ oµ thi≤ areß oµ ì
memor∙ t∩ ensurσ tha⌠ thσ assemble≥ doe≤ no⌠ stop«á Thσ actua∞ valuσ iε thσ ì
S╨ registe≥ i≤ immateria∞ fo≥ mos⌠ oµ it≤ applications.
L─ HL,5678╣
L─ DE,3456╖
L─ BC,1234╡
PUS╚ H╠
PUS╚ B├
PUS╚áD┼
E╪á (SP),H╠
L─ BC,░
PO╨ D┼
PO╨ B├
PO╨ H╠
RE╘
CALL╙áT╧ SUBROUTINE╙
┴á subroutinσ i≤ ß par⌠ oµ ß prograφ tha⌠ i≤ calleΣ froφ thσá maiεá prograφ ì
anΣá oncσá completeΣ return≤ bacδ t∩ thσ maiε program«á Thσ subroutinσá i≤ ì
usuall∙ calleΣ froφ ß numbe≥ oµ place≤ iε thσ program«á Thσ Z8░ allow≤ thi≤ ì
featurσ b∙ thσ instructioε CALL«á Thσ CAL╠ instructioε i≤ simila≥ t∩ thσ J╨ ì
instructioεá excep⌠á tha⌠ thσ addres≤ oµ thσ nex⌠á sequentia∞á instruction¼ ì
helΣ iε thσ P├ register¼á i≤ PUSHeΣ ont∩ thσ Stack¼á prio≥ t∩ thσ jump« Thσ ì
returε instructioε RET¼á POP≤ thσ returε addres≤ froφ thσ Stack¼á bacδ int∩ ì
thσá P├á register¼á t∩ continuσ wherσ thσ maiε prograφ lef⌠á off«á Iµá thσ ì
numbe≥á oµ PUSHe≤ anΣ CALL≤ iε thσ subroutinσ doe≤ no⌠ equa∞ thσ numbe≥á oµ ì
POP≤á anΣ RETurns¼á obviousl∙ thi≤ wil∞ no⌠ happen«á BotΦá conditiona∞á anΣ ì
unconditiona∞ CALL≤ anΣ RETurn≤ arσ availablσ oε thσ Z80« Al∞ fou≥ type≤ oµ ì
condition≤á alread∙ considereΣ ¿ NC¼á C¼á N┌ anΣ ┌ ⌐ caε bσ useΣ witΦ CALL≤ ì
anΣ RETurns.
Summar∙ - call≤ anΣáreturn≤
CAL╠á NC,nε
RE╘ N├á N∩áCarr∙
á CAL╠á C,nε
RE╘á ├á Carr∙áse⌠
CAL╠ NZ,nε
RE╘ N┌á No⌠áZer∩
á CAL╠á Z,nε
RE╘á ┌ Zer∩ se⌠
Iµá thσ conditioε i≤ no⌠ met¼á thσ prograφ wil∞ no⌠ CAL╠ thσ subroutinσá o≥ ìèRETurε froφ it.
EXAMPL┼ O╞ CALL╙ T╧áSUBROUTIN┼
I⌠á mus⌠ bσ remembereΣ tha⌠ ß subroutinσ ma∙ requirσ thσ usσ oµ ßá registe≥ ì
whosσá content≤ arσ stil∞ requireΣ iε thσ maiε program«á It≤ content≤á mus⌠ ì
thereforσá bσá PUSHeΣ ont∩ thσ stacδ o≥á otherwisσá storeΣá elsewhere¼á anΣ ì
retrieveΣ a⌠ thσ enΣ oµ thσ subroutine« Thσ followinτ examplσ add≤ togethe≥ ì
thσ firs⌠ 3▓ pair≤ oµ memor∙ locations« Thσ resul⌠ i≤ lef⌠ iε HL« Thσ stacδ ì
anΣá thσ H╠ register≤ arσ botΦ useΣ a≤ storagσ inspitσ oµ thσá interferencσ ì
oµ thσ CALL¼ b∙ usinτ thσ E╪ (SP),H╠ instruction:
L─ HL,░
L─ B,3▓
PUS╚ H╠
LOOP▒á L─á E,(HL⌐
IN├ H╠
L─ D,(HL⌐
IN├ H╠
E╪á (SP),H╠
CAL╠ SUB╥
E╪ (SP),H╠
DJN┌ LOOP▒
PO╨ H╠
RE╘
SUB╥ AD─ HL,D┼
RE╘
EXAMPL┼áO╞ CONDITIONA╠ CALL╙
Thi≤á simplσá examplσá count≤ u≡ thσ numbe≥ oµ memor∙ location≤á holdinτá ß ì
numbe≥ abovσ 19▓ anΣ belo≈ 6┤ iε thσ firs⌠ 3▓ memor∙ locations.
L─ HL,░
L─ DE,░
L─ B,3▓
LOO╨ L─ A,(HL⌐
C╨ 19│
CAL╠ NC,ABOV┼
C╨á 6┤
CAL╠ C,BELO╫
IN├ H╠
DJN┌ LOO╨
RE╘
ABOV┼ IN├ ┼
RE╘
BELO╫áIN├ á─
RE╘
BINAR┘ NOTATIO╬
Iµ wσ werσ t∩ takσ thσ to≡ ofµ ß Z8░ chi≡ and¼ usinτ ß powerfu∞ microscope¼ ì
looδ a⌠ ß register¼á wσ woulΣ seσ tha⌠ i⌠ consist≤ oµ ╕ cells«á Thesσ cell≤ ìèarσ capablσ oµ beinτ switcheΣ betweeε tw∩ differen⌠ states«á Conventionall∙ ì
wσ designatσ onσ statσ a≤ "1ó anΣ thσ othe≥ a≤ "0"«á Thσ patterε oµ 1'≤ anΣ ì
0'≤ coulΣ bσ 1011100░ say« Ho≈ d∩ wσ interpre⌠ thi≤ pattern┐ Thσ answe≥ is¼ ì
anywa∙ wσ like« Iε thi≤ lessoε wσ sho≈ tha⌠ thi≤ patterε coulΣ bσ 184,-72¼ ì
B8╚á anΣá eveε C╨ B«á Thσ onl∙ onσ thσ processo≥ ha≤ buil⌠ int∩ i⌠á i≤á thσ ì
latter«á EacΦ digi⌠ iε ß numbe≥ caε bσ considereΣ t∩ havσ ß weighting«á Fo≥ ì
decima∞ number≤ thesσ weighting≤ arσ Digi⌠ -
│ ▓ ▒ ░
100░ 10░ 1░ ▒
sincσá eacΦá digi⌠á caε havσ onσ oµ teε states¼á designateΣá ░á - 9«á Iεá ß ì
registe≥ eacΦ digi⌠ o≥ bi⌠ ha≤ onl∙ tw∩ states«á Thereforσ wσ caε interpre⌠ ì
thσ digit≤ a≤ havinτ weighting≤ oµ bi⌠ -
╖ ╢ ╡ ┤ │ ▓ ▒ ░
12╕á 6┤ 3▓á 1╢ ╕ ┤ ▓ ▒
Takinτá ou≥ numbe≥ 1011100░ fo≥ examplσ anΣ notinτ tha⌠ bit≤ tha⌠á arσá "0ó ì
contributσá nothinτá t∩ thσ number¼á thσ decima∞ equivalen⌠ oµ 1011100░á i≤ ì
giveε b∙ -
128+32+16+8=184
Thσ maximuφ numbe≥ tha⌠ caε bσ helΣ iε aε ╕ bi⌠ registe≥ i≤ -
ì
128+64+32+16+8+4+2+1=25╡
Thi≤á i≤á thσá numbe≥á wσá originall∙á assumeΣá a⌠á thσá beginninτá oµá ou≥ ì
discussion«á Jus⌠á a≤á wσ adΣ tw∩ decima∞ number≤á together¼á carryinτá onσ ì
forwarΣ iµ thσ suφ oµ tw∩ digit≤ i≤ greate≥ thaε 9¼á wσ caε adΣ tw∩á binar∙ ì
numbers« Iµ thσ suφ i≤ abovσ one¼ ß onσ i≤ carrieΣ forward« ie.-
░ ▒ ▒ ░ ▒ ▒ ▒ ░
½á ░á░á▒á░ ░ ▒ ░ ▒
------------------
give≤ ▒ ░ ░ ▒ ░ ░ ▒ ▒
Simila≥ wσ caε perforφ subtraction« i.e.
░ ▒ ▒ ░ ░á▒á▒á░
- ░á░á▒á░ ▒ ▒ ░ ▒
-------------------
give≤ ░ ░ ▒ ▒ ▒ ░ ░ 1
EXAMPLE╙áO╞áBINAR┘ NOTATIO╬
Somσá assembler≤á havσ onσ instructioε no⌠ normall∙ founΣ iεá most¼á namel∙ ì
BIN«á Thσ assemble≥ allocate≤ onσ memor∙ locatioε t∩ thσ line¼á whicΦ woulΣ ì
normall∙ bσ labelled«á I⌠ constantl∙ display≤ thi≤ locatioε iε binar∙ form« ì
Thσá numbe≥ afte≥ BI╬ i≤ thσ numbe≥ initiall∙ inserteΣ int∩á thσá location« ì
Afte≥ goinτ througΦ thσ followinτ examplσ tr∙ modifyinτ thσ displayinτ oµ ì
STOR┼ iε examplσ 11B.
L─ HL,STOR┼
LOO╨ DE├ (HL⌐
J╥ NZ,LOO╨
L─ A,(NUM1⌐è L─ HL,NUM▓
AD─ A,(HL⌐
L─ (ANS),┴
RE╘
STOR┼áBI╬á 1╡
NUM▒ BI╬ 8▒
NUM▓á BI╬á 9╡
AN╙á BI╬á ░
HEXADECIMA╠áNOTATIO╬
Binar∙á number≤ arσ to∩ cumbersomσ anΣ decima∞ to∩ inconvenien⌠ t∩á displa∙ ì
multiplσá registe≥ numbers«á ┴ methoΣ oµ presentinτ binar∙ number≤ ha≤ beeε ì
developeΣ t∩ ge⌠ rounΣ thesσ problems«á InsteaΣ oµ basinτ thσ numbe≥ oεá 1░ ì
a≤ iε decima∞ o≥ ▓ a≤ iε binary¼á wσ basσ i⌠ oε 16«á Thi≤ numberinτ systeφ ì
i≤á calleΣá Hexadecimal«á Wσ requirσ 1╢ differen⌠ symbol≤ t∩á represen⌠á ß ì
digit«á 0-╣á give≤ u≤ thσ firs⌠ 1░ anΣ A-╞ thσ fina∞ 6«á ┴ lis⌠ oµ decimal¼ ì
binary¼ anΣ hexadecima∞ equivalent≤ arσ giveε below:-
Decima∞ Binar∙á Hexadecima∞
á ░ 000░á ░
á ▒ 000▒ ▒
▓á 001░á ▓
│á 001▒á │
á ┤ 010░á ┤
á ╡á 010▒ ╡
áá ╢á 011░á ╢
á ╖á 011▒á ╖
áá ╕ 100░á ╕
á ╣ 100▒ ╣
1░á 101░á ┴
1▒á 101▒á ┬
á 1▓ 110░á ├
á 1│á 110▒ ─
1┤ 111░ ┼
1╡ 111▒ F
Al∞á 1╢ state≤ oµ thσ ┤ binar∙ bit≤ arσ covereΣ b∙ 0-F«á Hencσ onl∙ ▓á hex-ì
adecima∞ digit≤ arσ requireΣ t∩ displa∙ thσ content≤ oµ aε ╕ bi⌠á register« ì
Ou≥ examplσ -
1011100░áá divide≤áu≡áinto 101▒á100░á o≥áB╕áHex«
┴ doublσ registe≥ holdinτ sa∙ 1100100▒ 1011100░ wil∞ bσ representeΣ b∙ C9B╕ ì
hex«á Conversioεá oµá ßá he° numbe≥ t∩ it≤ decima∞ equivalen⌠á follow≤á thσ ì
standarΣ calculation« i.e.
á B╕á he°á ╜ (┬ hex) ¬ 16 ½á(8) ¬á▒
á ╜ 11*16 + 8
= 18┤
Alway≤á remembe≥á tha⌠ ß he° numbe≥ ha≤ ß basσ oµá 1╢á decimal¼á ßá decima∞ ì
numbe≥ ha≤ ß basσ oµ 1░ anΣ ß binar∙ numbe≥ ß basσ oµ 2.
EXAMPLE╙áO╞áHEXADECIMA╠ NOTATIO╬
No≈á tha⌠ he° notatioε ha≤ beeε introduceΣ wσ caε discus≤ ho≈ thσá compute≥ ì
store≤ program≤ iε morσ detail«á A≤ alread∙ mentioned¼á i⌠ storeΣ memor∙ a≤ ìènumbers«á Somσá instruction≤ onl∙ requirσ ß singlσ number¼á other≤á requirσ ì
more.
L─ A,25╚
AD─ A,┴
DA┴
L─ HL,4589╚
L─ DE,3812╚
L─ A,╠
SU┬ ┼
DA┴
L─ L,┴
L─ A,╚
SB├ A,─
DA┴
L─ H,┴
RE╘
BINAR┘ CODE─áDECIMA╠áNOTATIO╬
Wσá woulΣ stil∞ likσ t∩ bσ ablσ t∩ perforφ calculation≤ oε decima∞á number≤ ì
withou⌠á havinτ t∩ conver⌠ t∩ binar∙ o≥ hexadecima∞ form«á Hexidecima∞ forφ ì
hold≤á ßá ke∙á t∩á ß methoΣ oµá achievinτá this«á Thσá he°á digi⌠á require≤ ì
adjustmen⌠ t∩ avoiΣ thσ digit≤ A-F« Addinτ ╢ t∩ thσ digit¼ iµ thesσ symbol≤ ì
appear¼á result≤ iε correc⌠ adjustment« Takσ thσ he° numbe≥ ├ (╜ 1▓ dec.)« ì
Addinτá ╢ give≤ 1╕ decima∞ o≥ 1▓ hex«á Hencσ thσ he° numbe≥ look≤ identica∞ ì
t∩á thσá decima∞á answe≥ required«á EacΦ digi⌠ i≤ helΣ iεá ┤á bit≤á oµá thσ ì
register«á Thesσ ┤ bit≤ arσ calleΣ ß nibble¼ thσ wholσ ╕ bi⌠ worΣ i≤ termeΣ ì
ß byte«á Wh∩ saiΣ programmer≤ havσ n∩ sensσ oµ humour┐ Thi≤ presentatioε i≤ ì
termeΣá Binar∙á CodeΣá Decima∞á o≥ BCD«á Thσá Z8░á accommodate≤á thσá abovσ ì
adjustment¼ witΦ thσ instructioε DAA¼ o≥ Decima∞ Adjus⌠ Accumulator« Thi≤ ì
instructioεá i≤ useΣ afte≥ aε ╕ bi⌠ ADD¼á ADC¼á SUB¼á o≥ SB├ t∩ adjus⌠á thσ ì
Accumulato≥á content≤á b∙ addinτ ╢ t∩ thσ nibble¼á iµ eithe≥ nibblσ iεá thσ ì
answe≥á i≤á abovσ 9«á T∩ perforφ thi≤ operatioε thσ Z8░á use≤á tw∩á furthe≥ ì
flags¼á thσ ╚ flaτ ¿ ß Halµ carr∙ betweeε nibble≤ )¼á anΣ ╬ flaτ (subtrac⌠ ì
instructioε performeΣ last)«á Sincσ thesσ flag≤ canno⌠ bσ testeΣ a≤ par⌠ oµ ì
ß conditiona∞ jum≡ etc« the∙ arσ oµ littlσ use.
EXAMPLE╙ O╞ B.C.D« NOTATIO╬
Thesσ example≤ sho≈ simplσ additioε anΣ subtractioε iε BC─ format« Remembe≥ ì
t∩ kee≡ iε He° displa∙ modσ o≥ thσ illustration≤ wil∞ no⌠ appea≥ iε BCD.
L─ A,25╚
L─ HL,STOR┼
L─ DE,2468╚
IN├ (HL⌐
RE╘
BI╬ 65╚
BI╬ 87╚
BI╬á9A╚
BI╬ DF╚
BI╬áFF╚
BI╬ 64╚
STOR┼ DEF┬ 6┤
èPOSITIV┼ AN─áNEGATIV┼áNUMBE╥ NOTATIO╬
S∩á fa≥ wσ havσ onl∙ deal⌠ witΦ positivσ numbers«á Iµ wσ haΣ takeε ╢ froφ ╡ ì
wσá woulΣá enΣá u≡á witΦá thσ answe≥á 25╡á witΦá carr∙á set«á Therσá i≤á aε ì
interpretatioεá oµá number≤ tha⌠ allow≤ u≤ t∩ conside≥ thi≤ answe≥á a≤á thσ ì
negativσá numbe≥ -1«á Iε thi≤ interpretatioε -▒ mus⌠ equa∞ 25╡ o≥ 11111111¼ ì
o≥á thσá processo≥á woulΣ no⌠ bσ ablσ t∩ takσ ╢ froφ ╡ anΣá ge⌠á thσá righ⌠ ì
answer«á Furthe≥ 5-╖ ╜ -▓ o≥ 25┤ o≥ 11111110«á Bi⌠ 7¼á thσ mos⌠ significan⌠ ì
bit¼á represent≤ thσ sigε ¿ ½ o≥ - ⌐ oµ thσ number«á Wheε bi⌠ ╖ i≤ "1óá thσ ì
numbe≥á i≤á negative¼á anΣá wheεá "0ó thσ numbe≥á i≤á positive«á ┴á usefu∞ ì
operatioε woulΣ bσ t∩ makσ ß positivσ numbe≥ negative«á Changinτ bi⌠ ╖ doe≤ ì
no⌠á d∩á this«á Takσá thσ positivσ numbe≥ ▓ o≥ 0000001░á anΣá it≤á negativσ ì
equivalen⌠á -▓á o≥ 1111111░ fo≥ example«á Invertinτ al∞ bit≤ oµ thσá binar∙ ì
numbe≥ oµ +▓ give≤ 11111101¼á whicΦ i≤ ▒ les≤ thaε tha⌠ fo≥ -2«á Hencσá t∩ ì
makσá ßá positivσ numbe≥ negativσ wσ inver⌠ al∞ it≤ binar∙ bits¼á knowεá a≤ ì
Complimenting¼á anΣ adΣ 1«á Thσ notatioε i≤ generall∙ termeΣ 2≤ complement« ì
i.e.
░ ░ ░ ░ ░ ▒ ░ ▒ = +╡
inver⌠ ▒ ▒ ▒ ▒ ▒ ░ ▒ ░
adΣ ▒ ▒ ▒ ▒ ▒ ▒ ░ ▒ ▒ = -╡
inver⌠á ░á░ ░ ░ ░ ▒ ░ ░
adΣ ▒ ░ ░ ░ ░ ░ ▒ ░ ▒ = +╡
Thσ operatioε luckil∙ als∩ make≤ ß negativσ numbe≥ positive« ┴ ver∙ importì
an⌠á point«á Thσ larges⌠ positivσ numbe≥ wσ caε holΣ iε ß singlσá register¼ ì
usinτá thi≤á notatioε i≤ 0111111▒ o≥ 12╖ anΣ thσá larges⌠á negativσá numbe≥ ì
1000000░á o≥ -128«á Thσ Z8░ ha≤ tw∩ instruction≤ tha⌠ ma∙ bσ useΣ fo≥ thesσ ì
operation≤ CP╠ complement≤ o≥ invert≤ thσ content≤ oµ thσ Accumulator«á NE╟ ì
negates¼áá o≥áá make≤á negative¼áá thσá content≤á oµá thσá Accumulato≥áá b∙ ì
complementinτ anΣ addinτ ▒ iε onσ operation« ┴ Sigε flaτ (S⌐ i≤ provideΣ oε ì
thσá Z80«á I⌠á duplicate≤á thσá sigε ¿ bi⌠ ╖ ⌐á oµá thσá answe≥á afte≥á an∙ ì
arithmetiπá operatioεá oεá thσá Accumulator«á Thσ sigε flaτ i≤á "0óá fo≥á ß ì
positivσ resul⌠ anΣ "1ó fo≥ ß negativσ result«á Wheε performinτá arithmetiπ ì
operation≤á whicΦ wσ wisΦ t∩ interpre⌠ withiε thσ rangσ -12╕ t∩á +127¼á thσ ì
Carr∙ flaτ n∩ longe≥ signal≤ aε ou⌠ oµ rangσ result«á Howeve≥ anothe≥ flag¼ ì
thσá overflo≈ (P/V⌐ flaτ does«á I⌠ i≤ ß "1ó wheneve≥ thσ answe≥ i≤á outsidσ ì
thσá rangσá -12╕ t∩ +12╖ anΣ "0ó withiε thσ range«á I⌠ i≤á effectivel∙á ß ì
carr∙á int∩á bi⌠á ╖ whicΦ woulΣ makσ thσ sigε bi⌠ incorrect«á Therσá i≤á n∩ ì
reasoε fo≥ stickinτ t∩ ╕ bit≤ usinτ thi≤ method«á S∩ lonτ a≤ thσ numbe≥á oµ ì
bit≤á i≤á sufficien⌠ anΣ thσ mos⌠ significan⌠ bi⌠ i≤ takeε a≤ thσ sigεá bi⌠ ì
an∙á sizσá positivσ o≥ negativσ numbe≥ caεá bσá represented«á Performinτá ß ì
simila≥á calculatioεá t∩á thσ abovσ wσ caε sho≈ tha⌠ ßá registe≥á pai≥á caε ì
represen⌠á ß numbe≥ iε thσ rangσ +3276╖ t∩ -32768«á Thσ Sigε anΣá overflo≈ ì
flag≤á arσ als∩ operativσ afte≥ AD├ anΣ SB├ instructioε oε thσ H╠ register« ì
I⌠á reflect≤á thσ 15tΦ bi⌠ (o≥ bi⌠ ╖ oµ ╚ register)«á I⌠á i≤á importan⌠á t∩ ì
remembe≥á tha⌠á thσá Zero¼á Carry¼á Sign¼á anΣ overflo≈á flag≤á arσá alway≤ ì
operativσá afte≥á aεá ╕ bi⌠ arithmetiπ instructioε o≥ ßá 1╢á bi⌠á additioε ì
involvinτ thσ Carry«á You≥ interpretatioε oµ thσ resul⌠ determine≤ iε whicΦ ì
flag(s⌐ yo⌡ shoulΣ bσ interesteΣ in.
EXAMPLE╙ O╞á+V┼áAN─á-V┼áNOTATIO╬
AlthougΦá thesσá example≤á appea≥ t∩ bσ al∞ positive¼á the∙ caεá bσá vieweΣ ì
equall∙á a≤á negativσá wherσ appropriatσ anΣ thσ Sigεá anΣá overflo≈á flag≤ ìèobserveΣ operating«á Remembe≥ ß numbe≥ abovσ 12╕ i≤ negative« Sincσ al∞ thσ ì
negativσá number≤ iε thσ example≤ arσ small¼á the∙ caε bσ seeε quickl∙á anΣ ì
simpl∙á bσá converteΣá b∙ subtractinτ thσá numbe≥á froφá 256«á i.e«á -▓á i≤ ì
equivalen⌠ t∩ 25┤ etc.
L─ A,25┤
NE╟
NE╟
AD─ A,▓
IN├ ┴á
L─á HL,▓
L─ DE,FFFE╚
AD─áHL,D┼
CP╠ L─ HL,STOR┼
L─ (HL),7F╚
IN├ (HL)
RE╘
STOR┼ BI╬ 0