The fifth experiment - learn to do addition, subtraction, multiplication and division with me

Publisher:CelestialLightLatest update time:2011-02-25 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Seeing this topic, haha, many people may want to hit Shitou brother with the board; what is 7+5? Do I need you to teach me this? But in the single-chip microcomputer, numbers are represented by binary: this is a bit difficult to understand/ Although our textbook has reached this point, you may not have learned a single instruction. But what I mean is to do a few experiments first to increase everyone's interest in single-chip microcomputers. There are too many specific instructions, but fortunately, generally we only need to remember 10-20 commonly used ones. OK, now start.

We write the following two instructions

MOV P1,#23H
END

I think everyone can understand this program. It sends the hexadecimal number 23H to the P1 port (i.e. P1.0--P1.7), compiles the HEX code and burns it, then inserts the chip into the experimental card holder; you can see that the status of P1.0-1.7 is;

P1.0 Off

P1.1 off

P1.2 Bright

P1.3 Bright

P1.4 Bright

P1.5 off

P1.6 Bright

P1.7 Bright

(Photo of Yitian Development Kit in action)

Why is this happening?

Note that because the 8 lights of our P1 port are connected to positive 5V at one end and the port at the other end, the port is low level 0. The LED is on. High level is not on. Arranged from high to low (from 1.7 to 1.0), it is 00100011. This number is 23H. What? You don't believe it? Well, please continue reading! 00100011 is 100011 in binary. According to the principle of mathematics, the leading 0 does not count.

Follow me to open the computer's Programs/Accessories/Calculator, and then set the calculator to scientific type. Then click Binary and enter 100011

Then click on the hexadecimal number and you can see that the number becomes 23. This is the 23H we entered.

Exercise: 25H+36H?

The procedure is as follows:

MOV R0,#25H; Send the immediate value 25 to register R0

MOV A,#36H; Send the immediate value 36 to accumulator A

ADD A,R0; add the contents of R0 and A, and the result is in A

NOP; no operation

POV P1,A; send the value of accumulator A to port P1.

END; End

After compiling the program, burn it into the chip and run it; you can see that the status of the light is

P1.0 Off

P1.1 off

P1.2 Bright

P1.3 Extinction

P1.4 Extinction

P1.5 Bright

P1.6 Extinction

P1.7 Bright

That is the binary number 01011011. Let's use the calculator above to see if the result is correct: first set the calculator to hexadecimal, enter 25+36 = the result is 5E

Then click on the binary result, which is 1011110. It can be seen that the result is completely correct.

You can then practice on your own

Subtraction instruction SUBB

Multiplication instruction MUL

Division instruction DIV

I believe that after learning this section, everyone will have a deep impression of these instructions. At the same time, it also gives us a better understanding of computer numbers.

Deep understanding.

Reference address:The fifth experiment - learn to do addition, subtraction, multiplication and division with me

Previous article:The fourth experiment: the small speaker makes the sound of an ambulance
Next article:Experiment 7--------Comprehensive exercise on digital display of running lights

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号