Integer operations: only addition operations within the CPU

Source: Internet
Author: User

To learn the compilation of the side. What I'm talking about here is the principle of CPU computing.
First, I used the MC's Redstone circuit to simulate an adder: http://www.0xaa55.com/thread-313-1-1.htm
How is the adder implemented first? It uses a non-gate circuit. First look at the addition of the binary:
0+0=0
0+1=1
1+0=1
1+1=10
First look at the rules. Just look at the lowest bit, if the left "Summand" and "Addend" are the same, the lowest bit of the result is 0, otherwise it is 1.
And if the "Summand" and "Addend" are all 1, then there will be rounding.
The law is summed up:
The lowest bit of the result = summand logical non-addend
Rounding of arithmetic results = summand logic and Addend
This is the principle of adder.
So back to the topic, I say the CPU has only addition operations inside. Why do you say that? To listen to my explanation:
The addition is used by the CPU for addition operations. So how does subtraction operate? The addition operation is still used.
Assuming the CPU is a 8-bit CPU, let me give you an example.
01010101+11111111=101010100
The resulting calculation is a 9-bit binary number. But the CPU is 8 bits, the register is 8 bits, can only support 8 bit binary computation. Where did the extra bit go? Do not consider
One is that the CPU adds a number to another number, such as 3*6,CPU internal 3+3+3+3+3+3 operation.
Another way is to improve the method, I give an example:
1010x100100
How does this look?
First we can think of it as follows:
1000x100100+10x100100
This is simple, equivalent to 100100 left shift 3 bit plus 100100 left shift 1 bits.
So the internal CPU first shifted the addend, and then the addend of the shift to accumulate. The result of the operation is obtained. Essentially, the CPU is simply an addition operation.
So what about division, I'd like to cite this example: the quotient of 10010010÷00101101 is 11, the remainder is 1011. How did you get it?
In fact, and our primary school to do the same vertical calculation.
11
________
101101/10010010
101101
--------
1110000
101101
-------
1011
It is such a person to remove down.

Https://www.0xaa55.com/forum.php?mod=viewthread&tid=318&extra=page%3D14

Integer operations: only addition operations within the CPU

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.