How Hardware and Software communicates?

615 views
0

I still wonder how people manage to create a machine that visualize a graphic to a screen then commands it with a button.
I still wonder how “programming” works through metal/gold/copper
I’m still amaze that people made these stuff

In: Technology

Hardware is the medium on which software operates.

When your computer needs to do addition, it uses your processor’s ALU (arithmetic logic unit), essentially a complicated series of switches, to do it. Software is, ultimately, a very complicated set of states of a bunch of switches which will causes other switches to change their state.

[Assembly language](https://en.wikipedia.org/wiki/Assembly_language) is the lowest layer of software. It specifies which electronic circuits should switch on and off, and in what sequence, to perform the calculations.

It really comes down to two basic concepts:

1. You can represent any piece of information as a number as long as we all agree on a system for mapping those numbers back to their information. For example, if we all understand how to represent a color as numbers, and we all know how to signal that this specific number represents a color, so decode it as such, then we can easily communicate colors with numbers. This goes for everything: letters, pixels on a screen, sound, locations on a storage medium, etc.
2. You can represent any number in binary, and by extension in electrical circuits by something being in opposite states (e.g. high or low power).

So then it just comes down to sending a bunch of instructions to a processor on how to move and transform data really, really fast so that it appears as if it’s happening instantaneously. You can imagine circuits as a series of train tracks that control the levers of other train tracks. If a train is on track A, it might control whether another train goes down track B or track C. All of this gets orchestrated so that the right trains end up at the right destinations based on a handful of initial trains, such as the ones stored in your hard drive, or sent from your keyboard.

The software is a bunch of electrical charges arranged inside of the hardware. It’s not necessarily “communicating” to the hardware as much as it’s what’s going on inside of the hardware at a given moment. If you want to get a grasp of what’s happening, it’s best to ignore the fancy “how does it make this fancy spreadsheet or play Skyrim” and go back to basics: How do we get a computer to represent numbers and do basic stuff with them like adding? Once you see that it’s fairly easy to imagine how that scales up.

A very simple demonstration is made [in this excellent video](https://www.youtube.com/watch?v=lNuPy-r1GuQ) that demonstrates how you can make a basic calculator with dominoes. It’s the same principle as a computer uses, but it replaces transistors (little electrical switches) with dominoes knocking each other over. It doesn’t demonstrate all the complexity involved in a full computer, but gives a good flavor of what’s happening.

If you have a few hours to burn and know how breadboards work (a pretty easy thing to look up on Google or Youtube) you can watch Ben Eater demonstrate [how to build an 8-bit computer from scratch in this playlist](https://www.youtube.com/playlist?list=PLowKtXNTBypGqImE405J2565dvjafglHU). If you want to see how that translates to displaying graphics on a monitor he has a short series where he shows how to build a simple (and not very good) video card in a short series that begins with [this video](https://www.youtube.com/watch?v=l7rce6IQDWs).

The tl;dr of the series is that there are instructions that can be hard-wired into the CPU, which we represent as binary numbers. That number is represented by either having voltage on a wire or not, so a 4-bit number might be hot, cold, hot, cold (1010 or 9). When those voltages are applied to the CPU wires it triggers the hardwired arrangement of transistors to execute whatever the 1010 instruction is, which the CPU manufacturers have determined. This works just like the dominoes example I explained earlier. You’re telling the CPU to “knock over that particular arrangement of dominoes” which then turns on some arrangement of output wires from the CPU that gives you the answer to your math problem or sends a signal to some other part of the computer to do something. The input wires from the CPU are connected to the RAM chips (actually a bus on the mobo I believe, but let’s keep it simple). The RAM is holding the series of instructions as charges inside of capacitors (or other methods, again keep it simple). Those charges in the capacitors *are* the software.

Hi 🙂

That’s a very complex subject and a lot of great posts already 🙂

I’m not summarizing how you get from a key-press to a display message here; But if you’re interested in understanding such things at a fundamental level, with hands-on experience and not just reading about it… It’s fun to try stuff:

– Go through an electronics guide such as “Getting started in electronics”, it has a lot of cartoony drawings on how electrons move, what resistance, capacitors, transistors do. At their very core, computers are nothing else. Some experiments can be done with a battery and wire.

– Transistors are key. They can switch stuff on and off when applying a smaller current. Like an electronic switch. If you combine multiple of these, you can do logic operations and simple calculations. E.g. both switches have to be on for an LED to light up. Basically just stuff like 0+1 = 1 or 1-1 = 0. You can build that with a bunch of transistors and lights for cents. That doesn’t look very useful, it is the most basic, but if you imagine chaining up hundreds, thousands, millions of transistors, computers can work with complex numbers.

– Computer processors just do this all day. They add, subtract zeros from binary storage. 0010 could stand for the number 4 in some program, it could be a color on your display, anything. And every component of your computer has some memory and processing. E.g. a display has a display driver, cache. And these components know what to do with a certain string of zeros and ones.

– Try Scratch. It’s a programming suite for kids that uses blocks instead of written programming language. You can chain stuff together (e.g. “IF button is pressed” – “move cat.jpg to the right” – “ELSE play meow.mp3”). It’s abstract but understanding programming (IF ELSE actions) will de-mystify a lot of things.

– Try microcontrollers/microcomputers. The very basic computer with memory, inputs, outputs. E.g. Pick up an $10-20 “Arduino” kit or robot. You plug in a small board via USB, and you can tell it to switch things on and off, read inputs (buttons, thermometers, distance sensors). E.g. if the thermometer measures a rising temperature, it displays how hot it is with a chain of 5 LED, or triggers an alarm. This is forms a very basic input-output device. And it is possible to even hook up keyboards, displays.

– Arduino uses a C/C# programming environment, but there are visual programming languages like or based on Scratch (Scratch4Arduino, Blockly…).

– The nice thing is that there are so many examples you can basically just use one of them and try to change a few numbers to see what it does. E.g. reverse the direction of a motor, or the distance a sensor causes a robot to stop.

– With students I made a robot car. Arduino, battery, two motor boards, and a distance sensor. The program was 6 lines of code: “IF distance<20cm -> stop the right wheel for a second”. That’s enough for a car to crudely avoid tables, legs.

Have fun 🙂