
What’s up with the mysterious inc bp in prologues of 16-bit code? (2011) - userbinator
https://blogs.msdn.microsoft.com/oldnewthing/20110316-00/?p=11203/
======
userbinator
I stumbled across this while searching for something very similar, and found
it very interesting that 16-bit Windows was, while most known for being
cooperatively multitasked, also had what could be called _cooperative virtual
memory_.

~~~
sova
Please elaborate?

~~~
ajross
It's in the article. Windows could unload code segments that weren't running
to free space for other purposes. But those functions might be on a process
call stack. So it used the otherwise irrelevant low bit of the BP register to
store whether a frame was a near or far call, thus allowing the unload code to
fix up the return address to allow for reloading on demand.

~~~
sova
So if I get this right: the stack is limited in size, and certain "frequent
use" routines were labeled as "near" while others with less frequent use were
labeled as "far" and there was a dynamic way to keep frequent ones in memory?

~~~
ajross
It's a 16 bit architecture. Any code that doesn't fit in 64k needs to be in a
separate segment. In practice, the way typical C compilers managed this (there
were a bunch of code generation options) was to put all the code in a single
C/obj file into a separate segment. Calls within the segment were "near" and
used the simple CALL/RET variants which took and pushed a 16 bit address.
Others were "far" and called/returned to a tuple of an address and a segment
descriptor.

------
adamnemecek
God I’m glad that era is over.

------
mikequinlan
From 2011

~~~
bas
The author's book, Old New Thing, is worth a read, even though it was written
years ago.

------
gaius
The incredible ingenuity of those old-skool engineers. Can you imagine modern-
day TDD nodejs “ninjas” trying to solve this problem under these conditions?

~~~
phkahler
I think the better engineers use the MC68000 in their designs and had nothing
to do with this nonsense. I started reading TFA and stopped as soon as I
realized it was about a crummy abstraction that should never have happened.

~~~
mikeash
There’s a saying that anybody can design a bridge that will withstand a load,
but it takes an engineer to design a bridge that will just _barely_ withstand
a load.

In other words, limiting resource usage and cost is the whole point of the
game. Yes, you can solve it by throwing a fancy expensive CPU at it, but
that’s not necessarily good engineering.

~~~
perl4ever
There's also a saying that if a bridge cracks 1/3 of the way through, that is
not a safety factor of 3.

