r/AskComputerScience • • Jul 04 '21

How does a computer's software interact with transistors to use them as switches?

If I type an A on my computer screen, there's a row of transistors somewhere in my computer's system that represents the binary 01000001. What exactly is switching the state on these transistors?

Every time I Google about this, only explanations on how a transistor works come up.

33 Upvotes

12 comments sorted by

29

u/Thomas12345678901 Jul 04 '21

So basically each bit in the assembler code represents eaither control or data information. The cpu has a control unit, which is basically some and/or/not.... gates. Depending on the instruction, the control unit switches the coresponding transistors on/off. Here is a website that explains this in a bit more detail https://www.howtogeek.com/367931/htg-explains-how-does-a-cpu-actually-work/. I hope i could help you with this.

8

u/Heavy-Suggestion3464 Jul 04 '21

This is that one response that actually helped! Thank you so much for the link!

5

u/diogenes08 Jul 04 '21

ASCII and logic gates are what you are looking for.

On a hardware level, the input, say from a mouse, keyboard, network stream, etc, the bit you put in goes into a logic gate(containing a transistor,) and either sends or doesn't, send another bit depending on what the logic says.

On a software level, series of these bits, usually 8, are put into a byte, making 256 possible combinations. ASCII originally, though most current character encoders are still based on it, is a list of characters matched to these bytes.

Everything on the computer is just more and more complex layerings of these.

0

u/Heavy-Suggestion3464 Jul 04 '21

Yes, the hardware level part is what I'm looking for, but still quite don't understand how the transistors are flipped by the software. Can you elaborate on that process a bit?

6

u/ggchappell Jul 05 '21 edited Jul 05 '21

still quite don't understand how the transistors are flipped by the software. Can you elaborate on that process a bit?

Software doesn't actually do anything on its own. The hardware does everything. What is software? It's a collection of instructions that the hardware can follow ("execute"). The hardware executes the software by looking at memory (where the software is stored), deciding what the value in some particular location means, and then performing the indicated action.

The hardware that does all this is made of transistors. Really, transistors functioning as switches, which flip or do not flip, is the only thing that ever actually happens in a computer. Why does a transistor flip? Answer: because the voltage on one of its inputs changes. Where does that voltage come from? Answer: other transistors, as /u/khedoros indicated.

Now, how the hardware executes the software is a complicated story in which ever fancier structures are built up out of simpler components. As /u/diogenes08 indicated, using transistors, we can construct logic gates. Using those we can construct things like a flip-flop (simple memory), an adder (which adds two numbers), etc. Continuing like this, we can eventually construct large memories and processors.

/u/sequinors wrote:

This question can’t be answered in a single Reddit comment

And that is quite correct. If you really want the complete answer, then you'll need to do some reading on your own and/or take a class.

3

u/Heavy-Suggestion3464 Jul 05 '21

That made sense. Thanks for the answer!

5

u/zurkog Jul 05 '21

Play this game: https://nandgame.com/

Then take this (free) course: https://www.nand2tetris.org/

DM me if you need more info, but I took the course (the game is just a game-ified version of the course) and it really opened my eyes. I already knew how logic gates worked, I could build up to a full adder and a register (basic storage). From the top down, I knew how software worked, could write programs, knew how compilers worked, and knew the basics of computers (RAM, what a CPU was, the computer bus, etc). But I had never bridged the gap. Nand2Tetris did that for me.

4

u/khedoros Jul 04 '21

What exactly is switching the state on these transistors?

The states of the transistors that act as inputs to those ones :-P In the case of the keyboard, you closed a switch when you pressed the "A" key, and it set off a cascade of changes through a series of combinatorial and sequential logic circuits.

Computers can be viewed from a lot of levels of abstraction. Near the bottom, quantum physics, near the top, behavior of a software program. Just above the transistor level, we've got logic gates, which are each built out of a handful of transistors. The rest of what I'll say will be at about the level of those gates, and the circuits that they make when combined. The basic gates are "AND", "OR", and "NOT". "AND" outputs 1 if all of its inputs are 1, and 0 otherwise. "OR" outputs 1 if any of its inputs are 1. "NOT" outputs the opposite of its input.

Conceptually, these gates can be combined into more complicated gates, like NAND ("Not-AND", outputs the opposite of what an "AND" gate would), NOR ("Not-OR"), XOR (eXclusive-OR, outputs 1 if a single input is 1, but 0 otherwise). How these are actually implemented in transistors is often not literally "AND gate connected to a NOT gate", which is why I said "conceptually".

There are standard logic circuits, like multiplexers and demultiplexers (which help route data), adders (and implementations of other arithmetic and logical functions), flip-flops (which implement memory in silicon), etc. These are arranged into larger components that might do something like "Wait for input to transition from 0 to 1 on a specific wire, then send the data from these 8 wires to 1 of 4 possible places, depending on the inputs from the first 2 of those 8 wires". Those 4 locations might each have different functions that they perform on the lower 6 bits of data, or something.

1

u/emasculine Jul 04 '21

you need to look up flip flops which are generally transistors in a feedback loop to retain state. what's switching the state is the control logic surrounding them. all of it is built up from basic logic gates like nand and nor gates, which build bigger things like muxes, adders, alus, and so on.

1

u/Sandarr95 Jul 04 '21

Maybe play around with a logic gate simulator. You can try to make an xor or logic gate using only nand gates (if I remember correctly nands are quite commonly used as a base). Than you could also try to come up with display encodings like ASCII. If you google "logic gate simulator" you should find plenty of web apps and offline software.

Something you said about how the software flips the transistors I think will best be understood when doing it yourself. The software doesn't flip the transistors anymore than the transistors flipping make the software. It's like air molecules and music.

1

u/sequinors Jul 04 '21

This question can’t be answered in a single Reddit comment, and is only partially answered by any of the comments here. You might consider taking a few classes in a computer science department. A computer organization and operating systems class will definitely answer your question in full.

Here is a great textbook that will give you the full answer to your question - https://www.amazon.com/dp/0072467509/ref=cm_sw_r_cp_api_glt_fabc_D9F70F5289DV5SRMDQJ9

1

u/OldNewbProg Jul 05 '21

"What exactly is switching the state on these transistors?"

Electricity. :D Is the simple terrible answer. Everyone else has better answers. If you won't take a class and won't look for an online course, I'd recommend the place I first learned it: https://www.nand2tetris.org/

I'm a software dev with a degree in cs and read this book about a year or two before college. It isn't the most well written book but I think it's probably my favorite CS book.