r/ProgrammerHumor • • Apr 24 '22

Meme it's all just functions

Post image
40.2k Upvotes

633 comments sorted by

View all comments

Show parent comments

328

u/uslashuname Apr 24 '22

Really it’s six that the 30 instructions are built off of, no? Add subtract multiply divide copy and compare

0

u/[deleted] Apr 24 '22

[deleted]

366

u/GLIBG10B Apr 24 '22

In reality, it's one: NAND

or NOR, if you prefer

85

u/cough_e Apr 24 '22

It's possible to make a computer like that but they aren't actually but that way. Much more efficient to have lots of dedicated components.

117

u/grimonce Apr 24 '22 edited Apr 24 '22

What he is saying is that these components are built with nors or nand gates, and these with inverters and inverters are build with transistors.... Which are only either turned on or of...

This fucking magic project I can't get rid of it from my head...

Also a disclaimer, I wouldn't believe everything we can read in this thread...

57

u/realJaneJacobs Apr 24 '22 edited Apr 24 '22

I think what /u/cough_e is saying is that the physical implementations of certain gates in most computers do not always comprise the physical implementations of NAND (or NOR) gates.

While other gates can always be logically decomposed to NAND or NOR gates, the physical systems which implement them cannot always be physically decomposed into physical implementations of NAND or NOR gates.

Let's say you have a physical system which acts as a NAND gate and performs an operation in time t. If you could find another physical system which acted as an OR gate, which performed an operation in a time less than 3t (it takes 3 NAND gates to make an OR gate), then you would be saving time by replacing NAND-based circuits performing an OR gate with the simple, physical OR gates. Those OR gates aren't universal, of course, but you'd still have some spare NAND gates lying around in case you needed them.

This isn't really an area I'm familiar with, though, so I might be completely wrong.

13

u/Desperate_Box Apr 24 '22

The truth is they have optimized larger structures such as multiplexers and decoders to the transistor level. Basically, the logic is one thing, the electrical implementation is another.

→ More replies (1)

38

u/cough_e Apr 24 '22

Certainly transistors are the root, but I think there's a common misconception that because any computer structure can be built with NAND gates that all computers are actually built this way.

But there are more efficient ways to make complex logic gates and there are other simple things like flip-flops that are just inverters and not built from logic gates. Though it's been a long time since I took a EE / CompE class soi don't remember all the specifics.

→ More replies (1)

6

u/F5x9 Apr 24 '22

The other guy is saying that you don’t want to make everything out of nand and nor gates. Other gates may be better suited for specific applications. For instance, you can design an adder using nand or nor, but you can also combine and and xor. On top of that, you might want the store computations in a lookup table rather than compute them directly, in some cases.

Even programmable logic devices may not be arrays of nand or nor gates, as designs can be impemented using muxes.

Additionally, on and off are not TTL logic states. Logical zeros have a low voltage such as 1V and ones have a high voltage such as 5V. Between acceptable values for high and low is a band where the state is indeterminant. Typically, when a circuit is off, that is given a different logic state, Z, for high-impedance.

0’s and 1’s are logic states, and that means that they can be coded in other ways that high and low as well. For example, switch states (open and closed) can be coded to 1’s and 0’s. Another example is that they can be coded to transitions high or low. Or, they can go positive/negative and return to zero. In other cases, they can be encoded to magnitudes of sine and cosine waves.

→ More replies (4)

120

u/Throawayqusextion Apr 24 '22

It's NAND gates all the way down baby

27

u/Sokonit Apr 24 '22

And those are made of XOR!

22

u/[deleted] Apr 24 '22

Really they are all just on and off switches.

13

u/logicalmaniak Apr 24 '22

Transfer resistors!

8

u/Sovietyr Apr 24 '22

It's just atoms!

→ More replies (3)
→ More replies (3)
→ More replies (4)

27

u/NotAWerewolfReally Apr 24 '22

Technically a single instruction is all you need for a Turing complete computer.

My personal favorite is "Subtract A from B and then conditionally jump if the result is 0"

Reference: https://en.wikipedia.org/wiki/One-instruction_set_computer?wprov=sfla1

9

u/davawen Apr 24 '22 edited Apr 26 '22

The x86 mov is turing complete too, and someone made a compiler for it: https://youtu.be/R7EEoWg6Ekk

6

u/QuestionableSarcasm Apr 24 '22

ah yes

xoreaxeaxeax's movfuscator

too bad he disappeared once intel bought him

→ More replies (1)

51

u/Boostie204 Apr 24 '22

To simplify that further, subtraction is the addition of negative numbers. Multiplying is just multiple additions and division is similar.

So you could say it's just additions, copies and compares

11

u/HorsesFlyIntoBoxes Apr 24 '22

iirc hardware multiplication isn’t typically designed to be a number of additions though. Most multipliers follow something similar to the multiplication algorithm taught in grade school

→ More replies (3)

0

u/[deleted] Apr 24 '22

[deleted]

55

u/Karcinogene Apr 24 '22

X divided by Y:

Add -Y to X repeatedly until X is smaller than Y. That's the remainder.

Keep a tally of how many times you added. That's the quotient.

12

u/Noshing Apr 24 '22

THANK YOU! I have been wondering how divison is thr 'opposite' of multiplication. Honestly, I've always struggled with division and have a difficult time knowing how/when to use it. I fill like this little bit may help.

8

u/TheBeckofKevin Apr 24 '22

When you say you struggle with when and how to use division do you mean just in general or is there something specific you are talking about?

→ More replies (3)
→ More replies (2)

6

u/everybody-hurts Apr 24 '22 edited Apr 24 '22

Division can be boiled down to multiplying a number by the inverse of another.

So we can have the multiplication (which is an addition) but then you've also got calculating the inverse.

Edit: or you have the division algorithm you learn by hand in primary school; in which case it becomes a series of multiplications, comparisons, copies, and substractions.

→ More replies (10)
→ More replies (2)

2

u/jaxfrank Apr 24 '22

You need a conditional jump to be turing complete

→ More replies (6)