1 / 15

Branching Instructions

Branching Instructions. Module M17.2 Section 11.1. Calculating Branching Displacements. Calculating Branching Displacements. Note: Displacement is only 8 bits. Therefore, the program can only branch forward +127 bytes, or backward -128 bytes. But you should NEVER have to to this!.

zubin
Télécharger la présentation

Branching Instructions

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. Branching Instructions Module M17.2 Section 11.1

  2. Calculating Branching Displacements

  3. Calculating Branching Displacements Note: Displacement is only 8 bits. Therefore, the program can only branch forward +127 bytes, or backward -128 bytes.

  4. But you should NEVER have to to this! A possible way to branch conditionally more than +127 or -128 bytes is as follows: Replace JE distant next: --------- with JNE next JMP distant next: ----------

  5. Branching Example 1Branch on Z flag 0000 B9 03 00 LOOP1: MOV CX,3 0003 49 LOOP2: DEC CX 0004 75 FD JNE LOOP2 0006 74 F8 JE LOOP1

  6. Branching Example 2Branch on S flag 0000 B1 7D LOOP1: MOV CL,7DH 0002 FE C1 LOOP2: INC CL 0004 79 FC JNS LOOP2 0006 78 F8 JS LOOP1

  7. Branching Example 3Branch on C flag 0000 B0 2E LOOP1: MOV AL,2EH 0002 FE C8 LOOP2: DEC AL 0004 3C 2B CMP AL,2BH 0006 73 FA JNB LOOP2 0008 72 F6 JC LOOP1

  8. Problem: Go through a loop 20010 (C8H) times Trial solution: MOV CL,0 ;set CL = 0 LOOP: INC CL ;increment CL CMP CL,0C8H ;compare CL toC8H JL LOOP ;loop if CL < 200 How many times is the statement INC CL executed?

  9. Same as: 0000 B9 03 00 L1: MOV CX,3 0003 E2 FE L2: LOOP L2 0005 EB F9 JMP L1 Branching Example 1Branch on Z flag 0000 B9 03 00 LOOP1: MOV CX,3 0003 49 LOOP2: DEC CX 0004 75 FD JNE LOOP2 0006 74 F8 JE LOOP1

  10. Repeat While / Repeat Until Loop L1: --- --- --- LOOP L1 L1: --- --- --- CX = CX - 1 repeat while CX /= 0 L1: --- --- --- CX = CX - 1 repeat until CX = 0

  11. Do While Loop JCXZ NEXT L1: --- --- --- LOOP L1 NEXT: --- Do while CX /= 0 --- --- --- CX = CX - 1 end do NEXT: ---

More Related