Download presentation
Presentation is loading. Please wait.
Published byDeirdre Anthony Modified over 9 years ago
1
ACOE251Sofware Constructs1 Software Constructs What they are …..
2
ACOE251Sofware Constructs2 The “IF THEN ….” Construct The “IF THEN” construct is used when a sequence of instructions must be executed only if a condition is satisfied. Pseudo-Code: IF (Condition = True) THEN BEGIN Statement1......... StatementN END Assembly: CMP AL,Condition JNE Cont Statement1......... StatementN Cont:.......... Flowchart
3
ACOE251Sofware Constructs3 IF THEN :- Example 1 Write a procedure that increments the content of AH only if the content of AL is equal to 50H.
4
ACOE251Sofware Constructs4 IF THEN :- Example 2 Write a procedure that adds BL to AL. If the sum is greater than 255 then increment the contents of AH.
5
ACOE251Sofware Constructs5 The “IF THEN…ELSE” Construct The “IF THEN …ELSE” construct is used when a sequence of instructions must be executed only if a condition is satisfied, while another sequence must be executed if the condition is not satisfied.. Pseudo-Code: IF (Condition = True) THEN BEGIN Statement1; Statement2; END ELSE BEGIN Statement1; Statement2; END Assembly: CMP AL,Contition JNE No Yes_Statements JMP Cont No:No_Statements Cont:.......... Flowchart
6
ACOE251Sofware Constructs6 CASE Structure CASE structure is a multi-way branch instruction: CASE expression Values_1: Statements to perform if expression = values_1 Values_2: Statements to perform if expression = values_2. Values_N: Statements to perform if expression = values N END_CASE
7
ACOE251Sofware Constructs7 Conversion of Case Structure Consider: CASE AX 1 or 2: Add 1 to BX 3 or 4: Add 1 to CX End_CASE
8
ACOE251Sofware Constructs8 Conversion of Case Structure (cont’d) FIRST THOUGHTBETTER CODE ;CASE AX; CASE AX ;1 or 2; 1 or 2CMP AX,1JE ADD_BXCMP AX,2 JE ADD_BXJE ADD_BX ;3 or 4; 3 or 4CMP AX,3 JE ADD_CXJE ADD_CXCMP AX,4 JE ADD_CXJNE END_CASE_AX JMP END_CASE_AX ADD_CX: ADD_BX:INCCX INC BXJMP END_CASE_AX ADD_BX: ADD_CX:INCBX INCCXEND_CASE_AX: END_CASE_AX:
9
ACOE251Sofware Constructs9 Branches with Compound Conditions AND conditions (TRUE IF both conditions are true) How do you implement: IF AX=1 AND BX=1 THEN ADD 1 TO CX END_IF In AL we could code: ;IF AX=1 and BX=1 CMP AX,1 JNE END_IF CMP BX,1 JNE END_IF ;Then add 1 to CX INC CX END_IF:
10
ACOE251Sofware Constructs10 Branches with Comp. Conditions (cont’d) OR conditions (True if either condition is true, false IF both conditions are false) How do you implement: IF AX=1 or BX=1 Then Add 1 to CX END_IF In AL we could code: ; IF AX=1 or BX=1 CMP AX,1 JE ADD_CX CMP BX,1 JNE END_IF ADD_CX: INC CX END_IF:
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.