0

I heard that the 8086 has 16-bit registers which allow it to only address 64K of memory. Yet it is still able to address 1MB of memory which would require 20-bit registers. It does this by using another register to to hold another 16 bits, and then adds the value in the 16-bit registers to the value in this other register to be able to generate numbers which can address up to 1MB of memory. Is that right?

Why is it done this way? It seems that there are 32-bit registers, which is more than sufficient to address 1MB of memory.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
node ninja
  • 31,796
  • 59
  • 166
  • 254

5 Answers5

1

Actually this has nothing to do with number of registers. Its the size of the register which matters. A 16 bit register can hold up to 2^16 values so it can address 64K bytes of memory.

To address 1M, you need 20 bits (2^20 = 1M), so you need to use another register for the the additional 4 bits.

jman
  • 11,334
  • 5
  • 39
  • 61
1

The segment registers in an 8086 are also sixteen bits wide. However, the segment number is shifted left by four bits before being added to the base address. This gives you the 20 bits.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
  • Instead of shifting and adding why not just use 4 bits from the segment register to make 20 bits? – node ninja Aug 29 '11 at 23:40
  • It uses all 16 bits from the segment register: `DS:[AX]` does (DS<<4)+AX. Don't ask me why they did that. They fixed it in the 80286, which had segmented virtual memory and uses the segment registers to index into a segment table. – John Saunders Aug 29 '11 at 23:51
1

the 8088 (and by extension, 8086) is instruction compatible with its ancestor, the 8008, including the way it uses its registers and handles memory addressing. the 8008 was a purely 16 bit architecture, which really couldn't address more than 64K of ram. At the time the 8008 was created, that was adequate for most of its intended uses, but by the time the 8088 was being designed, it was clear that more was needed.

Instead of making a new way for addressing more ram, intel chose to keep the 8088 as similar as possible to the 8008, and that included using 16 bit addressing. To allow newer programs to take advantage of more ram, intel devised a scheme using some additional registers that were not present on the 8008 that would be combined with the normal registers. these "segment" registers would not affect programs that were targeted at the 8008; they just wouldn't use those extra registers, and would only 'see' 16 addres bits, the 64k of ram. Applications targeting the newer 8088 could instead 'see' 20 address bits, which gave them access to 1MB of ram

SingleNegationElimination
  • 151,563
  • 33
  • 264
  • 304
  • Why not just use 4 additional bits of the segment register? It seems wasteful to use all 16 bits and then add them together to create a 20-bit value. – node ninja Aug 29 '11 at 21:41
  • Beginning with the 80386, that's exactly what happens in "Unreal Mode". The 16<<4 + 16 nature of "real mode" on earlier processors facilitates an easier migration path between 16 bit and real mode code. The segment registers could be loaded with a segment that happens to contain the 64k of ram most appropriate to a particular 16 bit program, with lots of options for overlapping segment regions when a program doesn't actually need the full 64k. Modern MMUs fulfil a similar function on current processor technology. – SingleNegationElimination Aug 29 '11 at 22:50
0

I heard that the 8086 has 16 registers which allow it to only address 64K of memory. Yet it is still able to address 1MB of memory which would require 20 registers.

You're misunderstanding the number of registers and the registers' width. 8086 has eight 16-bit "general purpose" registers (that can be used for addressing) along with four segment registers. 16-bit addressing means that it can only support 216 B = 64 KB of memory. By getting 4 more bits from the segment registers we'll have 20 bits that can be used to address a total of 24*64KB = 1MB of memory

Why is it done this way? It seems that there are 32 registers, which is more than sufficient to address 1MB of memory.

As said, the 8086 doesn't have 32 registers. Even x86-64 nowadays don't have 32 general purpose registers. And the number of registers isn't relevant to how much memory a machine can address. Only the address bus width determines the amount of addressable memory

At the time of 8086, memory is extremely expensive and 640 KB is an enormous amount that people didn't think that would be reached in the near future. Even with a lot of money one may not be able to get that large amount of RAM. So there's no need to use the full 32-bit address

Besides, it's not easy to produce a 32-bit CPU with the contemporary technology. Even 64-bit CPUs today aren't designed to use all 64-bit address lines

It'll takes more wires, registers, silicons... and much more human effort to design, debug... a CPU with wider address space. With the limited transistor size of the technology in the 70s-80s that may not even come into reality.

phuclv
  • 37,963
  • 15
  • 156
  • 475
  • I'm pretty sure the OP meant 16-bit, 20-bit, and 32-bit. The question makes sense then, and the misunderstanding is that 8086 didn't have 32-bit registers, that came later. If they thought that 20 was a count, it wouldn't make sense for them to say that 20 registers would allow you to address 1MB. (Unless they were parroting something they completely misunderstood?) – Peter Cordes Jun 03 '19 at 09:25
0

8086 doesn't have any 32-bit integer registers; that came years later in 386 which had a much higher transistor budget.

8086's segmentation design made sense for a 16-bit-only CPU that wanted to be able to use 20-bit linear addresses.

Segment registers could have been only 8-bit or something with a larger shift, but apparently there are some advantages to fine-grained segmentation where a segment start address can be any 16-byte aligned linear address. (A linear address is computed from (seg << 4) + off.)

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847