CPU has built-in circuitry to do simple arithmetic operations

In summary, a CPU uses built-in circuitry to do simple arithmetic operations and logical operations, such as greater than, less than, etc.
  • #1
jackson6612
334
1
Hi

I'm a layman so please keep your reply as simple as possible. Thanks.

They say that a CPU has built-in circuitry to do simple arithmetic operations such as addition, subtraction, etc. and logical operation such as greater than, less than, etc. I don't understand how could some circuit(s) do these things? Could you please explain it with some simple example? Thank you for your time and help.
 
Technology news on Phys.org
  • #2
Well the CPU is made of billions of transistors. Those transistors are combined into different logical elements, called gates, that perform logical functions(AND, OR, NAND, NOT, etc). Different combinations of different gates can be made to perform a specific function such as those you have listed. In the CPU that part is called the ALU - arithmetic logic unit.

That is the simple explanation. I'm sure there are people here who know more about this stuff than me that can explain it in further detail.
 
  • #3
Thanks. Matrix.

It would be nice and really helpful if someone could show me that how a CPU add 1+1 to 2 or subtract 1-1 to 0.
 
  • #5
Thanks, JT. If that's what I'm supposed to know first, then I will read them and come back soon. I have some knowledge of the gates but don't understand half-adder and full-adder circuits.
 
  • #6
I just whipped up something that can add 1 plus 1:

pfadd1plus1.jpg


Does this make sense?
 
  • #7
jackson6612 said:
It would be nice and really helpful if someone could show me that how a CPU add 1+1 to 2 or subtract 1-1 to 0.
It's probably helpful to look at this stuff at different levels. For instance, at the level of CPU instructions, you can do addition by using the ADD instruction, as in the following x86 assembly code:
Code:
mov ax, 1  ; Move the value 1 into the AX register
add ax, 2   ; Add 2 to the value in the AX register

The text after each semicolon is a comment.
After the second instruction above, the value 3 will be in the AX register.

Subtraction can be done using the SUB instruction, like so:
Code:
mov ax, 1  ; Move the value 1 into the AX register
sub ax, 1   ; Subtract 1 from the value in the AX register
After the second instruction executes, the value in the AX register will be 0.

If you're interested in knowing how the CPU actually carries out the addition and subtraction, then you need to look into things at the level of logic gates and adders, as jtbell suggests. Speaking for myself, my interest is more on the programming side than the electrical/electronic engineering side. I take it on faith that the engineering guys know how to make a chip add, subtract, and so on. This is usually, but not always, a safe bet. In the case of the Pentium 1 processor back in about 1992 or so, the microcode for division had an error that was difficult to detect. Fixing the problem by recalling these chips cost Intel about $1.5 Billion.
 
  • #8
jackson6612 said:
Hi

I'm a layman so please keep your reply as simple as possible. Thanks.

They say that a CPU has built-in circuitry to do simple arithmetic operations such as addition, subtraction, etc. and logical operation such as greater than, less than, etc. I don't understand how could some circuit(s) do these things? Could you please explain it with some simple example? Thank you for your time and help.

For arithmetic you use what is known as "adder" circuits. They work just like the way you add numbers in base 10 except that a computer uses base 2. It takes two bits computes the result and also the carry bit. You basically have a chain of these to calculate the full result and the number of adders is basically the number of bits that is the size of the number your adding.

Things that compare use logic. Let's say you want to see if a number is a certain number and if its you do something. You can take the value in some register and subtract your 'number' from it. If it equals zero then you do something. One way we can test this is to invert the bits of the result and then compute the result bit to be (bit0 AND bit1 AND bit2 ... AND bitn) which will give 1 if true and 0 if not. Then this bit is used to do something.

A way to say compare if one number is greater than the other with unsigned bits is to simply do a subtraction involving two words with the CPU using n+1 bits and then checking the sign bit at the end of the computation. If you want to know how signed bits work look at "2's complement" on wikipedia.

So in a nutshell arithmetic is done using adders and with multiplication you just use AND gates as well as adders in exactly the same way you do multiplication using pen and paper.

When you use comparisons you basically use a formula that sets a bit to some state (1 or 0) to represent if the comparison was true or false.
 
  • #9
Thank you, everyone.

