• Keine Ergebnisse gefunden

Hexadecimal numbers

Im Dokument been In (Seite 92-97)

dull subject of number systems had been segregated into a sepa-rate chapter at the beginning of the book, you probably would have skipped it. Shame on you!

Hexadecimal numbers

When the ancients first began counting, they should have started counting on their fingers. Unfortunately, they counted on their fingers and thumbs. As a result, we are raised on the base ten (decimal) number system, and seem to feel that it is "natural."

This is not true. Decimal numbers feel natural to us only because we grew up with them. Things in nature occur naturally in powers of two. Amoebas multiply by splitting in half, so successive generations include 1, 2, 4, 8, 16, . . . members. We have re-cently been looking at binary, octal, and hex numbers. These are based, obviously, on members of the series above: 2, 8, and 16. If early humankind had counted on fingers only, and used thumbs as pointers, we might have started out with hexadecimal numbers.

Hold your hands up in front of your face, with the thumbs tucked out of sight away from you, and there you have our eight-bit byte (Fig. 7-1) expressed as two four-finger hexadecimal digits!

78 Assembly Language Programming

What could be more natural than that? By curling up fingers to represent zero, and leaving them extended to represent one, we can easily duplicate the binary pattern of any eight-bit byte. This naturally separates into two four-bit groups, our two hex digits. Be careful when you express 24H this way.

Since hex numbers are so natural, you'd think you would have been using them all your life. Surprise! You have been. All we are doing here is introducing new symbols to express each increment in a base 16 number system. You have been using a base 16 device for a large part of your life.

While decimal numbers seem natural to us, the fractions we used in grammar school actually are natural. The familiar inexpen-sive ruler has each major division (one inch) divided into 16 small-est divisions, and these are multiplied by 2, 4, and 8 for intermedi-ate divisions. Naturally.

FIGURE 7-3. This fictitious "hexadecimal ruler" helps the newcomer to the base-sixteen number system visualize relationships within hex numbers. In hex, eight is half of ten, and four plus C is ten. Similarly, it can be easily seen that A plus 3 is D, etc.

1/8 1/4 1/2 3/4

Assembly Language Programming 79 While it is stretching the truth just a bit to claim that hex numbers are the same as fractions, you can see from the illustration of the "hex ruler" that it is easy to learn the basic relationships in hexadecimal. Eight in hex is half of 10 (SH

+

SH = 10H). Similar-ly, 4H is a quarter, and OCH is three-quarters of 10H. Looking now at Table 7-1, we see the reason for this discussion. We use hex numbers as memory addresses, and speak of blocks of memory in terms of K bytes. Earlier we defined 1K as 1024 bytes, and men-tioned that 1024 is two raised to the tenth power. Two raised to the eighth power is 256, and is the largest number that can be ex-pressed with eight bits.

You should be able to see, now, how natural all these relation-ships are using hex numbers. Looking at Table 7-1, the relations between memory size in K bytes and the equivalent hex addresses form simple sequences. The only complicated numbers in the table are those silly decimals. Because they are not natural numbers.

Just as on the hexadecimal ruler where eight was half of 10, we can see from Table 7-1 that SOOOH is half of our total memory address space. Since we begin mapping our memory address space TABLE 7-1. Some common memory segment addresses

expressed in different number systems: the xx K byte shorthand;

decimal equivalents; and hexadecimal notation.

K Bytes Decimal Hexadecimal

64K 65536 10000H

48K 49152 COOOH

32K 32768 8000H

16K 16384 4000H

8K 8192 2000H

4K 4096 1000H

3K 3072 COOH

2K 2048 800H

lK 1024 400H

Y2K 512 200H

Y4K 256 100H

YaK 128 80H

80 Assembly Language Programming

at location OOOOH, our top address is FFFFH. If we counted from one up, our top address would have been 10000H, similarly to how we count from one to 10. In decimal, five is half of 10, and 50,000 is half of 100,000. In hex, 8H is half of 10H, and 8000H is half of 10000H. The other fractions work out just as nicely.

Referring back to Fig. 7-2 and Table 7-1 as we discuss memo-ry addresses in future chapters will help you establish a feeling for hexadecimal, without the need for the usual rigorous discussions of number theory. That you probably wouldn't read anyway.

The 8080

Microprocessor

And Its Relatives

Version 2 (of anything) is the first version that works.

Anonymous

The CP/M operating system executes on any of a number of differ-ent computers. These computers do not all have the same CPU chip inside. There are a number of microprocessors that will ex-ecute the same instruction set as the original Intel 8080, but also add new opcodes of their own. Any of these ICs can be used as the CPU in a computer running CP/M, since the operating system was itself written using only the standard 8080 instructions.

Anyone writing programs to execute within the CP/M en-vironment should restrict his selection of instructions to those com-patible with the 8080. In this chapter we will be looking at the features of the 8080 and its descendants, and will see what we must do to maintain program portability.

81

Im Dokument been In (Seite 92-97)