Академический Документы
Профессиональный Документы
Культура Документы
Boolean Logic
g Instructions
Todays Goals
L
Learn
h
how to
t use Boolean
B l
iinstructions
t
ti
iin assembly
bl code
d
Logical Instructions
T
Target
t and
dM
Mask
kb
byte
t
Format
[[logical
g
instruction][register
][ g
or memory]
y] [[mask byte]
y ]
Ex. ANDA #%00001111
Function
0 Mask Bit
0MaskBit
1 Mask Bit
1MaskBit
AND
Clearto0
Noaffect
OR
Noaffect
Setto1
XOR
Noaffect
Toggle
AND
ANDA and ANDB
ANDA and
d ANDB
affect N and Z
clear V
no affect on C
Example
p
ORAA ORAB
ORAA,
affect N and Z
clear V
no affect on C
EORA, EORB
(meaning XOR)
affect
ff
N and
dZ
clear V
no affect on C
(meaning NOT)
Example
Consider a two-door
two door sports car with a trunk and a glove box.
box
Assume that contact switches are used to
monitor each door and
send
d signals
i
l tto th
the processor iindicating
di ti
Four bits are need to monitor two side doors, a trunk, and a glove
box.
The four bits will be 7, 6, 5, and 4 of memory $0000.
7
6
GBOXD LEFTD
5
4
RGHTD TRNKD
2
GBOXL
1
CBNL
0
TRNKL
Example
Turn off the glove box light without affecting the other bits.
T
Turn
OFF Use
U AND with
ith a proper mask
k byte
b t
LDAA
ANDA
STAA
$00
#%11111011
$00
RGHTD TRNKD
GBOXL CBNL
0
TRNKL
Example
Turn on the trunk light without affecting the other bits.
T
Turn
ON Use
U OR with
ith a proper mask
kb
byte
t
LDAA
ORA
STAA
$00
#%00000001
$00
RGHTD TRNKD
GBOXL CBNL
0
TRNKL
Example
Turn on the glove box light and the cabin light without affecting the other bits.
T
Turn
ON Use
U OR with
ith a proper mask
kb
byte
t
LDAA
ORA
STAA
$00
#%00000101
$00
RGHTD TRNKD
GBOXL CBNL
0
TRNKL
Example
Toggle the cabin light without affecting the other bits.
T
Toggle
l Use
U XOR with
ith a proper mask
kb
byte
t
LDAA
EORA
STAA
$00
#%00000010
$00
RGHTD TRNKD
GBOXL CBNL
0
TRNKL
Example
Negate accumulator D
N
Negate
t accumulator
l t D
COMA
COMB
ADD
#1
N
Negate
t D without
ith t using
i
the
th logical
l i l complement
l
t functions
f
ti
EORA
EORB
ADDD
#%11111111
#%11111111
#1
; #$FF
; #$FF
Example
Toggle the cabin lights at exactly 1000 Hz
flip:
loop:
LDAA
EORA
STAA
LDX
DEX
BNE
BRA
$00
#CBNL
$00
#N
loop
flip
p
;
;
;
;
;
;
;
3
2
3
2
N
3(N
3(N-1)+1
3
When the sum of all cycles of the lines become 24,000, we can say the
module
d l runs 1
1,000
000 times
i
per second.
d
3 + 2 + 3 + 2 + N + 3(N-1) + 1 +3 = 24,000
11 + 4N = 24,000
,
then,, 4N = 23989. Therefore,, N = 5997.25
N should be an integer, so 4N + 11 + ? = 24,000
If 5 is used for ?, then N = 5996
Example - continued
Toggle the cabin lights at exactly 1,000 Hz
flip:
loop:
LDAA
EORA
NOP
NOP
BRA
STAA
LDX
DEX
BNE
BRA
$00
#CBNL
0
$00
#5996
loop
flip
;
;
;
;
;
;
;
;
;
;
3
2
1
1 (to add 5 extra clock cycles)
3 (use 3 clock cycles while do nothing)
3
2
5996
3(
3(5996
5996-1)+1
3
I general,
In
l
K means 1,000
M means 1,000,000
K means 1,024
,
M means 1,024 x 1,024
210 = 1,024
Remember 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024,
Questions?
Wrap-up
What weve learned
B l
Boolean
llogical
i l iinstructions
t
ti
What to Come
Bit iinstructions
t
ti
Stack
Subroutines