lecture 13 lecture 13 special bit instructions today s
play

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


  1. Lecture 13 : Lecture 13 : Special Bit Instructions

  2. Today’s Goals L Learn bit-set and bit-clear instructions bit t d bit l i t ti • Branch on bit instructions •

  3. Bit Manipulate Instructions Set or Set or clear bits in a clear bits in a memory byte memory byte BSET (M  (M) + (mm)) 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 … • They can only be used on data in memory. Th l b d d t i  Use AND and OR instructions for setting/clearing bits on registers.  Therefore, two operands are needed.  1 st : the address 1 : the address • 2 nd : immediate mask value • In the mask byte,  1 means to affect the bit • 0 0 means preserve the bit th bit • Examples •  BSET 0,X, $81 BSET 0,X, $81 ; $81 = %10000001 ; $81 %10000001  BCLR 0,Y, $33 ; $33 = %00110011

  4. Bit Test Instructions Test bits Test bits BITA BITA ((A) ((A) · (M)) (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.

  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 BRCLR: branch if (M) · (mm) = 0 [if selected bit(s) clear] [if selected bit(s) clear] • • BRSET: branch if (M) · (mm) = 0 [if selected bit(s) set] • E Examples l • here brclr $66,$80,here Note: The first operand is an address. ldd $70 ;; ------------------------- loop inc count … brset $66,$e0,loop …

  6. Examples Two door sport car Two door sport car Turn on the cabin light without affecting other bits T th bi li ht ith t ff ti th bit • BSET $00, %00000010 ; $02 7 7 6 6 5 5 4 4 3 3 2 2 1 1 0 0 $0000 GBOXD LEFTD RGHTD TRNKD - GBOXL CBNL TRNKL

  7. Examples Two door sport car Two door sport car Turn off the glove box light and trunk light without affecting T ff th l b li ht d t k li ht ith t ff ti • other bits BCLR $00, %00000101 ; $05 7 7 6 6 5 5 4 4 3 3 2 2 1 1 0 0 $0000 GBOXD LEFTD RGHTD TRNKD - GBOXL CBNL TRNKL

  8. Examples Two door sport car Two door sport car Turn on the cabin light if either door is open (=the bit is set) T th bi li ht if ith d i ( th bit i t) • LDAA $00 BITA #%01100000 ; #$60 BNE CBNLON BRA SKIP CBNLON: BSET $00, %00000010 ; $02 SKIP: 7 7 6 6 5 5 4 4 3 3 2 2 1 1 0 0 $0000 GBOXD LEFTD RGHTD TRNKD - GBOXL CBNL TRNKL

  9. Examples Two door sport car Two door sport car T Turn off the cabin light if both doors are closed ff th bi li ht if b th d l d • BRCLR $00, %01100000, CBNLOFF BRA SKIP CBNLOFF: BCLR $00, %00000010 SKIP: 7 7 6 6 5 5 4 4 3 3 2 2 1 1 0 0 $0000 GBOXD LEFTD RGHTD TRNKD - GBOXL CBNL TRNKL

  10. Examples Two door sport car Two door sport car T Turn on the cabin light if both doors are open th bi li ht if b th d • BRSET #%01100000 CBNLON BRA SKIP CBNLON: BSET $00, %00000010 ; $02 SKIP: 7 7 6 6 5 5 4 4 3 3 2 2 1 1 0 0 $0000 GBOXD LEFTD RGHTD TRNKD - GBOXL CBNL TRNKL

  11. Questions?

  12. Wrap-up What we’ve learned What we’ve learned

  13. What to Come

Recommend


More recommend