conditional_jump_and_loop_instructions

100 %
0 %
Information about conditional_jump_and_loop_instructions
Education

Published on March 23, 2014

Author: yuri56

Source: slideshare.net

* Property of STI Page 1 of 19 Conditional Jump and Loop Instruction Computer Organization and Assembly Language The Jcc Instructions  The Jcc (Conditional Jump) instructions are jumps that may or may not transfer control depending on the state of the status flags at the time the instruction is executed.  Format: Jcc operand  Action: If the specified condition cc is true, it will jump to the address specified in the operand; otherwise the next instruction is executed. 1 _________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ * Property of STI Page 3 of 19 Conditional Jump and Loop Instruction Computer Organization and Assembly Language The Jcc Instructions Mnemonic “Jump if …” Condition JG/JNLE greater than/not less than or equal ZF=0 or (SF=OF) JGE/JNL greater than or equal/not less than SF = OF JL/JNGE less than/not greater than or equal SF  OF JLE/JNG less than or equal/not greater than ZF=1 or (SFOF) Comparing Signed Numbers 3 __________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ * Property of STI Page 2 of 19 Conditional Jump and Loop Instruction Computer Organization and Assembly Language The Jcc Instructions Mnemonic “Jump if …” Condition JA/JNBE above/not below nor equal (CF or ZF) = 0 JAE/JNB above or equal/not below CF = 0 JB/JNA below/not above nor equal CF = 1 JBE/JNA below or equal/not above (CF or ZF) = 1 Comparing Unsigned Numbers 2 _________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ * Property of STI Page 4 of 19 Conditional Jump and Loop Instruction Computer Organization and Assembly Language The Jcc Instructions Mnemonic “Jump if …” Condition JE/JZ equal to/zero ZF = 1 JNE/JNZ not equal to/not zero ZF = 0 JC carry CF = 1 JNC not carry CF = 0 JS sign SF = 1 JNS not sign SF = 0 JP/JPE parity/parity even PF = 1 JNP/JPO no parity/parity odd PF = 0 JO overflow OF = 1 JNO no overflow OF = 0 Test Flags 4 __________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________

* Property of STI Page 5 of 19 Conditional Jump and Loop Instruction Computer Organization and Assembly Language Example – Jcc Instruction 1. MOV AL, A5H MOV BL, 73H CMP AL, BL JA L1 5 _________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ * Property of STI Page 7 of 19 Conditional Jump and Loop Instruction Computer Organization and Assembly Language Example – Jcc Instruction 3. MOV AL, 00H MOV CL, 03H AGAIN: ADD AL, 02H DEC CL JNZ AGAIN 7 __________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ * Property of STI Page 6 of 19 Conditional Jump and Loop Instruction Computer Organization and Assembly Language Example – Jcc Instruction 2. MOV AL, A5H MOV BL, 73H CMP AL, BL JG L1 6 _________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ * Property of STI Page 8 of 19 Conditional Jump and Loop Instruction Computer Organization and Assembly Language Example – Jcc Instruction 4. MOV AL, 7FH MOV BL, 75H ADD AL, BL JO NEXT 8 __________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________

* Property of STI Page 9 of 19 Conditional Jump and Loop Instruction Computer Organization and Assembly Language Example – Jcc Instruction 5. MOV AL, 01H DEC AL JG L1 9 _________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ * Property of STI Page 11 of 19 Conditional Jump and Loop Instruction Computer Organization and Assembly Language The JCXZ Instruction  The JCXZ (Jump if CX is 0) instruction transfers control to the target operand if CX is 0.  Format: JCXZ short-label  Action: If CX = 0, then jump to the address specified by the operand. 11 _________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ * Property of STI Page 10 of 19 Conditional Jump and Loop Instruction Computer Organization and Assembly Language Example – Jcc Instruction 6. Circumventing the limitation of the short- label: MOV BX, 0002H MOV CX, 0002H CMP BX, CX JE L1 : : : L1: : : 10 ________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ * Property of STI Page 12 of 19 Conditional Jump and Loop Instruction Computer Organization and Assembly Language Program Tracing Example Unless otherwise stated, determine the contents of all the affected general-purpose registers and the flags after executing the following programs (assume that all registers and flags are initially 0): MOV AL, 23H MOV CH, 6BH XOR AL, CH TEST AL, 77H JZ L1 AND CH, 33H L1: XOR CH, AAH TEST CH, AL JZ L2 NOT AL OR CH, AL L2: NOT CH What will be AX and CX after executing this program? 12 _________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________

