L06_ControlStructures

14
CONTROL STRUCTURES The Processor Status and the FLAGS Register The circuits in the CPU can perform simple decision-making based on the current state of the processor. For the 8086/8088 processors the processor state is implemented as nine bits called flags in the Flags register. !ach decision made b" the 8086/8088 CPU is based on the #alues of these flags. The flags are classified as either status flags or control flags. There are 6 status flags$ Carr" flag %CF& Parit" flag %PF& 'u(iliar" carr" flag %'F& )ero flag %)F& *ign flag %*F& and +#erflo, flag %+F&. There are control flags$ Trap flag %TF& nterrupt flag %F& and irection flag %F&. 1 2 3 0 4 8 5 6 1 2 3 0 +F F F TF *F )F 'F PF CF The Flags register: Bits 8, 9, and 10 are the Control flags. The *tatus flags reflect the result of some instructions e(ecuted b" the processor. For e(ample ,hen a subtraction operation results in a ero the )ero flag %)F& is set to %true&. The Control flags enable or disable certain operations of the processor. For e(ample if the nterrupt flag %F& is cleared to 0 inputs from the ke"board are ignored b" the processor . 7ost 8086/8088 instructions can be classified into three categories$ %i& nstructions that modif" one or more *tatus flag s. %*tatus flags modif" ing instructions&. %ii& nstructions that modif" one or more C ontrol flags. %Control flags modif" ing instructions&. %iii& nstructions that do not modif " an" f lag. FLOW CONTROL INSTRUCTIONS The 7P %ump& C'99 :!T and :!T instructions transfer control unconditionall" to another part of the  program. The conditional ;ump instructions e(cep t C<) and !C<) transfer control to another part of the program each depending on one or more *tatus flag settings. These instructions are of the form con diti on, ,here condition  is represented b" one t,o or th ree letters. C<) and !C<) transfer control to another part of the program if C< = 0 and !C< = 0 respecti#el". The 9++P in structi on decr ements C< and transf er control to the beginning of its loop if C<  0. f C< = 0  befor e the 9++P instruction it is decremented to - at the end of the first iteration of the loop. This - is treated as the unsigned number 6111 thus the loop ,ill iterate 6116 times. The conditional loop instructions 9++P! and 9++P) ,hich are e>ui#alent decrement C< and transfer control to the beginning of their loops if C< > 0 and )F = . f C<  0 before the loop the loop is e(ecuted once. The conditional loop instructions 9++P?! and 9++P?) ,hich are e>ui#alent decrement C< and transfer control to the beginning of their loops if C< > 0 and )F = 0. f C<  0 before the loop the loop is e(ecuted once.

Transcript of L06_ControlStructures

Page 1: L06_ControlStructures

8/10/2019 L06_ControlStructures

http://slidepdf.com/reader/full/l06controlstructures 1/13

CONTROL STRUCTURES

The Processor Status and the FLAGS Register

The circuits in the CPU can perform simple decision-making based on the current state of the processor. For the8086/8088 processors the processor state is implemented as nine bits called flags in the Flags register. !achdecision made b" the 8086/8088 CPU is based on the #alues of these flags.

The flags are classified as either status flags or control flags. There are 6 status flags$ Carr" flag %CF& Parit" flag%PF& 'u(iliar" carr" flag %'F& )ero flag %)F& *ign flag %*F& and +#erflo, flag %+F&. There are control flags$Trap flag %TF& nterrupt flag %F& and irection flag %F&.

1 2 3 0 4 8 5 6 1 2 3 0

+F F F TF *F )F 'F PF CF

The Flags register: Bits 8, 9, and 10 are the Control flags.

