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

This lecture is part of lecture series on Computer Organization and Assembly Language. Main points of this lecture are: Conditional Processing, Boolean and Comparison, Conditional Jumps, Conditional Loop Instructions, Conditional Structures, Finite-State Machines, Decision Directives, Applications, Instruction Generates, Destination Operand

Typology: Slides

2012/2013

Uploaded on 04/25/2013

aristel
aristel 🇺🇸

4.2

(34)

313 documents

1 / 77

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Computer Organization &
Assembly Languages
Conditional Processing
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d

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