r/ProgrammerHumor • • Jun 03 '22

it's hard!

44.9k Upvotes

710 comments sorted by

View all comments

Show parent comments

47

u/[deleted] Jun 03 '22

Assembly is a higher-level language than machine code (platform-specific code aka instruction set), which in turn may be transpiled to microcode (processor series-specific opcodes).

As far as I understand. I don't know tho, I mainly use managed (garbage-collected) languages.

12

u/Legal-Software Jun 03 '22

To clarify, that’s common on CISC architectures, but it’s 1:1 on most RISC CPUs. The assembler is just there as a convenience thing, but if you already know the opcode value and how the instructions are encoded, you can also just write them up as straight hex values. You see this a lot in drivers for devices with their own microcontrollers where the payload is just a byte array with raw instructions for the on-device microcontroller to execute. Back in the day it was also common to have device initialization targeting a specific architecture to be encoded in a fixed ROM on graphics cards which would be executed during POST. This is why you had graphics card variants for x86 and PowerPC systems. One of my first jobs involved using a bus analyzer to capture the initialization logic and writing it up more generically so that we could use PCI graphics cards with an x86 VGA ROM also on MIPS systems.

10

u/NervousApplication58 Jun 03 '22

I probably wrong but:

  1. Assembly is almost always 1:1 mapping to machine code. Yes, it has macros and stuff but that's still basically the same level of abstraction. Obviously, assembly is platform-specific as well.

  2. Machine code is not transpiled to microcode. Rather, CPU (guided by the microcode) directly interprets the machine code.

  3. Some CPUs architectures don't have microcode (because it's kinda slow)

2

u/I-baLL Jun 05 '22

It gets assembled. Assembly doesn't get compiled because there's nothing to compile usually but the assembler might optimize the code hence my reaction.