4. Using logic gates to implement adder and subtraction device

Source: Internet
Author: User

Understanding the door, we can do some practical application, the main purpose of the computer is to calculate, and the door can be used for computing, so it can be said that the computer is composed of a variety of different doors. The next thing we do is make a binary adder, because if you make the adder, you can expand to subtract, multiply, divide. And how do we implement adder? We only use some of the most common and somewhat backward parts this time: switches, bulbs, wires, batteries, doors.

The input is a switch, the output is a row of light bulbs, the light represents 1, the off means 0. If the binary string is to be additive, we will definitely think of one person doing the addition, so if there is a 8-bit binary number, we will divide 8 operations. By trying to know, only if the input is two 1 o'clock, the carry bit is 1, and therefore conforms to the gate characteristics, and when the input is two 1 or two 0 o'clock, the addition bit will be 0. This conforms to the XOR feature. Or how do we use the most basic logic gates to express it. We can make it through two and non-doors, one or gate. This makes up a half-additive.

The purpose of the semi-adder is because we do not consider the low carry problem, if we consider it, we are called the full adder. And the full-additive is composed of 2 half-plus and one or a door.

Next we'll talk about how many relays we need to use:

The carry bit is with the door, so consists of 2 relays.

The addition bit is one or the door, one with the non-gate, one with the door composed, so by 6 relays.

The half adder consists of a carry bit and an addition bit, then there are 8 relays.

The full-add device consists of two halves and one or gate, then there are 18 relays.

If we have a full adder, we can make a binary string addition by cascading.

But now the computer is using transistors, so the relays need to be switched to transistors.

We implemented the adder before, as we said, subtraction is the extension of addition, so implement the adder, only need a little modification, you can achieve subtraction, and subtraction is the most annoying is borrow, so we think there is a way to avoid borrow it.
The answer is yes,
(1) When meiosis > meiosis, set to be meiosis x, meiosis y, assuming X and y are three decimal digits, only need to x-y=x+ (999-y) +1-1000, this equation looks very common, but can avoid borrow problems. Because 999-y cannot happen borrow, other steps are impossible.
(2) When meiosis < meiosis, x-y=-(999-(x+ (999-y)), this can also avoid borrow.
Here we implement the binary subtraction, so similar to the above,
(1) When meiosis > meiosis, x-y=x+ (111-y) +1-1000.
(2) When meiosis < meiosis, x-y=-(111-(x+ (111-y)).
So we know the method, how do we implement it using the adder? Here we only implemented the first case.
We split x+ (11...1-y) +1-100...0 and see,
(1) First a=11...1-y, this is actually the negation, that is, through the aforementioned inverter.
(2) b=x+ (111...1-y) +1, this requires only the previous adder.
(3) b-100 ... 0 This only needs to ignore the highest bit. Because of the meiosis >, the highest bit is definitely 1.
What if we can't do a subtraction alone, but instead combine the adder with the subtraction?
We first have to have a switch, which is the choice of addition and subtraction. If it is an addition, it is done according to the adder, and if it is subtraction, it is done by the subtraction method.
Let's set this option to X, subtract to 1, and add to 0. This bit is different from each bit of the input or, if it is an addition, the input and input is inconvenient, if it is subtraction, then the input is opposite to the output, that is, the 2 is complementary. This achieves the 11 ... The 1-y function.
We also set the minimum carry Y, or 1 if it is subtraction, or 0 if it is an addition. This solves the x+1+ (11...1-y).
We set the highest bit to Z, and if it is addition, the output is constant, and if it is subtraction, the output becomes 0. We need to use XOR gates. The x+ (111...1-y) +1-1000..0 is implemented.
This allows us to combine the subtraction with the adder.
Here are a few terms to follow:
(1) If the number is X, then 999-x is the complement of 10, then 111-x is the complement of 2.
We have another question, how to say subtraction.
Many people know that there is the original code, anti-code, and complement.
For example 111 in signed number is 1. In the unsigned number is +3. So the original binary is not any meaning, only give him the context, will have meaning.
We also need to consider the overflow problem when the signed number is added. If, for example, 011+010=101, the original positive number becomes negative, because he is beyond the range that the complement can represent.

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.