• 13 Posts
  • 572 Comments
Joined 1 year ago
cake
Cake day: April 18th, 2025

help-circle







  • Assemblers can come from the CPU manufacturer, but they can also come from a third party. They’re most often bundled into the compiler, since it’s rare to need to compile without also assembling (many compilers skip the assembly step and convert directly to machine code). There’s actually a third tool involved I didn’t mention, which is a Linker (takes pieces of machine code and combines them together, so you can separate your software into different parts).

    Some CPUs are more niche, and the assemblers/compilers for them sometimes are created by the manufacturer. But there are a few “standard” processor architectures that many CPUs follow, and because they’re common between many brands of CPU (and the architectures are published and well known), the compilers are often created by third parties. And there are some compilers (like gcc) that can compile to dozens of different architectures.

    As an example, you might have heard terms like x86, x86_64, armv7, or RISC-V – these are all processor “architectures”, which means that any processor that meets a particular architecture can run machine code built for that architecture. Currently, x86/64 architectures are common among desktops and most laptops (Intel and AMD processors), while ARM architectures are common for tablets and phones and some laptops (Snapdragon processors, for example).


  • It might be helpful to understand the connection between hardware and software better. There are various ways we can create something that a machine can interpret that have evolved over time. We group these into “generations.”

    Generation 1: writing machine code directly. Either using things like punch cards, or typing in the 1s and 0s directly (more likely hex code, but close enough). This is difficult and error prone, because it’s hard for us to make sense of it. So we came up with…

    Generation 2: human-readable machine instructions (aka assembly). We write code in something that’s easier for us to understand, but it’s still explicit instructions to the processor. Then we use a software tool (an assembler) to convert that to machine code. Assembly is still specific to the processor and requires knowledge of exactly what registers are available and such. And then we thought: what if we could write software in a generic way that could work on any processor? So we came up with…

    Generation 3: procedural code. With this, we create a new language that is independent of any processor, which means we’re not giving direct instructions anymore. Instead, we specify a general procedure, and that generic code is passed through a new tool (a compiler) which converts the generic code to processor-specific instructions. When people say “I’m a programmer” they usually mean Gen 3 programming.

    There are additional generations, but this should help provide a background as to why a language like C exists and how it relates to the actual hardware.

    A statement like while (1) might not seem terribly elegant, but that’s because it probably wasn’t anticipated to be a common use case when the language was created. A normal while loop would likely be converted into something like a jnz (jump if not zero) instruction, checking the result of the argument, but any modern compiler would likely convert while(1) to a simple jmp (jump, no conditions) instruction.

    I understand your fascination with the point where software and hardware meet. I did my undergrad in electrical engineering, and there was one class where we used a simulator to take transistors (the simplest eletrical “switches”), build logic gates from the transistors, then build processor components like registers and a math processor from the logic gates, then finally a simple calculator out of those components. Super cool.





  • You might be able to use something like distrobox instead of a full VM. That would at least put it in a container that you could either run from an encrypted partition or something.

    Different users would be the “simple” way you’d normally do something like this under Linux. But if your regular users have sudo access, you can’t really lock anything down.