• Aucun résultat trouvé

16 Bits’ll Buy You 64K

Dans le document Assembly Language Step-by-Step (Page 115-118)

In 1974, the year I graduated from college, Intel introduced the 8080 CPU and basically invented microcomputing. (Yes, I’m an old guy, but I’ve been blessed with a sense of history—by virtue of having lived through quite a bit of it.) The 8080 was a white-hot little item at the time. I had one that ran at 1 MHz, and it was a pretty effective word processor, which is mostly what I did with it.

The 8080 was an 8-bit CPU, meaning it processed 8 bits of information at a time. However, it had 16 address lines coming out of it. The ‘‘bitness’’ of a CPU—how many bits wide its general-purpose registers are—is important, but to my view the far more important measure of a CPU’s effectiveness is how many address lines it can muster in one operation. In 1974, 16 address lines was aggressive, because memory wasextremelyexpensive, and most machines had 4K or 8K bytes (remember, that means 4,000 or 8,000) at most—and some had a lot less.

Sixteen address lines will address 64K bytes. If you count in binary (which computers always do) and limit yourself to 16 binary columns, you can count from 0 to 65,535. (The colloquial ‘‘64K’’ is shorthand for the number 66,536.) This means that every one of 65,536 separate memory locations can have its own unique address, from 0 up to 65,535.

The 8080 memory-addressing scheme was very simple: you put a 16-bit address out on the address lines, and you got back the 8-bit value that was stored at that address. Note well: there isnonecessary relation between the number of address lines in a memory system and the size of the data stored at each location. The 8080 stored 8 bits at each location, but it could have stored 16 or even 32 bits at each location, and still have 16 memory address lines.

By far and away, the operating system most used with the 8080 was CP/M-80. CP/M-80 was a little unusual in that it existed at thetopof installed memory—sometimes so that it could be contained in ROM, but mostly just to get it out of the way and allow a consistent memory starting point fortransient programs,those that (unlike the operating system) were loaded into memory and run only when needed. When CP/M-80 read a program in from disk to run it, it would load the program into low memory, at address 0100H—that is, 256 bytes from the very bottom of memory. The first 256 bytes of memory were called theprogram segment prefix (PSP) and contained various odd bits of information as well as a general-purpose memory buffer for the program’s

80 Chapter 4 Location, Location, Location

disk input/output (I/O). The executable code itself did not begin until address 0100H.

I’ve drawn the 8080 and CP/M-80 memory model in Figure 4-1.

16-Bit Memory Address

0FFFFH

Top of Installed Memory

0000H 0100H

Program Segment Prefix (PSP)

Transient Program Code

CP/M-80 Operating System

Unused Memory Addresses Without

Installed Memory

Code Execution Begins Here 64K

Often 16K, 32K, or 48K

Figure 4-1: The 8080 memory model

The 8080’s memory model as used with CP/M-80 was simple, and people used it a lot; so when Intel created its first 16-bit CPU, the 8086, it wanted to make it easy for people to translate older CP/M-80 software from the 8080 to the 8086—a process calledporting. One way to do this was to make sure that a 16-bit addressing system such as that of the 8080 still worked. So, even though the 8086 could address 16 times as much memory as the 8080

Chapter 4 Location, Location, Location 81 (16×64K=1MB), Intel set up the 8086 so that a program could take some 64K byte segment within that megabyte of memory and run entirely inside it, just as though it were the smaller 8080 memory system.

This was done by the use ofsegment registers,which are basically memory pointers located in CPU registers that point to a place in memory where things begin, be this data storage, code execution, or anything else. You’ll learn a lot more about segment registers very shortly. For now, it’s enough to think of them as pointers indicating where, within the 8086’s megabyte of memory, a program ported from the 8080 world would begin (see Figure 4-2).

20-Bit Memory Address

0FFFFFH

00000H

64K Memory Segment

IMB

Segment Register CS 080000H

Figure 4-2: The 8080 memory model inside an 8086 memory system

82 Chapter 4 Location, Location, Location

When speaking of the 8086 and 8088, there are four segment registers to consider (again, we’ll be dealing with them in detail very soon). For the purposes of Figure 4-2, consider the register called CS—which stands for code segment. Again, it’s a pointer to a location within the 8086’s megabyte of memory. This location acts as the starting point for a 64K region of memory, within which a quickly converted CP/M-80 program could run very happily.

This was very wise short-term thinking—and catastrophically bad long-term thinking. Any number of CP/M-80 programs were converted to the 8086 within a couple of years. The problems began big-time when programmers attempted to create new programs from scratch that had never seen the 8080 and had no need for the segmented memory model. Too bad—the segmented model dominated the architecture of the 8086. Programs that needed more than 64K of memory at a time had to use memory in 64K chunks, switching between chunks by switching values into and out of segment registers.

This was a nightmare. There is one good reason to learn it, however:

understanding the way real-mode segmented memory addressing works will help you understand how the two x86 flat models work, and in the process you will come to understand the nature of the CPU a lot better.

Dans le document Assembly Language Step-by-Step (Page 115-118)