The *tatus flags reflect the result of some instructions e(ecuted b" the processor. For e(ample ,hen a subtractionoperation results in a ero the )ero flag %)F& is set to %true&. The Control flags enable or disable certainoperations of the processor. For e(ample if the nterrupt flag %F& is cleared to 0 inputs from the ke"board are

ignored b" the processor.

7ost 8086/8088 instructions can be classified into three categories$%i& nstructions that modif" one or more *tatus flags. %*tatus flags modif"ing instructions&.%ii& nstructions that modif" one or more Control flags. %Control flags modif"ing instructions&.%iii& nstructions that do not modif" an" flag.

FLOW CONTROL INSTRUCTIONS

• The 7P %ump& C'99 :!T and :!T instructions transfer control unconditionall" to another part of the

 program.

• The conditional ;ump instructions e(cept C<) and !C<) transfer control to another part of the program

each depending on one or more *tatus flag settings. These instructions are of the form condition, ,here

condition is represented b" one t,o or three letters.• C<) and !C<) transfer control to another part of the program if C< = 0 and !C< = 0 respecti#el".

• The 9++P instruction decrements C< and transfer control to the beginning of its loop if C< ≠ 0. f C< = 0

 before the 9++P instruction it is decremented to - at the end of the first iteration of the loop. This - istreated as the unsigned number 6111 thus the loop ,ill iterate 6116 times.

• The conditional loop instructions 9++P! and 9++P) ,hich are e>ui#alent decrement C< and transfer 

control to the beginning of their loops if C< > 0 and )F = . f C< ≤ 0 before the loop the loop is e(ecuted

once.

• The conditional loop instructions 9++P?! and 9++P?) ,hich are e>ui#alent decrement C< and transfer 

