2.
Logical instructions
1 Set port 0, bits 1,3,5,7, t0 1; set rest to 0.
1.ANL 80H,#0AAH
2. MOV 80H,#0AAH
2 Clear bit 3 of RAM location 22h without affecting any other bit
1)ANL 22h,#0F7h ; Byte level instruction
2)CLR 13h ; bit3 of RAM address 22h(bit level instruction)
3 Invert the data on port0 pins and data to port1
MOV A,P0
CPL A
MOV P1,A
4 Swap the nibbles of R0 and R1 so that low
nibble of R0 swaps with high nibble of R1 and Method2
high nibble of R1 and high nibble of R0 swaps MOV R0,#24H
with Low nibble of R1 . MOV R1,#78H
MOV R0,#24H MOV A,R0 ; A=24H
MOV R1,#78H SWAP A ;A=42H
MOV A,R0 ; A=24H XCH A,R1 ;A=87H
SWAP A ;A=42H SWAP A ;R0=87H, A=42H
MOV R0,A ;R0=42H MOV R0,A ; R1=42H
MOV A,R1 ;A=78H END
SWAP A ;A=87H
XCH A,R0 ;R0=87H, A=42H
MOV R1,A ; R1=42H
END
5 Complement the lower nibble of RAM location 2Ah.
MOV A,2AH
XRL A,#0FH
MOV 2AH,A
END
6 Make low nibble of R5 the compliment of high nibble of R6.
MOV R6, #72H
MOV R5, #34H
XRL 06H, #0F0H ;R6=82H
MOV A,R6 ;A=82H
SWAP A ;A=28H
ANL A, #0Fh ;A=08H
MOV R2,A ;R2=08H
MOV A,R5 ;A=34H
ANL A, #0F0H ;A=30H
ORL A, R2 ;A=38H
MOV R5, A ;R5=38H
END
1
7 Make the high nibble of R5 the complement of low nibble of R6.
MOV R6, #72H
MOV R5, #34H
XRL 05H, #0F0H ;R6=82H
MOV A,R5 ;A=82H
SWAP A ;A=28H
ANL A, #0Fh ;A=08H
MOV R2,A ;R2=08H
MOV A,R6 ;A=34H
ANL A, #0F0H ;A=30H
ORL A, R2 ;A=38H
MOV R5, A ;R5=38H
END
8 Move bit 6 of R0 to bit 3 of port 3.
MOV R0,#0FH
MOV 20h,R0
MOV C,06H
MOV 0B3H,C
END
9 Move bit 4 of RAM location 30h to bit 2 of accumulator.
MOV 30H,#0F0h
MOV 20H,30H
MOV C,04H
MOV ACC.2,C
END
10 XOR a number with whatever is in A so that result is FFh.
MOV R3,A
XRL A,#0FFH
XRL A,R0
END
11 Store most significant NIBBLE of A in both nibbles of register R5.
ANL A,#0F0H
MOV R3,A
SWAP A
ORL A,R3
END
12 Store least significant nibble of A in both the nibbles of RAM address 3Ch; Ex: if A=36h then
3Ch=66h
ANL A,#0FH
MOV 3Ch,A
SWAP A
ORL 3Ch,A
END
13 Set the carry flag to one if the number in A is Method 2
even; set the carry flag to zero if the number MOV A,#45H
in A is odd. ORL C,/0E0H
RRC A END
2
CPL C
END
14 Treat registers R0 and R1 as 16 bit registers, and rotate them one place to the LEFT: bit7 of R0
becomes bit0 of R1 becomes bit0 of R0 , and so on.
MOV R0,#09H
MOV R1,#08H
MOV A,R0
RLC A
MOV R0,A
MOV A,R1
RLC A
MOV R1,A
MOV A,R0
MOV ACC.0,C
MOV R0,A
END
15 Treat registers R0 and R1 as 16 bit registers, and rotate them one place to the RIGHT: bit0 of R1
becomes bit7 of R0 bit0 of R0 becomes bit7 of R1.
MOV A,R1
RRC A
MOV R1,A
MOV A,R0
RRC A
MOV R0,A
MOV A,R1
MOV ACC.7,C
MOV R1,A
END
16 Rotate the DPTR one place to the left; bit 15 becomes bit 0.
MOV DPTR,#1234h
MOV A,DPL
RLC A
MOV DPL,A
MOV A,DPH
RLC A
MOV DPH,A
MOV A,DPL
MOV ACC.0,C
MOV DPL,A
END
17 Repeat problem 16 to rotate the DPTR one place to the right.
MOV DPL,#34H
MOV DPH,#12H
MOV A,DPH
RRC A
MOV DPH,A
MOV A,DPL
RRC A
3
MOV DPL,A
MOV A,DPH
MOV ACC.7,C
MOV DPH,A
END
18 Shift register B one place to the left; bit 0 becomes a zero, bit 6 becomes bit7, and so on bit7 is
lost.
MOV 0F0H,#0FFH
MOV A,0F0H
CLR C
RLC A
CLR C
END
20 Write a program that will swap the bits of
each nibble in register R5.Swap the bits 0 and
1 with bits 2 and 3, and bits 4 and 5 with bits
6 and 7.
Method2
Method1 MOV A,R5
MOV A,R5 SWAP A
MOV 30H,R5 MOV R5,A
RL A END
RL A
ANL A,#0CCH
PUSH OE0H
MOV A,30H
RR A
RR A
ANL A,#33H
POP 05H
ORL A,05H
END