This preview shows page 1-2-19-20 out of 20 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Conditional JumpsConditional StructuresJumps Based on Specific Flag Values(10)Jumps Based on Unsigned Comparisons(8)Jumps Based on Signed Comparisons(8)Conditional Jump ApplicationsIn Class ProblemsSlide 9Slide 10Slide 11Slide 12Slide 13Block-Structured IF StatementsIF, Else StatementsLogical AND Operator Finding alternate ways to implement expressions may reduce the amount of code needed. Using JBE instead of JA:Logical OR Operator There are several ways to implement expressionsWhile LoopTable-Driven SelectionsPart of a TableConditional JumpsJcond destinationCond refers to a flag conditionDestination should be a local labelDestination must be within –128 to +127 bytes from the current locationLots of different conditional jump instructionsFour types: Specific flag comparisonsEquality between operands, or the value of ECX unsigned comparisons signed comparisonsConditional StructuresTwo steps are needed to executeAn operation such as CMP, AND, or SUBTo modify the flagsA conditional jump instruction tests the flags and causes a branch to a new address.1. CMP al, 0jz L1 ;jump to L1 if ZF = 12. AND dl, 1011 0000bjnz L2 ;jump to L2 if ZF = 0Jumps Based on Specific Flag Values(10)Mnemonic Description Flags/RegistersJZ if zero ZF = 1JNZ if not zero ZF = 0JC if carry CF = 1JNC if not carry CF = 0JO If overflow OF = 1JNO If not overflow OF = 0JS if signed SF = 1JNS if not signed SF = 0JP if parity (even) PF = 1JNP if not parity (odd) PF = 0Mnemonic Description Flags/RegistersJE if equal ZF = 1JNE if not equal ZF = 0JCXZ if CX = 0 ZF = 0JECXZ if ECX = 0 ZF = 0Jumps Based on Equality(4)Jumps Based on Unsigned Comparisons(8)Jumps Based on Signed Comparisons(8)Conditional Jump ApplicationsIn Class Problems1. Will the following code jump to the label named Target?mov ax, 8109hcmp ax, 26hjg Targetjg → signed conditional jump (8109h < 26h) so no jumpIn Class Problems2. Will the following code jump to the label named Target?mov ax, -30cmp ax, -50jg Targetjg → signed conditional jump (-30 > -50) so jump is takenIn Class Problems3. Will the following code jump to the label named Target?mov ax, -42cmp ax, 26ja Targetja → unsigned conditional jump -42 = D6h, 26 = 1Ah D6 > 1A so jump is takenIn Class Problems4. Write instructions that jump to label L1 when the unsigned integer in DX is less than or equal to the integer in CX.cmp dx, cxjbe L1In Class Problems5. Write instructions that jump to label L2 when the signed integer in AX is greater than the integer in CX.cmp ax, cxjg L2In Class Problems6. Write instructions that clear bits 0 and 1 in AL. If the destination operand is equal to zero, jump to label L3. Otherwise, jump to label L4.AND AL, 0FChJZ L3JMP L4Block-Structured IF StatementsIf ( op1 == op2){X = 1;Y = 2;}Mov eax, op1Cmp eax, op2Je L1Jmp L2L1:Mov X, 1Mov Y, 2L2:IF, Else StatementsIf ( op1 == op2){X = 1;Y = 2;}Else{ X = 4; Y = 5;}Mov eax, op1Cmp eax, op2Je L1Jmp L2L1:Mov X, 1Mov X, 2Jmp L3L2:Mov, X, 4mov X, 5L3:Logical AND OperatorFinding alternate ways to implement expressions may reduce the amount of code needed. Using JBE instead of JA: If (al > bl) AND (bl > cl){x = 1;}Cmp al, bljbe nextcmp bl, cljbe nextmov X, 1Next:Logical OR OperatorThere are several ways to implement expressionsIf (al > bl) OR (bl > cl){x = 1;}Cmp al, blja L1cmp bl, cljbe nextL1:mov X, 1Next:While LoopWhile (val1 < val2){val1++;val2--;}mov eax, val1While:cmp eax, val2jnl endwhileinc eaxdec val2jmp whileEndwhile:mov val1, eaxTable-Driven SelectionsA way of using a table lookup to replace a multiway selection structure.Create a table containing lookup values and the offsets of labels or procedures, and use a loop to search the table.Link to ProcTble.asmPart of a Table.dataCaseTable BYTE ‘1’ ;lookup valueDWORD Process_1BYTE ‘2’DWORD Process_2…..‘1’ 00000120 ‘2’ 00000130 ‘3’ 00000140Address of process_2Lookup


View Full Document

MSU ECE 3724 - Conditional Jumps

Documents in this Course
Timers

Timers

38 pages

TEST 4

TEST 4

9 pages

Flags

Flags

6 pages

Timers

Timers

6 pages

Timers

Timers

54 pages

TEST2

TEST2

8 pages

Load more
Download Conditional Jumps
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Conditional Jumps and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Conditional Jumps 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?