Please let me remind you again that I'm a very much layman in these techno subject, so please be as much specific as possible. Thanks.

Here K2 really helped me to understand what a logic gate actually is:
https://www.physicsforums.com/showpost.php?p=3016758&postcount=9

The logic gates AND, OR, etc. are simply 'mathematical' or 'boolean' objects and in real life are implemented through circuits made from transistors. Right?

So, if this is possible to explain to me with the limited extent of knowledge, then would you please tell me how some circuits would be implemented to get "01" (which stands for '2') once the two inputs of the circuits are '1' and '1', i.e. 1+1=01 (in binary)? Could you please help me? If this seems a complex problem to explain then you could choose some less complex example to explain what I seek to know. Thanks a lot for the guidance and your time.
 
  • #10
jackson6612 said:
The logic gates AND, OR, etc. are simply 'mathematical' or 'boolean' objects and in real life are implemented through circuits made from transistors.
AND, OR, and XOR logic can be created from NAND or NOR gates.

Wiki article about NAND gates, second link includes diagram of simple adder:

http://en.wikipedia.org/wiki/Nand_gate
http://en.wikipedia.org/wiki/NAND_gate

The same thing could be done with NOR gates (although NAND gate based logic would be more common):

http://en.wikipedia.org/wiki/Nor_gate
http://en.wikipedia.org/wiki/NOR_logic

To store and hold data you need a latch (flip flop) for each bit:

http://en.wikipedia.org/wiki/Latch_(electronics)

To implement a true multi-bit adder, you need an adder that includes 3 bit inputs, the two input bits plus the carry bit from the lower order add bit.

http://en.wikipedia.org/wiki/Adder_(electronics)

Although it's unlikely you'll run into this, some old computers used different names for these operations in their instruction sets.

selective_set
(control) OR (data)
for each 1 bit in control or data word, the data bit is set in the output word

selective_copy
(control) AND (data)
for each 1 bit in control word, a bit from the data word is copied, otherwise the bit is set to 0

selective_complement
(control) XOR (data)
for each 1 bit in control word, a bit from the data word is complemented, otherwise the bit is copied

selective_clear (few computers have this instruction)
(~control) AND (data)
for each 1 bit in control word, a bit is cleared, otherwise the bit is copied
 
Last edited:
  • #11
jackson6612 said:
So, if this is possible to explain to me with the limited extent of knowledge, then would you please tell me how some circuits would be implemented to get "01" (which stands for '2') once the two inputs of the circuits are '1' and '1', i.e. 1+1=01 (in binary)? Could you please help me? If this seems a complex problem to explain then you could choose some less complex example to explain what I seek to know. Thanks a lot for the guidance and your time.

see post #6
 
  • #12
i want cpu circuit to do arithmetic operations and logical operations
 
  • #13
anyone can help me to design cpu
 

1. What is a CPU?

A CPU, or central processing unit, is the main component of a computer system that is responsible for executing instructions and performing calculations.

2. What is meant by "built-in circuitry" in a CPU?

Built-in circuitry refers to the electronic components within a CPU that are designed specifically for processing and manipulating data. These components include transistors, logic gates, and arithmetic and logic units (ALUs).

3. How do CPUs perform arithmetic operations?

CPU's perform arithmetic operations by using their built-in circuitry, specifically the ALU. The ALU is responsible for performing basic arithmetic operations such as addition, subtraction, multiplication, and division.

4. What are some examples of simple arithmetic operations?

Examples of simple arithmetic operations include adding two numbers together, subtracting one number from another, multiplying two numbers, and dividing one number by another.

5. Why is it important for a CPU to have built-in circuitry for arithmetic operations?

Having built-in circuitry for arithmetic operations allows a CPU to perform calculations quickly and efficiently, which is essential for running programs and executing instructions in a computer system. It also reduces the need for external components and makes the CPU more compact and cost-effective.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
7
Views
3K
  • Programming and Computer Science
2
Replies
37
Views
8K
Replies
6
Views
1K
  • Programming and Computer Science
Replies
21
Views
3K
  • Programming and Computer Science
Replies
5
Views
3K
Replies
1
Views
828
  • Programming and Computer Science
Replies
29
Views
2K
Replies
14
Views
1K
Replies
4
Views
2K
Back
Top