Ordinary MCU Teaching——Lecture 11 MCU Instructions (V)

Publisher:清新自然Latest update time:2015-01-23 Source: laogu Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.
 

Reference address:Ordinary MCU Teaching——Lecture 11 MCU Instructions (V)

Previous article:Ordinary MCU Teaching——Lecture 12 MCU Instructions (VI)
Next article:Ordinary MCU Teaching——Lecture 10 MCU Instructions (IV)

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号