Download presentation
Presentation is loading. Please wait.
1
Introduction to Computer Engineering by Richard E. Haskell Branching Instructions Module M17.2 Section 11.1
2
Introduction to Computer Engineering by Richard E. Haskell
3
Calculating Branching Displacements
4
Introduction to Computer Engineering by Richard E. Haskell Calculating Branching Displacements Note: Displacement is only 8 bits. Therefore, the program can only branch forward +127 bytes, or backward -128 bytes.
5
Introduction to Computer Engineering by Richard E. Haskell 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: ---------- But you should NEVER have to to this!
6
Introduction to Computer Engineering by Richard E. Haskell Branching Example 1 Branch 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
7
Introduction to Computer Engineering by Richard E. Haskell Branching Example 2 Branch 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
8
Introduction to Computer Engineering by Richard E. Haskell Branching Example 3 Branch 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
9
Introduction to Computer Engineering by Richard E. Haskell
11
Problem: Go through a loop 200 10 (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?
12
Introduction to Computer Engineering by Richard E. Haskell
13
Branching Example 1 Branch 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 0000 B9 03 00 L1: MOV CX,3 0003 E2 FE L2: LOOP L2 0005 EB F9 JMP L1 Same as:
14
Introduction to Computer Engineering by Richard E. Haskell Repeat While / Repeat Until Loop L1:--- --- LOOP L1 L1:--- --- CX = CX - 1 repeat while CX /= 0 L1:--- --- CX = CX - 1 repeat until CX = 0
15
Introduction to Computer Engineering by Richard E. Haskell Do While Loop JCXZ NEXT L1: --- --- LOOP L1 NEXT: --- Do while CX /= 0 --- CX = CX - 1 end do NEXT: ---
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.