Software Constructs - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

Software Constructs

Description:

Software Constructs What they are .. – PowerPoint PPT presentation

Number of Views:32
Avg rating:3.0/5.0
Slides: 11
Provided by: CKy4
Category:

less

Transcript and Presenter's Notes

Title: Software Constructs


1
Software Constructs
  • What they are ..

2
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
IF THEN - Example 1
  • Write a procedure that increments the content of
    AH only if the content of AL is equal to 50H.

4
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
The IF THENELSE 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
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
Conversion of Case Structure
  • Consider
  • CASE AX
  • 1 or 2 Add 1 to BX
  • 3 or 4 Add 1 to CX
  • End_CASE

8
Conversion of Case Structure (contd)
  • FIRST THOUGHT BETTER CODE
  • CASE AX CASE AX
  • 1 or 2 1 or 2
  • CMP AX,1 CMP AX,1
  • JE ADD_BX JE ADD_BX
  • CMP AX,2 CMP AX,2
  • JE ADD_BX JE ADD_BX
  • 3 or 4 3 or 4
  • CMP AX,3 CMP AX,3
  • JE ADD_CX JE ADD_CX
  • CMP AX,4 CMP AX,4
  • JE ADD_CX JNE END_CASE_AX
  • JMP END_CASE_AX ADD_CX
  • ADD_BX INC CX
  • INC BX JMP END_CASE_AX ADD_BX
  • ADD_CX INC BX
  • INC CX END_CASE_AX
  • END_CASE_AX

9
Branches with Compound Conditions
  • AND conditions (TRUE IF both conditions are true)
  • How do you implement
  • IF AX1 AND BX1
  • THEN ADD 1 TO CX
  • END_IF
  • In AL we could code
  • IF AX1 and BX1
  • CMP AX,1
  • JNE END_IF
  • CMP BX,1
  • JNE END_IF
  • Then add 1 to CX
  • INC CX
  • END_IF

10
Branches with Comp. Conditions (contd)
  • OR conditions (True if either condition is true,
    false IF both conditions are false)
  • How do you implement
  • IF AX1 or BX1
  • Then Add 1 to CX
  • END_IF
  • In AL we could code
  • IF AX1 or BX1
  • CMP AX,1
  • JE ADD_CX
  • CMP BX,1
  • JNE END_IF
  • ADD_CX
  • INC CX
  • END_IF
Write a Comment
User Comments (0)
About PowerShow.com