CPU has built-in circuitry to do simple arithmetic operations

Click For Summary

Discussion Overview

The discussion centers around how a CPU performs simple arithmetic operations, such as addition and subtraction, using built-in circuitry. Participants explore the underlying components, including transistors, logic gates, and adder circuits, while addressing the complexity of these operations in a binary system.

Discussion Character

  • Exploratory
  • Technical explanation
  • Conceptual clarification
  • Homework-related

Main Points Raised

  • Some participants explain that CPUs use billions of transistors organized into logic gates (AND, OR, etc.) to perform arithmetic and logical operations.
  • One participant mentions the Arithmetic Logic Unit (ALU) as the part of the CPU responsible for these operations.
  • There is a request for a simple example of how a CPU adds numbers, specifically 1 + 1.
  • Another participant suggests looking into basic logic gates and adder circuits, such as half-adders and full-adders, to understand the addition process.
  • One participant provides assembly code examples for addition and subtraction, highlighting the use of CPU instructions like ADD and SUB.
  • There is a discussion about how comparisons can be made using subtraction and checking the sign bit, as well as using logical operations to determine equality.
  • Some participants express a desire for a more detailed explanation of how circuits implement the addition of binary numbers, specifically how to achieve the output "01" for the input "1" and "1".
  • References to external resources, such as Wikipedia articles on logic gates and adders, are provided for further reading.

Areas of Agreement / Disagreement

Participants generally agree on the basic principles of how CPUs perform arithmetic operations using logic gates and circuits, but there is no consensus on the specific implementation details or the best way to explain these concepts to a layman.

Contextual Notes

Some participants acknowledge their limited knowledge of electronics and express the need for simpler explanations. There are references to various types of circuits and operations, but the discussion remains exploratory without definitive conclusions.

Who May Find This Useful

This discussion may be useful for individuals interested in understanding the basic functioning of CPUs, particularly those with limited technical background in electronics or computer architecture.

jackson6612
Messages
334
Reaction score
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
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.
 
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.
 
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.
 
I just whipped up something that can add 1 plus 1:

pfadd1plus1.jpg


Does this make sense?
 
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.
 
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.
 
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
 

Similar threads

  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 37 ·
2
Replies
37
Views
9K
  • · Replies 21 ·
Replies
21
Views
4K
Replies
6
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
3
Views
3K
Replies
6
Views
5K
Replies
10
Views
4K
Replies
29
Views
6K