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 JumpsJcond destinationCond refers to a flag conditionDestination should be a local labelDestination must be within –128 to +127 bytes from the current locationLots of different conditional jump instructionsFour types: Specific flag comparisonsEquality between operands, or the value of ECX unsigned comparisons signed comparisonsConditional StructuresTwo steps are needed to executeAn operation such as CMP, AND, or SUBTo modify the flagsA 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 SelectionsA 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