3. Logical operation instructions:
1. Logical operation on accumulator A:
CLR A; clear the value in A to 0, single-cycle single-byte instruction, with the same effect as MOV A, #00H.
CPL A ; Bitwise inversion of the value in A
--------------------------------------------------------------------------------
RL A ; Logically shift the value in A left
RLC A; logically shift left the value in A plus the carry bit
RR A ; logically shift the value in A to the right
RRC A ; Add the value in A to the carry bit and perform a logical right shift
SWAP A; swap the high and low 4 bits of the value in A.
Example: (A) = 73H, then execute CPL A, as follows:
73H is converted to binary 01110011,
The bit-by-bit inversion is 10001100, which is 8CH.
RL A sends the 7th bit of the value in (A) to the 0th bit, the 1st bit to the 0th bit, and so on.
For example: The value in A is 68H, and RL A is executed. 68H is converted to binary as 01101000, and the movement is performed as shown above. 01101000 is converted to 11010000, which is D0H.
RLC A, shifts the value in (A) with the carry bit (C).
For example: if the value in A is 68H and the value in C is 1, then RLC A is executed.
After 1 01101000, the result is 0 11010001, that is, the value of the carry bit of C becomes 0, and (A) becomes D1H.
I won’t talk much about RR A and RRC A. Please refer to the two examples above and practice on your own.
SWAP A, swaps the high and low 4 bits of the value in A.
For example: (A) = 39H, then after executing SWAP A, the value in A is 93H. Why is it swapped like this? Because this is a hexadecimal number, and each hexadecimal digit represents 4 binary bits. Note that if it is like this: (A) = 39, there is no H after it, after executing SWAP A, (A) is not 93. It needs to be converted into binary and then calculated: 39 is converted into binary 10111, which is 0001. The high 4 bits of 0111 are 0001, and the low 4 bits are 0111. After the swap, it is 01110001, which is 71H, or 113.
Exercise, given (A) = 39H, write out the results of each step after executing the following instructions
CPL A
RL A
CLR C
RRC A
SETB C
RLC A
SWAP A
Through the previous study, we have mastered a considerable part of the instructions. You may be a little tired of these boring instructions. Let's relax and do an experiment.
Experiment 5:
ORG 0000H
LJMP START
ORG 30H
START:
MOV SP,#5FH
MOV A,#80H
LOOP:
MOV P1,A
RL A
LCALL DELAY
LJMP LOOP
delay:
mov r7,#255
d1: mov r6,#255
d2: nop
nop
nop
nop
djnz r6,d2
djnz r7,d1
ret
END
First, let's write the program into the chip, install it into the experimental board, and take a look at the phenomenon.
What we see is a phenomenon of dark spots flowing. Let's analyze it.
We will analyze the previous ORG 0000H, LJMP START, ORG 30H, etc. later. Starting from START, MOV SP, #5FH, this is to initialize the stack. It doesn't matter whether this sentence exists in this program, but we are slowly starting to get in touch with formal programming, so I will slowly cultivate the habit for everyone.
MOV A,#80H, sends the number 80H to A. What does it do? I don't know. Read on.
MOV P1, A. Send the value in A to the P1 port. At this time, the value in A is 80H, so the value sent out is 80H, so the value of the P1 port is 80H, which is 10000000B. Through the previous analysis, we should know that at this time, the LED connected to P1.7 is not bright, while the other LEDs are bright, so a "dark spot" is formed. Continue to look, RL A, RL A is to shift the value in A to the left. Calculate, what is the result after the shift? Yes, it is 01H, which is 00000001B. In this way, the LED connected to P1.0 should not be bright, while the others are bright. From the phenomenon, the "dark spot" flows to the back. Then call the delay program, which we are very familiar with, to make this "dark spot" "dark" for a while. Then transfer to LOOP (LJMP LOOP). Please calculate which light should be off below. . . . . . That's right, it should be connected to P1. The light on 1 is not on. This cycle will form the phenomenon of "dark spot flow".
Question:
1. How to achieve bright spot flow?
2. How to change the direction of flow?
Answer:
1. Change the initial value in A to 7FH.
2. Change RL A to RR A.
Previous article:Ordinary MCU Teaching——Lecture 12 MCU Instructions (VI)
Next article:Ordinary MCU Teaching——Lecture 10 MCU Instructions (IV)
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Ranking of installed capacity of smart driving suppliers from January to September 2024: Rise of independent manufacturers and strong growth of LiDAR market
- Industry first! Xiaopeng announces P7 car chip crowdfunding is completed: upgraded to Snapdragon 8295, fluency doubled
- P22-009_Butterfly E3106 Cord Board Solution
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Recruitment for part-time MBSE technical or consulting services
- EEWORLD University - 10 hours to learn image processing opencv introductory tutorial
- Single chip LCD1602 display program-controlled measurement amplifier
- Simple laser flashlight circuit diagram
- GD32E230C Test 1: Simple Date and Time Display
- What problems can the high-performance H7 chip solve?
- The Secret of Operational Amplifiers!
- Zero-knowledge open source sharing-temperature and humidity module SHT3X SHT30 SHT31 SHT35
- Why does the waveform of the bubble sensor in medical infusion pipeline have two segments?
- How to test and debug the frequency accuracy of radio frequency