Local Register Allocator for 8086
github.com
github.com
To load a value from memory we need the memory address in one of 3 suitable registers: bx, si, di.
You can use bp too, and for local variables it's the best one, since it defaults to using the stack segment. Adding support for non-movs with memory operands is probably the last step to this algorithm, and with that, its output could fool the majority of people into believing a human wrote the code instead of a compiler.
But we were doing this for 32bit x86, so a lot of the limitations addressed here were not relevant anymore, and our register allocator code was likely far simpler, and probably still less efficient. (It's been at least 10 years now, not sure anymore.)
On a side note, I was surprised when some short time later I looked into Chrome V8's source code, and discovered that it didn't really have a register allocator either. I believe that was quickly addressed (by a new engine actually, if I recall right).
Once all that is done a register allocator starts becoming relevant, and even then you probably want another kind of allocator than is mainstream for lowlevel languages since you might not be doing a full-method compilation or a compilation that shouldn't require a full de-optimization if an divergent type is detected.