* Property of STI Page 13 of 19 Conditional Jump and Loop Instruction Computer Organization and Assembly Language The LOOP Instruction  The LOOP instruction decrements CX by 1 and transfers control to the target location if CX is not 0; otherwise, the instruction following LOOP is executed.  Format: LOOP short-label  Action: CX [CX] - 1 If CX  0, then jump to the address specified by the operand; otherwise execute the instruction following the LOOP. 13 ________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ * Property of STI Page 15 of 19 Conditional Jump and Loop Instruction Computer Organization and Assembly Language The LOOPE/LOOPZ Instruction  The LOOPE/LOOPZ (Loop while equal/Loop while zero) instruction decrements CX by 1 and transfers control to target location if CX is not zero and if ZF is 1; otherwise the instruction following LOOPE/LOOPZ is executed.  Format: LOOPE short-label LOOPZ short-label  Action: CX [CX] - 1 If CX  0 and ZF = 1, then jump to the address specified by the operand; otherwise execute the instruction following the LOOPE/LOOPZ. 15 _________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ * Property of STI Page 14 of 19 Conditional Jump and Loop Instruction Computer Organization and Assembly Language Example - LOOP Instruction MOV CX, 0003H MOV AX, 0000H L1: INC AX LOOP L1 What is the value of AX and CX? 14 ________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ * Property of STI Page 16 of 19 Conditional Jump and Loop Instruction Computer Organization and Assembly Language Example - LOOPE/LOOPZ Instruction MOV CX, 0005H MOV SI, FFFFH MOV AL, 01H L1: INC SI CMP BETA [SI], AL LOOPE L1 01H 01H 03H 01H 01HBETA: 16 _________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________

* Property of STI Page 17 of 19 Conditional Jump and Loop Instruction Computer Organization and Assembly Language The LOOPNE/LOOPNZ Instruction  The LOOPNE/LOOPNZ (Loop while not equal/Loop while not zero) instruction decrements CX by 1 and transfers control to the target location if CX is not zero and ZF is 0; otherwise the instruction following LOOPNE/LOOPNZ is executed.  Format: LOOPNE short-label LOOPNZ short-label  Action: CX [CX] - 1 If CX  0 and ZF = 0, then jump to the address specified by the operand; otherwise execute the instruction following the LOOPNE/LOOPNZ. 17 ________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ * Property of STI Page 19 of 19 Conditional Jump and Loop Instruction Computer Organization and Assembly Language Program Tracing Example Unless otherwise stated, determine the contents of all the affected general-purpose registers and the flags after executing the following programs (assume that all registers and flags are initially 0): MOV AX, 000AH MOV CX, 0014H L1: SUB AX, 0001H LOOP L1 LOOPZ L1 LOOPNZ L1 What will be AX and CX after executing this program? 19 _________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ * Property of STI Page 18 of 19 Conditional Jump and Loop Instruction Computer Organization and Assembly Language Example - LOOPNE/LOOPNZ Instruction MOV CX, 0005H MOV SI, FFFFH MOV AL, 01H L1: INC SI CMP BETA [SI], AL LOOPNE L1 04H 07H 01H 05H 03HBETA: 18 ________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________ ___________________

Add a comment

Related presentations

Related pages

3.5 Control Transfer Instructions - logix.cz

3.5 Control Transfer Instructions The 80386 provides both conditional and unconditional control transfer instructions to direct the flow of execution.
Read more

condition cc - cs.tufts.edu

General-Purpose Programming 59 24592—Rev. 3.14—September 2007 AMD64 Technology target offset of the JMP instruction is ignored, and the new values ...
Read more

MELJUN CORTES Conditional Jump and Loop Instructions

Computer Organization and Assembly LanguageThe Jcc Instructions Ø The Jcc (Conditional Jump) instructions are jumps ...
Read more

Exam topics for Assembly language programming II E 2007

13. jump, conditional jump and loop instructions 14. software interrupts 15. procedures 16. macro definitions 17. macro and procedure libraries 18 ...
Read more

Module_4_-_COMPARISON_AND_CONDITIONAL_INSTRUCTIONS.pdf

MELJUN CORTES Conditional Jump and Loop Instructions. MELJUN CORTES Data Transfer Instructions. Addressing Modes&Instructions. MELJUN CORTES Rotate ...
Read more

Chapter Objectives - Kip Irvine

Irvine Assembly Language for x86 Processors 6th Edition Chapter Objectives. ... Be familar with all types of conditional jump and loop instructions;
Read more

Assembly Language for Intel-Based Computers, 5th Edition ...

... how the CMP instruction affects CPU status flags Be familar with all types of conditional jump and loop instructions Know how to create ...
Read more

Irvine K.R. - Assembly Language for x86 Processors, 6th ...

• Be familar with all types of conditional jump and loop instructions ... Assembly Language for x86 Processors, 7th edition
Read more