Download presentation
Presentation is loading. Please wait.
1
Microcontroller Fundamentals & Programming
Logical Instructions
2
Logic Instructions Consist AND, OR, EOR (XOR) and COM instructions.
Contents of accumulator operated logically, bit by bit, with corresponding bit in the memory. The result after logic instruction will be placed back in accumulator. C flag will not change. Only N and Z flags will change according to the result.
3
Logic Instructions – Block Diagram
Accumulator Result back to accumulator Memory AND, OR, EOR operation CCR N Z N & Z flags change
4
AND Instructions ANDA , ANDB
AND operation is used to clear or mask off any bit to “0” with other bits unchanged. Example: To clear bit 0 to bit 3 of ACCA LDAA #$5A $5A = ANDA #$F ; $F0 = AND Operation ; $50 = Results go to ACCA Result: ACCA = $50 ; Flag bits : N = “0” , Z = “0”
5
OR Instructions ORAA , ORAB
OR operation is used to set any bit to “1” with other bits unchanged. Example: To set bit 0 and 7 of ACCB LDAB #$1A ; $1A = ORAB #$81 ; $81 = OR Operation ; $9B = Results to ACCB Result: ACCB = $9B ; Flag bits : N = “1” , Z = “0”
6
EOR Instructions EORA , EORB (Exclusive OR)
EOR operation is used to invert any bits from a “1” to “0” and vice versa in accumulators A or B. Example: Invert Bit-0 ~ 3 of ACCB LDAB #$5A ; $5A = EORB #$0F ; $0F = EOR Operation ; $55 = Results to ACCB Result: ACCB =$55 ; Flag bits : N = “0” , Z = “0”
7
Complement Instructions
Example: COMA, COMB, COM Instruction will invert all the 8-bit contents in accumulator A or B or memory location. N and Z flag bits will change according to the result. C flag will set to “1”.
8
Example: Complement Instructions
MNEMONICS COMMENTS CLRA ; ACCA = $00 COMA ; ACCA = $FF LDAB #$F0 ; ACCB = $F0 COMB ; ACCB = $0F CLR $8000 ; contents of memory location ; ($8000) = $00 COM $8000 ; contents of memory location ; ($8000) = $FF.
9
Bit Instructions Example: BITA , BITB
An 8-bit logical test instructions. Bit instructions operate similar to AND operation. After executing Bit instructions : no result will be saved. only the flags in CCR are updated. N and Z flag bits will change according to the result. V flag will automatically set to “0”.
10
Example: Bit Instructions
Let value in memory ($1000) = % LDAA $ ; the 8-bit data in memory location ; ($1000) = % BITA #% ; % AND with ; % ; Results = (% ) ; N = “0” , Z = “1” BNE READKEY ; result not equal zero ; branch to READKEY routine.
11
Bit Instructions Instructions Addressing modes Comments BITA #$35 IMM
ACCA AND with $35 BITB #% ACCB AND with $0C BITB $90 DIR ACCB AND with data in memory $90 BITA $8000 EXT ACCA AND with data in memory ($8000) BITA $10,X IND,X ACCA AND with data in memory ($10 + X)
12
Bit Clear and Bit Set Instructions
Example: BCLR, BSET Bit clear instructions will clear any 8-bit directly in memory location. Bit set instructions will set any 8-bit directly in memory location. N and Z flag bits will change according to the result. V flag will set to “0”.
13
Example: Bit Clear and Bit Set Instructions
Instructions Addressing Comments Modes LDX #$2000 IMM IX = $2000 BCLR $10,$ DIR bit 4,5 of memory ($10) are cleared to “0”. BSET $20,$0C DIR bit 2,3 of memory ($20) are set to “1” BCLR $10,X,$ IND,X bit 4,5 of memory ($10+X) are cleared to “0”.
14
Example: Bit Clear and Bit Set Instructions
Instructions Addressing Comments Modes LDX #$ IMM IX = $2000 BCLR $10,% DIR bit 4,5 of memory ($10) are cleared to “0”. BSET $20,% DIR bit 2,3 of memory ($20) are set to “1” BCLR $10,X,% IND,X bit 4,5 of memory ($10+X) are cleared to “0”.
15
Shift & Rotate Instructions
Consist of Logical Shift , Arithmetic Shift and Rotate instructions. Move 8-bit values in accumulator or memory, including the C-flag, by 1-bit to the left or right. N, Z and C flags in CCR will change according to result. Types of addressing modes : INH, EXT, INDX & INDY.
16
Logical Shift Left Instructions
Example: Shift Left : LSL , LSLA , LSLB “0” B7 B6 B5 B4 B3 B2 B1 B0 C Memory or Accumulator Logical Shift Left: shift 8-bit value 1 place to the left. Bit-7 is shifted into C-bit . a “0” is placed into bit-0. Shifting binary number 1 bit to the left each time will multiply the original number by 2.
17
Example: Logical Shift Left instructions
Mnemonics C-flag ACCA Decimal Value LDAA #$22 3410 LSLA 6810 13610 1 1610 3210
18
Logical Shift Right Instructions
Example: Shift Right : LSR , LSRA , LSRB B7 B6 B5 B4 B3 B2 B1 B0 C “0” Logical Shift Right: shift the 8-bit value 1 place to the right. Bit-0 is shifted into C-bit a “0” is placed into bit-7. Memory or Accumulator Shifting binary number 1 bit to the right each time will divide the original number by 2.
19
Example: Logical Shift Right instructions
Mnemonics ACCA C-flag Decimal Value LDAA #$24 3610 LSRA 1810 0910 1 0410 0210
20
Arithmetic Shift Left Instructions
Example: Shift Left : ASL , ASLA , ASLB , ASLD “0” B7 B6 B5 B4 B3 B2 B1 B0 C Memory or Accumulator Arithmetic Shift Left: - Operation same as Logical shift left .
21
Example: Arithmetic Shift Left instructions
Mnemonics Accumulator A LDAA #$32 ASLA Arithmetic Shift Left is same as Logical Shift Left . Mnemonics Accumulator A LDAA #$32 LSLA
22
Arithmetic Shift Right Instructions
Example: Shift Right : ASR , ASRA , ASRB B7 B6 B5 B4 B3 B2 B1 B0 C Arithmetic Shift Right: shift 8-bit data (accumulator or memory) 1 place to the right. Bit-0 data is shifted into C-bit. The sign bit or bit-7 remains unchanged. Memory or Accumulator
23
Example: Arithmetic Shift Right instructions
Mnemonics Accumulator B C-flag LDAB #$C2 ASRB 1
24
Rotate Left Instructions
Example: Rotate Left : ROL , ROLA , ROLB B7 B6 B5 B4 B3 B2 B1 B0 C Rotate Left : shift 8-bit value (accumulator or memory) 1 place to the left. Bit-7 is shifted into C-bit and C-bit is placed into bit-0.
25
Example: Rotate Left instructions
Mnemonics C-flag Accumulator A LDAA #$F ROLA ROLA ROLA
26
Rotate Right Instructions
Example: Rotate Right : ROR , RORA , RORB C B7 B6 B5 B4 B3 B2 B1 B0 Rotate Right : shift 8-bit value (accumulator or memory) 1 place to the right. Bit-0 is shifted into C-bit and C-bit is placed into bit-7.
27
Example: Rotate Right instructions
Mnemonics Accumulator B C-flag LDAB #$0F RORB RORB RORB
28
Thank You
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.