Lecture 13 : Lecture 13 : Special Bit Instructions Todays Goals L - - PowerPoint PPT Presentation

lecture 13 lecture 13 special bit instructions today s
SMART_READER_LITE
LIVE PREVIEW

Lecture 13 : Lecture 13 : Special Bit Instructions Todays Goals L - - PowerPoint PPT Presentation

Lecture 13 : Lecture 13 : Special Bit Instructions Todays Goals L Learn bit-set and bit-clear instructions bit t d bit l i t ti Branch on bit instructions Bit Manipulate Instructions Set or Set or clear bits in a clear


slide-1
SLIDE 1

Lecture 13 : Lecture 13 : Special Bit Instructions

slide-2
SLIDE 2

Today’s Goals

L bit t d bit l i t ti

  • Learn bit-set and bit-clear instructions
  • Branch on bit instructions
slide-3
SLIDE 3

Bit Manipulate Instructions

  • BSET (M  (M) + (mm))

Set or Set or clear bits in a clear bits in a memory byte memory byte

  • BSET (M  (M) + (mm))
  • Set to 1 bits in a memory location
  • BCLR (M  (M) · (mm))

( ( ) ( ))

  • Clear to 0 bits in a memory location
  • Note that …

Th l b d d t i

  • They can only be used on data in memory.
  • Use AND and OR instructions for setting/clearing bits on registers.
  • Therefore, two operands are needed.
  • 1st : the address

1 : the address

  • 2nd : immediate mask value
  • In the mask byte,
  • 1 means to affect the bit

th bit

  • 0 means preserve the bit
  • Examples
  • BSET 0,X, $81

; $81 = %10000001 BSET 0,X, $81 ; $81 %10000001

  • BCLR 0,Y, $33

; $33 = %00110011

slide-4
SLIDE 4

Bit Test Instructions

BITA ((A) (M))

Test bits Test bits

  • BITA

((A) · (M))

  • Bit test A
  • Test bits without altering the value of the register.

g g

  • BITB

((B) · (M))

  • Bit test B
  • Test bits without altering the value of the register.
  • Examples

Examples

  • BITA #$44

; $44 = %01000100

  • Tests the bit 6 and 2 of register A.
  • Updates Z and N bits of CCR accordingly
  • Updates Z and N bits of CCR accordingly.
  • Note that…
  • Like comparison instructions the result is discarded CCR bits
  • Like comparison instructions, the result is discarded. CCR bits

are affected by the instructions.

slide-5
SLIDE 5

Bit Condition Branch Instructions

Make branch decisions based on the value of bits

  • Make branch decisions based on the value of bits.
  • BRCLR, BRSET
  • Perform bitwise logical AND on the contents of the specified memory location

and the mask supplied with the instruction.

  • BRCLR: branch if (M) · (mm) = 0

[if selected bit(s) clear]

  • BRCLR: branch if (M) · (mm) = 0

[if selected bit(s) clear]

  • BRSET: branch if (M) · (mm) = 0

[if selected bit(s) set]

E l

  • Examples

here brclr $66,$80,here ldd $70

Note: The first operand is an address.

;; ------------------------- loop inc count … brset $66,$e0,loop …

slide-6
SLIDE 6

Examples

T th bi li ht ith t ff ti th bit

Two door sport car Two door sport car

  • Turn on the cabin light without affecting other bits

BSET $00, %00000010 ; $02

7 6 5 4 3 2 1 7 6 5 4 3 2 1 $0000 GBOXD LEFTD RGHTD TRNKD

  • GBOXL

CBNL TRNKL

slide-7
SLIDE 7

Examples

T ff th l b li ht d t k li ht ith t ff ti

Two door sport car Two door sport car

  • Turn off the glove box light and trunk light without affecting
  • ther bits

BCLR $00, %00000101 ; $05

7 6 5 4 3 2 1 7 6 5 4 3 2 1 $0000 GBOXD LEFTD RGHTD TRNKD

  • GBOXL

CBNL TRNKL

slide-8
SLIDE 8

Examples

T th bi li ht if ith d i ( th bit i t)

Two door sport car Two door sport car

  • Turn on the cabin light if either door is open (=the bit is set)

LDAA $00 BITA #%01100000 ; #$60 BNE CBNLON BRA SKIP CBNLON: BSET $00, %00000010 ; $02 SKIP:

7 6 5 4 3 2 1 7 6 5 4 3 2 1 $0000 GBOXD LEFTD RGHTD TRNKD

  • GBOXL

CBNL TRNKL

slide-9
SLIDE 9

Examples

T ff th bi li ht if b th d l d

Two door sport car Two door sport car

  • Turn off the cabin light if both doors are closed

BRCLR $00, %01100000, CBNLOFF BRA SKIP CBNLOFF: BCLR $00, %00000010 SKIP:

7 6 5 4 3 2 1 7 6 5 4 3 2 1 $0000 GBOXD LEFTD RGHTD TRNKD

  • GBOXL

CBNL TRNKL

slide-10
SLIDE 10

Examples

T th bi li ht if b th d

Two door sport car Two door sport car

  • Turn on the cabin light if both doors are open

BRSET #%01100000 CBNLON BRA SKIP CBNLON: BSET $00, %00000010 ; $02 SKIP:

7 6 5 4 3 2 1 7 6 5 4 3 2 1 $0000 GBOXD LEFTD RGHTD TRNKD

  • GBOXL

CBNL TRNKL

slide-11
SLIDE 11

Questions?

slide-12
SLIDE 12

Wrap-up

What we’ve learned What we’ve learned

slide-13
SLIDE 13

What to Come