← Back to context

Comment by bowsamic

1 year ago

Yeah the issue is that the pedagogy doesn’t make it clear how to bridge the “calculator” with the OS stuff. I had this issue when I was a kid. How does adding eventually make something draw on the screen? Of course, it doesn’t, you need some hardware or OS specific information

It wasn't until I read Petzold's CODE that this stuff, especially the role of the the motherboard bridging processing, memory and I/O and what an OS is for, that it started to click for me.

  • Yeah my stepdad bought me CODE as a kid and that really helped. A similar book that took a "top down" approach as much as possible would have also helped though, but would be much harder to pull off

But if this doesn't satisfy your curiosity, you might realize this is just pushing the magic blackbox/question mark a little further down the chain

How does the OS and the hardware draw on the screen, actually? All they have is also just calculator stuff, super basic primitives. You can't even do loops in hardware, or even real branches (hardware always "executes both sides" of a branch at once)

Anyways, if you keep digging long enough you eventually end up finding this XKCD https://xkcd.com/435/ =)

  • > hardware always "executes both sides" of a branch at once

    Unless you're talking about quantum hardware, that is very much not true. The whole point of transistors is to choose whether to power one part of a circuit or another.

    Plus, even for hardware, the solution to all this is to modularize all the way down. One piece of hardware sets up the right state and powers up another piece of hardware - this type of logic doesn't stop at the OS level. For drawing on the screen, ultimately you reach a piece of hardware that lights up in one of three colors based on that state - but all the way there, it's the same kind of "function calls" (and even more indirection, such as communication protocols) on many levels.

    • At least in CMOS, the power supplied to the transistor is not being modulated as part of logic operations. Modern hardware does clock gating and power gating of modules for power saving, but that is not what the OP is talking about.

      In hardware the equivalent of a ternary is a mux, which can be made from a lot of parallel instances of

         out0 = (a0 & cond) | (b0 & ~cond)
      

      Or in other words, both branches must be computed and the correct value is chosen based on the condition.

      4 replies →

    • At least for classic textbook CPUs, it's common to run both sides of a decision in parallel while it's still being made, then finally use a transistor to select the desired result after the fact. No one wants the latency of powering everything up and down every cycle, except on the largest scales where power consumption makes a big difference.

      3 replies →