How many registers does a computer *need*? I read about Why does a processor have 32 registers?, and others. Currently I am messing around with an OS in JavaScript, and wondering how many registers -- or more specifically, how many temporary variable slots -- you need in a computer. How many do you need? Bare minimum, what is theoretically the lower bound? Is it 2? Or is it 8? I read some CPUs had 8 at one point, why did they switch to 32 or more these days? I wonder if you can get by with only 2 registers for all computation. If so, is it very inefficient or something? These are all aspects of the main question.

As a tangent question as to why they need $X$ number, what is the ideal number of registers and why? Is there even an ideal? If not a specific number, what is a measure of idealness when it comes to figuring out how many registers your OS simulator should have. I want to avoid "unlimited" registers if at all possible, since that isn't realistic in actual hardware.
You need to make your question a bit more precise.

First, regarding your request to avoid "unlimited" registers -- I assume you mean registers that can hold an arbitrary value (e.g., any natural number).

If you a-priori bound your registers, then the possible states your machine can be in is finite. That is, you have a deterministic finite automaton (or transducer, if you allow inputs and outputs). In this case, you don't need any register, but the machine would be huge without them. For example, you can replace 32 binary registers with $2^{32}$ states.

If you do allow arbitrary values, then 2 counters suffice to simulate a Turing Machine using a Minsky Counter Machine, under certain assumptions.