Logical operations on Microcontrollers accumulator A:
The CLR A;Clear the value in A to 0, single-period single-byte instruction, and MOV A, #00H effect is the same.
CPL A;Invert the values in A by bits
RL A;Move the value logic in A to the left
RLC A;Move the value in A to the left by adding the carry bit
The RR A;Move the value in A to the right logically
RRC A;Add the carry bit to the value in A to move it logically to the right
SWAP A;Swap the high and low values of A by 4 bits.
Example: (A) =73H, then CPL A is executed as follows:
73H into binary is 01110011,
Bitwise inversion is 10001100, or 8CH.
RL A is to send the 7th bit of the value in (A) to the 0th bit, the 0th bit to the 1st bit, and so on.
Example: the value in A is 68H and RL A is executed.68H into binary is 01101000, according to the figure above to move.01101000 becomes 11010000, which is D0H.
RLC A, is to carry the value in (A) with the carry bit (C) and shift it.
Example: if the value in A is 68H and the value in C is 1, RLC A is executed
After 1 01101000, the result is 0 11010001, that is, the value of the C carry bit becomes 0, and (A) becomes D1H.
RR A and RRC A are not much to talk about, please refer to the above two routines for your own practice.
SWAP A is to SWAP the high and low bits of the value in A.
Example :(A) =39H, then the value in A is 93H after executing SWAP A.How could it happen to switch back and forth like this?Because this is a hexadecimal number, each 16 digit represents four binary digits.Note that if this is true :(A) =39, followed by no H, after executing SWAP A, it is not true that (A) =93.If we want to convert it to binary, we can do it again: 39 to binary is 10111, which is the same thing as 0001,0111, so the high four bits are 0001, the low four bits are 0111, and the swap is 01110001, which is 71H, which is 113.
Practice, given (A) =39H, performing the following Microcontrollers instruction and writing out the results of each step
CPL a.
RL a.
The CLR C
RRC a.
SETB C
RLC a.
SWAP A