control to the beginning of their loops if C< > 0 and )F = 0. f C< ≤ 0 before the loop the loop is e(ecuted

once.

Page 2: L06_ControlStructures

8/10/2019 L06_ControlStructures

http://slidepdf.com/reader/full/l06controlstructures 2/13

THE JP INSTRUCTION !Unconditiona" Ju#$%The 7P instruction ,hose s"nta( is$

JP targetunconditionall" transfers control to the target location. There are t,o ma;or categories of 7P instructions$

%i& ntrasegment ;ump$ ' ;ump to a statement in the same code segment.%ii& ntersegment or far ;ump$ ' ;ump to a statement in a different code segment.

ntrasegment ;umps simpl" change the #alue in the P register. ntersegment ;umps change both C* and P.

irect and ndirect ;umps' ;ump can either be direct or indirect. n a direct ;ump the address of the target is obtained from the instructionitself i.e. the operand of the 7P instruction is a label. !(ample$

7P 93 n an indirect ;ump the address of the target is obtained from a 6-bit or a 3-bit #ariable or a general-purposeregister referenced b" the 7P instruction. !(ample$

7P '<

CON&ITIONAL JUP INSTRUCTIONSConditional ;umps are of the general form$  Jcondition  State#entLa'e",here %i& condition is one t,o or three letters %ii& the *tatement9abel must in the current code segment andshould be ,ithin -38 to @35 b"tes from the conditional ;ump instruction.

Ao, the CPU implements a conditional ;ump!(cept for the C<) %ump if the #alue in the C< register is ero& and !C<) %ump if the #alue in !C< register is ero& instruction e#er" conditional ;ump instruction must follo, a status-flag modif"ing instruction either immediatel" or other,ise. t is the settings of the flags b" this status-flag modif"ing instruction to ,hich theconditional ;ump reacts$

Bhen a conditional ;ump is e(ecuted the CPU checks the flags register. f the conditions for the ;ump %e(pressedas one or more status flag settings& are true the CPU ad;usts the P register to point to the destination label so thatthe instruction at this label ,ill be e(ecuted ne(t. f the ;ump condition is false then the P register is not alteredthis means that the ne(t se>uential instruction ,ill be e(ecuted.

Note( The conditiona" )u#$ instructions do not #odi*+ the *"ags, the+ on"+ react to the current *"ag -a"ues.!(ample$ . . .

*UD '< D<) 93 ;ump to 93 if the result is ero.

.

.93(

7aking a conditional ;ump to E;ump to a label outside the range -38 to 35 b"tes

' conditional ;ump cannot ;ump to a label outside the range -38 to @35 b"tes. To o#ercome this change theconditional ;ump to its opposite and then use a 7P instruction to ;ump to the label. !(ample$ *uppose label 93in the follo,ing fragment is outside the range$

. . .*UD '< D<) 93 ;ump to 93 if the result is ero...

93(

3

Page 3: L06_ControlStructures

8/10/2019 L06_ControlStructures

http://slidepdf.com/reader/full/l06controlstructures 3/13

then change the fragment to the follo,ing e>ui#alent fragment$. . .*UD '< D<?) 97P 93

9( ..

.93(  

7'*7 6.0 and abo#e can automate ;ump-e(tending for "ou. f "ou target a conditional ;ump to a label farther than 38 b"tes a,a" 7'*7 re,rites the instruction ,ith an unconditional ;ump ,hich ensures that the ;ump canreach its target.

The co#$arison o* signed nu#'ers and the co#$arison o* unsigned nu#'ers( THE CP

!Co#$are% INSTRUCTION

• ' signed number can be g reater l ess or e>ual to another signed number.

• 'n unsigned number can be a bo#e belo, or e>ual to another unsigned number.

The C7P instruction ,hose s"nta( is$CP O$erand/ 0 O$erand1

compares t,o operands and then sets or clears the follo,ing flags$ 'F CF +F PF and )F. The instruction performs the subtraction$

+perand - +perand3,ithout modif"ing an" of its operands.

 ?ote$

• The t,o operands must be of the same sie e(cept in a comparison of the form$

C7P +perand mmediate mmediate ma" be of a smaller sie than +perand.

• Doth operands ma" not be memor" locations at the same time.

•  ?o operand ma" be a segment register.

• +perand ma" not be an immediate #alue.

Conditional ;umps can be classified into three$ %& *igned ;umps %3& Unsigned ;umps and %& *ingle flag ;umps.

*G?! U7P* U?*G?! U7P*

condition e>ui#alent condition mnemonic ;ump condition mnemonic ;ump condition

> not ≤ G ?9! )F = 0 and *F = +F ' ?D! CF = 0 and )F = 0

≥ not < G! ?9 *F = +F '! ?D CF = 0

< not ≥ 9 ?G! *F ≠ +F D ?'! CF =

≤ not > 9! ?G )F = or *F ≠ +F D! ?' CF = or )F =

*ingle flag ;umps

mnemonic ;ump condition description

! ) )F = ump if e>ual

?! ?) )F = 0 ump if not e>ual

C CF = ump if carr"

?C CF = 0 ump if no carr"

+ +F = ump if o#erflo,

?+ +F = 0 ump if no o#erflo,

* *F = ump if sign negati#e

?* *F = 0 ump if sign is not negati#e

P P! PF = ump if parit" e#en i.e. if there is an e#en number of bits in the result.

?P P+ PF = 0 ump if parit" odd i.e. if there is an odd number of bits in the result.

Page 4: L06_ControlStructures

8/10/2019 L06_ControlStructures

http://slidepdf.com/reader/full/l06controlstructures 4/13

!(ample$ Brite a loop to displa"$ ''''''*olution$ . . .

7+H C< 67+H 'A 03A7+H 9 I'J

  9$ ?T 3A!C C<

?) 9. . .

an alternati#e solution is$. . .7+H C< 67+H 'A 03A7+H 9 I'J

  9$ ?T 3A!C C<C<) 937P 9

  93$. . .

!(ample$ Brite a loop to displa"$ 'DC!FG*olution$ . . .

7+H D9 57+H 'A 03A7+H 9 I'J

  *T':T$ ?T 3A?C 9!C D9?) *T':T. . .

an alternati#e solution is$. . .

7+H 'A 03A7+H 9 I'J

  9'D!9$ ?T 3A?C 9C7P 9 IGJD! 9'D!9. . .

!(ample$ Brite a loop to displa"$ Z

Y

X

W

V

U

*olution$7+H 'A 03A7+H D9 I)J

93$ 7+H 9 D9?T 3A7+H 9 0A generate C: and 9F?T 3A 7+H 9 0'A ?T 3A !C D9C7P D9 IUJ'! 93

2

Page 5: L06_ControlStructures

8/10/2019 L06_ControlStructures

http://slidepdf.com/reader/full/l06controlstructures 5/13

!(ample$ Brite a procedure ,hich sets the Carr" Flag if the '9 register contains an '*C digit i.e. I0J IJ I3J . . . or I4J other,ise it clears the Carr" Flag.*olution$ The state of the Carr" Flag follo,ing the e(ecution of the instruction$

C7P estination *ourceis one of$

*tate of Carr" Flag

estination >  *ource 0

estination = *ource 0

estination <  *ource

Dased on the abo#e table the re>uired procedure is$

'9K*KGTL P:+C

C7P '9 0A CF = if '9 <  I0J other,ise CF = 0

C7C CF = 0 if '9 <  I0J other,ise CF =

?C +?! ump to +?! if CF = 0

C7P '9 'A CF = if '9 <  %I4J @ & other,ise CF = 0

+?!$ :!T'9K*KGTL !?P

' t"pical call to the abo#e procedure is$C'99 '9K*KGTLC 92 ump to 92 if '9 contains an '*C digit..  %'ction to be taken if '9 does not contain an '*C digit&.7P 91

  92$ .. !'ction to be taken if '9 contains an '*C digit&

  91$

IPLEENTATION OF HIGH2LE3EL LANGUAGE CONTROL STRUCTURES ?ote$ n ,hat follo,s it is assumed that +P +P and +P3 are signed operands such that in an" comparison there

is no assembl" error and statement'  is the assembl" language translation of statement .

. F-!?F *T'T!7!?T

%a& F%+P = +P3&TA!?  statement

  statement3!?F

  can be translated to$

  C7P +P +P3  ! ?!<TK9'D!9

  7P !?KF ?!<TK9'D!9$  statementJ  statement3J!?KF$

ho,e#er if the condition is re#ersed a better solution is obtained$C7P +P +P3?! !?KF  statementJ  statement3J!?KF$

1

Page 6: L06_ControlStructures

8/10/2019 L06_ControlStructures

http://slidepdf.com/reader/full/l06controlstructures 6/13

%b& F%%'9 M +P& +: %'9 M= 0P3&&TA!?  statement  !?F

can be translated to$

C7P '9 +PG 9C7P '9 +P3G! 97P 93

  9$ statementJ  93$

%c& F%%'9 M +P& '? %'9 M= +P3&&TA!?statementJ

  !?F

  can be translated to$  C7P '9 +P  G 9  7P !?KF

  9$ C7P '9 +P3  G! 93  7P !?KF  93$ statementJ  !?KF$

ho,e#er a better solution is obtained b" re#ersing each of the conditions and ;umping to an !?KF label,hen an" re#ersed condition is true$

C7P '9 +P?G !?KF

C7P '9 +P3?G! !?KFstatementJ

  !?KF$

6

Page 7: L06_ControlStructures

8/10/2019 L06_ControlStructures

http://slidepdf.com/reader/full/l06controlstructures 7/13

3. F-!9*!-!?F *T'T!7!?T

F%+P N= +P3&TA!?statementstatement3

!9*!statement

!?F

can be translated to$

C7P +P +P39! 9statementJ7P !?KF

9$ statementJstatement3J

!?KF$

ho,e#er if the condition is re#ersed the follo,ing solution is obtained$

C7P +P +P3?9! 9statementJstatement3J7P !?KF

9$ statementJ!?KF$

. BA9! 9++P %,hile loop condition is true&

BA9!%+P N +P3&+  statement  statement3

!?BA9!

can be translated to$

*T':T$ C7P +P +P3  9 BA9!KD+O  7P !?KBA9!

BA9!KD+O$statementJstatement3J7P *T':T

!?KBA9!$

  ho,e#er a better solution is obtained b" re#ersing the condition and e(iting the loop ,hen the re#ersedcondition becomes true$

  *T':T$ C7P +P +P3  ?9 !?KBA9!statementJstatement3J7P *T':T

!?KBA9!$

5

Page 8: L06_ControlStructures

8/10/2019 L06_ControlStructures

http://slidepdf.com/reader/full/l06controlstructures 8/13

2. +-BA9! %do ,hile loop condition is true&

+  statement  statement3

BA9!%+P N +P3&

can be translated to$

*T':T$ statementJstatement3JC7P +P +P39 *T':T

1. :!P!'T- U?T9 9++P %:epeat until the loop condition becomes true&

 :!P!'T  statement  statement3  statement

 U?T9%+P = +P3& +: %+P M 0P&

can be translated to$

*:!P!'T(  statementJ  statement3J  statementJ  C7P +P +P3  ! !?K:!P!'T  C7P +P +P  G !?K:!P!'T  7P *:!P!'T

!?K:!P!'T(

ho,e#er a better solution is obtained b" re#ersing the last condition$

*:!P!'T(  statementJ  statement3J  statementJ  C7P +P +P3  ! !?K:!P!'T  C7P +P +P  ?G *:!P!'T

!?K:!P!'T(

8

Page 9: L06_ControlStructures

8/10/2019 L06_ControlStructures

http://slidepdf.com/reader/full/l06controlstructures 9/13

6. F+: 9++P

for% i = i N= 20 i@@ & 

  statement   statement3

  statement   Q

can be translated to$

 7+H D9 *T':T$ C7P D9 20

 ' !?KF+: statementJ

  statement3J  statementJ  ?C D9  7P *T':T

!?KF+:$

 ?ote$ Be assume that D9 is not modified in an" of the statements$ statementJ statement3J and statementJ

5. TA! *BTCA *T'T!7!?T

s,itch%+P& 

  case const( statement   break

  case const3(  statement3   break . . .

  case const?$ statement?

  break default(   statement?@ Q

can be translated to$

C7P +P const! 9C7P +P const3! 93. . .C7P +P const?! 9?

statement?@J7P !?K*BTCA9$ statementJ

7P !?K*BTCA93$ statement3J

  7P !?K*BTCA  . . .

9?$ statement?J!?K*BTCA$

4

Page 10: L06_ControlStructures

8/10/2019 L06_ControlStructures

http://slidepdf.com/reader/full/l06controlstructures 10/13

THE LOOP INSTRUCTIONThe s"nta( of the 9++P instruction is$

LOOP  StatementLabel ,here StatementLabel is the label of a statement in the current code segment that is ,ithin -38 b"tes from theloop instruction. %?ote$ The label ma" be ,ithin @35 b"tes from the 9++P instruction but although such loopsare s"ntacticall" correct the" are meaningless the bod" of the loop is not e(ecuted&.

 ?ote$ f the label is outside the range the assembler generates the error$ E;ump destination too far. Unlike aconditional ;ump the range of a loop is not automaticall" e(tended.

The 9++P instruction decrements C< and transfer control to the beginning of its loop if C< ≠ 0 other,ise the

ne(t se>uential instruction in the program is e(ecuted. f C< = 0 before the loop it is decremented to - at the endof the first iteration of the loop. This - is treated as the unsigned number 6111 thus the loop ,ill iterate 6116times. *imilarl" if C< = -n before the loop the loop ,ill iterate m @ times ,here m is the 3Js complement of -n.

The 9++P instruction is used to implement a for-loop that 4i"" e5ecute at "east once  and in ,hich the loop inde(decrements b" one in each loop iteration and the loop terminates ,hen the loop inde( becomes ero. For e(amplethe loop$

*or! 6 7 89 , 6 : 9 , 622%

  ;  state#ent/ ,  state#ent1 ,  <can be implemented as$

O3 C= 0 89START>FOR( state#ent/?

state#ent1?LOOP START>FOR 

Note( The -a"ue o* C= #ust not 'e #odi*ied0 4ithout 'eing sa-ed and restored0 4ithin the "oo$.

f the number of iterations of the 9++P instruction is computed d"namicall" it is better to check that that number is positi#e before the loop is e(ecuted other,ise the loop ,ill be e(ecuted man" times$

7+H C< ?U7D!: C7P C< 09! !?KF+: 

*T':TKF+: (. . .9++P *T':TKF+: 

!?KF+:$

The 9++P instruction can also be used to implement for-loops in ,hich the loop inde( is incremented if a general purpose register of an appropriate sie other than C< or a #ariable of an appropriate sie is used as the loopinde(. For e(ample the loop$  for% i = 1 i N= 00 i@@ &

 

  statement   statement3   Q

can be implemented as$7+H D9 17+H C< 46

  9$ statementJstatement3J?C D99++P 9

assuming that %a& D9 and C< are not modified b" statementJ and statement3J and %b& D9 is used in at least oneof the statements.

0

Page 11: L06_ControlStructures

8/10/2019 L06_ControlStructures

http://slidepdf.com/reader/full/l06controlstructures 11/13

Nested LOOP instructions9++P instructions can be nested pro#ided the C< register is sa#ed before entering the inner loop and thenrestored ,hen e(iting the inner loop. For e(ample the nested for-loops$

for% i = 20 i M 0 i-- &    statement

  statement3   for% k = 0 k M 0 k-- &    statement

  statement2   Q  statement1   Q

can be implemented as$

7+H C< 20+UT!:KF+:$ statementJ

statement3JPU*A C<7+H C< 0

??!:KF+:$ statementJstatement2J9++P ??!:KF+: P+P C<statement1J9++P +UT!:KF+: 

!(ample$ Brite nested 9++P instructions to displa" the pattern$

'(((((((((('(((((((((('(((((((((('((((((((((

*olution$ . . .7+H 'A 03A7+H C< 2

  9$ 7+H 9 I'J?T 3APU*A C<7+H C< 07+H 9 I(J

  93$ ?T 3A9++P 93P+P C<9++P 9. . .

THE LOOPE !Loo$ 4hi"e E@ua"% OR LOOP !Loo$ 4hi"e Bero% INSTRUCTION9++P! and 9++P) are different mnemonics for the same instruction. The s"nta( of the 9++P! instruction is$

LOOPE  StatementLabel ,here StatementLabel is the label of a statement in the current code segment that is ,ithin -38 b"tes from theloop instruction. %?ote$ The label ma" be ,ithin @35 b"tes from the 9++P! instruction but although such loopsare s"ntacticall" correct the" are meaningless the bod" of the loop is not e(ecuted&.

 ?ote$ f the label is outside the range the assembler generates the error$ E;ump destination too far. Unlike aconditional ;ump the range of a conditional loop is not automaticall" e(tended.

The 9++P! instruction decrements C< and transfer control to the beginning of its loop if C< >  0 and )F =

other,ise the ne(t se>uential instruction in the program is e(ecuted. I* C= 9 'e*ore the "oo$0 the "oo$ is

e5ecuted once.

The 9++P! instruction is used to implement for-loops in ,hich the e(istence of an e>ual condition at the end of the loop is used to repeat the loop i.e. loops of the form$

Page 12: L06_ControlStructures

8/10/2019 L06_ControlStructures

http://slidepdf.com/reader/full/l06controlstructures 12/13

for% k = 10 k M 0 k--& 

  statement   statement3

  if%+P +P3&

  break   Q

the abo#e for-loop can be implemented as$

7+H C< 10*T':TKF+:$ statementJ

statement3JC7P +P +P39++P! *T':TKF+: 

Note( A *"ag #odi*+ing instruction shou"d not a$$ear 'et4een the CP 4hich deter#ines "oo$ continuationor ter#ination and the conditiona" "oo$ instruction, other4ise the "ogic o* the "oo$ 4i"" change.

!(ample$ Brite a loop that reads 6 characters if each is IOJ other,ise the loop terminates. The count of the

number of characters read must be left in the D9 register.

*olution$ 7+H D9 -7+H 'A 0A7+H C< 6

  *T':T$ ?C D9 This flag modif"ing instruction cannot appear bet,een C7P and 9++P!?T 3AC7P '9 IOJ9++P! *T':T?) 9?C D9

9$

THE LOOPNE !Loo$ 4hi"e Not E@ua"% OR LOOPN !Loo$ 4hi"e not Bero%INSTRUCTION

9++P?! and 9++P?) are different mnemonics for the same instruction. The s"nta( of the 9++P?! instructionis$

LOOPNE  StatementLabel ,here StatementLabel is the label of a statement in the current code segment that is ,ithin -38 b"tes from theloop instruction. %?ote$ The label ma" be ,ithin @35 b"tes from the 9++P?! instruction but although suchloops are s"ntacticall" correct the" are meaningless the bod" of the loop is not e(ecuted&.

 ?ote$ f the label is outside the range the assembler generates the error$ E;ump destination too far. Unlike aconditional ;ump the range of a conditional loop is not automaticall" e(tended.

The 9++P?! instruction decrements C< and transfer control to the beginning of its loop if C< > 0 and )F = 0

other,ise the ne(t se>uential instruction in the program is e(ecuted. I* C= 9 'e*ore the "oo$0 the "oo$ is

e5ecuted once.

3

Page 13: L06_ControlStructures

8/10/2019 L06_ControlStructures

http://slidepdf.com/reader/full/l06controlstructures 13/13

The 9++P?! instruction is used to implement for-loops in ,hich the e(istence of a not e>ual condition at the endof the loop is used to repeat the loop i.e. loops of the form$

  for% k = 10 k M 0 k--& 

  statement   statement3

  if%+P 7 +P3&  break

  Q

the abo#e for-loop can be implemented as$

7+H C< 10*T':TKF+:$ statementJ

statement3JC7P +P +P39++P?! *T':TKF+: 

Note( A *"ag #odi*+ing instruction shou"d not a$$ear 'et4een the CP 4hich deter#ines "oo$ continuationor ter#ination and the conditiona" "oo$ instruction, other4ise the "ogic o* the "oo$ 4i"" change.

!(ample$ Brite a loop that reads 6 characters if each is not IOJ other,ise the loop terminates. The count of thenumber of characters read must be left in the D9 register.

*olution$ 7+H D9 -7+H 'A 0A7+H C< 6

  *T':T$ ?C D9 This flag modif"ing instruction cannot appear bet,een C7P and 9++P?!?T 3AC7P '9 IOJ9++P?! *T':T) 9?C D9

9$

Anon+#ous La'e"sBhen "ou code ;umps and loops in assembl" language "ou must in#ent man" label names. +ne alternati#e to

continuall" thinking up ne, label names is to use anon"mous labels ,hich "ou can use an",here in "our

 program. ut 'ecause anon+#ous "a'e"s do not $ro-ide #eaning*u" na#es0 the+ are 'est used *or )u#$ing

o-er on"+ a *e4 "ines o* code. Dou shou"d #ar6 #a)or di-isions o* a $rogra# 4ith actua" na#ed "a'e"s.

Use t,o at signs %RR& follo,ed b" a colon %$& as an anon"mous label. To ;ump to the nearest preceding

anon"mous label use  %back& in the ;ump instructionJs operand field to ;ump to the nearest follo,ing

anon"mous label use F %for,ard& in the operand field.

The ;ump in the follo,ing e(ample targets an anon"mous label$

  JGE F  .  .  .(

The ite#s @B  and @F a"4a+s re*er to the nearest occurrences o* (0 so there is ne-er an+ con*"ict

'et4een di**erent anon+#ous "a'e"s.