Presentation is loading. Please wait.

Presentation is loading. Please wait.

Comparison Instructions Test instruction –Performs an implied AND operation between each of the bits in 2 operands. Neither operand is modified. (Flags.

Similar presentations


Presentation on theme: "Comparison Instructions Test instruction –Performs an implied AND operation between each of the bits in 2 operands. Neither operand is modified. (Flags."— Presentation transcript:

1 Comparison Instructions Test instruction –Performs an implied AND operation between each of the bits in 2 operands. Neither operand is modified. (Flags affected: OF=CF=0, SF, ZF,AF,PF) –TEST reg, reg-TEST mem, reg –TEST reg,mem -TEST mem, immed –TEST reg, immed Example: Checking printer status –Mov ah,2 ;function: read printer status –Int 17h ;call BIOS –Test al,00100000b ;ZF=0 if out of paper Can check if either bit 0 or bit 3 is set (ZF=1 only if both bits are clear)

2 Comparison Instructions CMP Instruction –Performs an implied subtraction of a source operand from a destination operand. Neither operand is modified. Segment registers cannot be used. –CMP reg, reg- CMP mem, reg –CMP reg,mem - CMP mem, immed –CMP reg, immed For Unsigned operand comparisons:

3 Using Compare (CMP)

4 Comparison Instructions CMP Instruction For Signed operand comparisons:

5 Conditional Jumps Jcond Instructions –Transfers control to a destination address when a flag condition is true. –Destination address must be –128 to +127 bytes from the current location, which can sometimes be a problem. –Three types of conditional jump instructions: general comparisons unsigned comparisons signed comparisons

6 Jumps Based on General Comparisons

7 Jumps Based on Unsigned Comparisons

8 Jumps Based on Signed Comparisons

9 Steps to executing IF statements Use comparison and arithmetic statements (CPU sets individual flags based on result) Use conditional jump instructions (CPU takes action based on flags) cmp al, 0 Jznext;jump if ZF=1 … Next:

10 Use SHORT operator to improve machine code Use SHORT before jump label to eliminate NOP instructions after your jump instruction. Cmp ax,0 Jne short L2 Movbx,2 L2: …

11

12 Do While Loop

13


Download ppt "Comparison Instructions Test instruction –Performs an implied AND operation between each of the bits in 2 operands. Neither operand is modified. (Flags."

Similar presentations


Ads by Google