1 / 10

Software Constructs

Software Constructs. What they are …. 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:

felix-noble
Download Presentation

Software Constructs

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Software Constructs What they are ….. Sofware Constructs

  2. 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: . . . . . . . . . . The “IF THEN ….” Construct Flowchart Sofware Constructs

  3. Write a procedure that increments the content of AH only if the content of AL is equal to 50H. IF THEN :- Example 1 Sofware Constructs

  4. Write a procedure that adds BL to AL. If the sum is greater than 255 then increment the contents of AH. IF THEN :- Example 2 Sofware Constructs

  5. 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: . . . . . . . . . . The “IF THEN…ELSE” Construct Flowchart Sofware Constructs

  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 Sofware Constructs

  7. Conversion of Case Structure • Consider: CASE AX 1 or 2: Add 1 to BX 3 or 4: Add 1 to CX End_CASE Sofware Constructs

  8. Conversion of Case Structure (cont’d) • FIRST THOUGHTBETTER 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: Sofware Constructs

  9. 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: Sofware Constructs

  10. 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: Sofware Constructs

More Related