Microcomputers I CE 320 Electrical and Computer Engineering Kettering University jkwonketteringedu httpwwwketteringedujkwon Jaerock Kwon PhD Announcements Quiz 3 30 mins 1045 AM 1115 AM ID: 830138
Download The PPT/PDF document "© 2010 Kettering University, All rights..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
© 2010 Kettering University, All rights reserved.
Slide2Slide3Microcomputers I – CE 320
Electrical and Computer Engineering
Kettering University
jkwon@kettering.eduhttp://www.kettering.edu/~jkwon
Jaerock Kwon, Ph.D.
Slide4Announcements
Quiz 3
30
mins (10:45 AM ~ 11:15 AM)
Slide5Lecture 13 :
Special Bit Instructions
Slide6Today’s Goals
Learn bit-set and bit-clear instructions
Branch on bit instructions
Slide7Bit Manipulate Instructions
BSET (M
(M) + (mm))
Set to 1 bits in a memory locationBCLR (M
(M) · (mm))Clear to 0 bits in a memory locationNote that …
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.
1
st
: the address
2
nd
: immediate mask valueIn the mask byte,1 means to affect the bit 0 means preserve the bitExamplesBSET 0,X, $81 ; $81 = %10000001BCLR 0,Y, $33 ; $33 = %00110011
Set or clear bits in a memory byte
Slide8Bit Test Instructions
BITA ((A)
· (M))
Bit test ATest bits without altering the value of the register.BITB ((B)
· (M)) Bit test BTest bits without altering the value of the register.
Examples
BITA #$44 ; $44 = %01000100
Tests the bit 6 and 2 of register A.
Updates Z and N bits of CCR accordingly.
Note that…
Like comparison instructions, the result is discarded. CCR bits are affected by the instructions.
Test bits
Slide9Bit Condition Branch Instructions
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]
BRSET: branch if (M)
· (mm) = 0 [if selected bit(s) set]
Examples
here
brclr
$66,$80,here
ldd
$70
;; -------------------------
loop inc count
…
brset
$66,$e0,loop
…
Note: The first operand is an address.
Slide10Examples
Turn on the cabin light without affecting other bits
Two door sport car
BSET $00, %00000010 ; $02
7
6
5
4
3
2
1
0
$0000
GBOXD
LEFTD
RGHTD
TRNKD
-
GBOXL
CBNL
TRNKL
Slide11Examples
Turn off the glove box light and trunk light without affecting other bits
Two door sport car
BCLR $00, %00000101 ; $05
7
6
5
4
3
2
1
0
$0000
GBOXD
LEFTD
RGHTD
TRNKD
-
GBOXL
CBNL
TRNKL
Slide12Examples
Turn on the cabin light if either door is open (=the bit is set)
Two door sport car
LDAA $00
BITA #%01100000 ; #$60
BNE CBNLON
BRA SKIP
CBNLON: BSET $00, %00000010 ; $02
SKIP:
7
6
5
4
3
2
1
0
$0000
GBOXD
LEFTD
RGHTD
TRNKD
-
GBOXL
CBNL
TRNKL
Slide13Examples
Turn off the cabin light if both doors are closed
Two door sport car
BRCLR $00, %01100000, CBNLOFF
BRA SKIP
CBNLOFF: BCLR $00, %00000010
SKIP:
7
6
5
4
3
2
1
0
$0000
GBOXD
LEFTD
RGHTD
TRNKD
-
GBOXL
CBNL
TRNKL
Slide14Examples
Turn on the cabin light if both doors are open
Two door sport car
BRSET #%01100000 CBNLON
BRA SKIP
CBNLON: BSET $00, %00000010 ; $02
SKIP:
7
6
5
4
3
2
1
0
$0000
GBOXD
LEFTD
RGHTD
TRNKD
-
GBOXL
CBNL
TRNKL
Slide15Questions?
Slide16Wrap-up
Bit set/clear instructions
Bit condition branch instructions
What we’ve learned
Slide17What to Come
Stack
Subroutines