3 ms·
The instructions that you the user see are in themselves little sequences of code. Think about it this way - you like code reuse, right? DRY? If you want a bit
by Gordonjcp 4y ago
The instructions that you the user see are in themselves little sequences of code. Think about it this way - you like code reuse, right? DRY? If you want a bit of hardware that can add two numbers in registers, why would you want to have another copy of the same thing that can add a value to the program counter? It's just a register, even if it's a bit special.
The thing is, the microcode is often using instructions that are a very different "shape" from sensible machine-code instructions, because quite often they have to drive gates within the chip directly and not all combinations might make sense. So you might have an instruction that breaks down as "load register A into the ALU A port, load register X in the the ALU B port, carry out an ADD and be ready to latch the result into X but don't actually latch it for another clock cycle in case we're waiting for carry to stabilise", much of which you simply don't want to care about. The instructions might be many many bits long, with a lot of those bits "irrelevant" for a particular task.
The 6502 CPU was a directly-wired CPU where everything was decoded from the current opcode. It doesn't really have "microcode" but it does have a state machine that'll carry out instructions in phases across a few clocks. It does actually have a lot of "undefined" instructions, which are where the opcode decodes into something nonsensical like "load X and Y at the same time into the ALU" which returns something unpredictable.