r/computerscience • • May 05 '26

Discussion Real Mode 20 Bits

x86 processors have a mode known as "real mode" where physical memory is straight mapped. So if I'm interpreting what I read correctly an instruction to load the value at location 1000 into a register would fetch the value at the position 1000 in memory and put it into the register. This is limited to 20 bits of addressing. I read this was due to backward compatibility to the 8086 which lacked a protected mode. If a 32-bit processor uses 32 bits for addressing, why would the real mode be 20 bits? If real is for backwards compatibility with older processors, shouldn't it be 16 bits since the 8086 was a 16-bit?

On the advice of a mod, certain information was omitted for posting so my question may be unclear but I hope you can understand.

14 Upvotes

16 comments sorted by

15

u/undercoveryankee May 05 '26

The 8086 was a “16-bit” processor in the sense that the largest integer registers were 16 bits, but it used 20-bit physical memory addresses.

3

u/ShadowGuyinRealLife May 05 '26

Ohhhh Ok thanks, that makes sense. So the successor processor in real mode would use 20 bits of addressing since the 8086 would use 20 bit physical memory address. The address size wasn't the same as the integer register. Thanks for understanding and replying.

4

u/ready_or_not_3434 May 06 '26

Yep, they basically shifted a 16 bit segment register by 4 bits and added an offset. It was a pretty clever hack to hit 1MB of physical memory without needing wider regsters.

0

u/[deleted] May 05 '26

[deleted] — view deleted comment

2

u/ShadowGuyinRealLife May 06 '26

Not that it's too relevant when there are perfectly good languages to use like C, Java, Commons LISP, Haskell, and so on, but how would you say modern x86 Assembly compares to what was used in the past? 20 is not a multiple of 16, but at least 32 is a multiple of 32. Hurray for compilers and interpeters dealing with memory.

→ More replies (1)

2

u/high_throughput May 05 '26

Like people are saying, the developers of the 8086 realized that 64kb would not be enough for both real RAM and memory mapped hardware, so they allowed the chip to use TWO 16-bit values to specify an address.

However, they also realized that 32 bits would be a disgusting waste of traces, so instead of (hi<<16)+lo for a 32-bit address, they used (hi<<4)+lo for a 20-bit address.

This is how the 16-bit CPU was made to access 20-bit addresses using pairs of registers.

Read all about it on https://en.wikipedia.org/wiki/X86_memory_segmentation

1

u/ShadowGuyinRealLife May 27 '26

Would using 32 (or any multiple of 16) bits have any advantages to a machine that only has enough physical memory 20 bit-address? You mentioned 16 wouldn't be enough.  (hi<<16)+lo Has the disadvantage of wasting traces. Does it have any advantages of... I don't know making it easier for compilers (or programmers) to do addressing or anything? Or is the benefit of being a multiple of 16 just something that looks nice but doesn't actually help?

→ More replies (1)
→ More replies (1)

4

u/[deleted] May 05 '26

[removed] — view removed comment

4

u/apnorton Devops Engineer | Post-quantum crypto grad student May 05 '26

For transparency: this post was having some issues with the automod completely killing the post based on keyword filters. And, instead of the usual behavior of "automod deletes the post, but a mod can go in and undelete it," the block was happening prior to the post ever getting created so there was nothing for us to undelete/approve.

Hence, the recommendation to omit a few keywords while we figure out what happened with the automod.