Docsity

Conditional Processing - Computer Organization and Assembly Language - Lecture Slides, Slides of Assembly Language Programming

Partial preview of the text

Download Conditional Processing - Computer Organization and Assembly Language - Lecture Slides and more Slides Assembly Language Programming in PDF only on Docsity!

Computer Organization &

Assembly Languages

Conditional Processing

Chapter Overview

Boolean and Comparison

Instructions

 Conditional Jumps

 Conditional Loop Instructions

 Conditional Structures

 Application: Finite-State Machines

 Decision Directives

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.

 The Parity flag is set when an instruction generates an even

number of 1 bits in the low byte of the destination operand.

 The Auxiliary Carry flag is set when an operation produces a

carry out from bit 3 to bit 4 Docsity.com

AND Instruction

 Performs a Boolean AND operation between each

pair of matching bits in two operands

 Syntax: (OF=0,CF=0,SF,ZF,PF)

AND destination, source (same operand types as MOV)

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

AND cleared unchanged

AND

XOR Instruction

 Performs a Boolean exclusive-OR operation between each pair of matching bits in two operands

 Syntax: (OF=0,CF=0,SF,ZF,PF)

XOR destination, source

XOR

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

XOR unchanged inverted

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

NOT Instruction

 Performs a Boolean NOT operation on a single destination operand

 Syntax: (no flag affected)

NOT destination

NOT

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

NOT inverted

Applications (2 of 5)

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

Applications (3 of 5)

mov ax,40h ; BIOS segment mov ds,ax mov bx,17h ; keyboard flag byte or BYTE PTR [bx],01000000b ; CapsLock on

  • Task: Turn on the keyboard CapsLock key
  • Solution: Use the OR instruction to set bit 6 in the

keyboard flag byte at 0040:0017h in the BIOS data area.

This code only runs in Real-address mode, and it does not work under Windows NT, 2000, or XP.

Applications (5 of 5)

or al,al jnz IsNotZero ; jump if not zero

  • Task: Jump to a label if the value in AL is not zero.
  • Solution: OR the byte with itself, then use the JNZ

(jump if not zero) instruction.

ORing any number with itself does not change its value.

TEST Instruction

 Performs a nondestructive AND operation between each pair of matching bits in two operands

 No operands are modified, but the flags 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

CMP Instruction (2 of 3)

 Example: destination > source (unsigned)

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

(both the Zero and Carry flags are clear)

CMP Instruction (3 of 3)

 Example: destination > source (signed)

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

  • Example: destination < source (signed)

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

Pentium Flags Register

What's Next

 Boolean and Comparison Instructions

Conditional Jumps

 Conditional Loop Instructions

 Conditional Structures

 Application: Finite-State Machines

 Decision Directives