Docsity

Status Flags Review-Assembly Language Programming-Lab Slides, Slides of Assembly Language Programming

Toggle sidebar
bg1
1
Status Flags - Review
•The Zero flag is set when the result of an operation
equals zero.
•The Carry flag is set when an instruction generates a
result that is too large (or too small) for the destination
operand.
•The Sign flag is set if the destination operand is
negative, and it is clear if the destination operand is
positive.
•The Overflow flag is set when an instruction generates
an invalid signed result (bit 7 carry is XORed with bit 6
Carry).
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16

Partial preview of the text

Download Status Flags Review-Assembly Language Programming-Lab Slides and more Slides Assembly Language Programming in PDF only on Docsity!

1

Status Flags - Review

• The Zero flag is set when the result of an operation

equals zero.

• The Carry flag is set when an instruction generates a

result that is too large (or too small) for the destination

operand.

• The Sign flag is set if the destination operand is

negative, and it is clear if the destination operand is

positive.

• The Overflow flag is set when an instruction generates

an invalid signed result (bit 7 carry is XORed with bit 6

Carry).

2

AND Instruction

• Performs a Boolean AND operation between each

pair of matching bits in two operands

• Syntax:

AND destination, source

(same operand types as MOV)

AND cleared unchanged

AND

4

XOR Instruction

• Performs a Boolean exclusive-OR operation between

each pair of matching bits in two operands

• Syntax:

XOR destination, source XOR

XOR unchanged inverted

XOR is a useful way to toggle (invert) the bits in an operand.

5

NOT Instruction

• Performs a Boolean NOT operation on a single

destination operand

• Syntax:

NOT destination NOT

0 0 1 1 1 0 1 1 1 1 0 0 0 1 0 0

NOT inverted

7

Applications

mov al,6 ; AL = 00000110b or al,00110000b ; AL = 00110110b

  • Task: Convert a binary decimal byte into its equivalent

ASCII decimal digit.

  • Solution: Use the OR instruction to set bits 4 and 5.

The ASCII digit '6' = 00110110b

8

TEST Instruction

  • Performs a nondestructive AND operation between each pair of

matching bits in two operands

  • No operands are modified, but the Zero flag is affected.
  • Example: jump to a label if either bit 0 or bit 1 in AL is set.

test al,00000011b jnz ValueFound

  • Example: jump to a label if neither bit 0 nor bit 1 in AL is set.

test al,00000011b jz ValueNotFound

10

CMP Instruction (2 of 3)

  • Example: destination > source

mov al, cmp al,5 ; ZF = 0, CF = 0

(both the Zero and Carry flags are clear)

11

CMP Instruction (3 of 3)

  • Example: destination > source

mov al, cmp al,-2 ; Sign flag == Overflow flag

The comparisons shown here are performed with signed integers.

  • Example: destination < source

mov al,- cmp al,5 ; Sign flag != Overflow flag

13

Jumps Based on Specific Flags

14

Jumps Based on Equality

16

Jumps Based on Signed Comparisons

17

Applications (1 of 5)

cmp ax,bx ja Larger

  • Task: Jump to a label if unsigned AX is greater than BX
  • Solution: Use CMP, followed by JA

cmp ax,bx jg Greater

  • Task: Jump to a label if signed AX is greater than BX
  • Solution: Use CMP, followed by JG

19

Applications (3 of 5)

mov Large,bx cmp ax,bx jna Next mov Large,ax Next:

  • Compare unsigned AX to BX, and copy the larger of the two

into a variable named Large

mov Small,ax cmp bx,ax jnl Next mov Small,bx Next:

  • Compare signed AX to BX, and copy the smaller of the two into a variable named Small

20

Applications (4 of 5)

cmp WORD PTR [esi], je L

  • Jump to label L1 if the memory word pointed to by SI equals

Zero

test DWORD PTR [di], jz L

  • Jump to label L2 if the doubleword in memory pointed to by DI is even