Echo #03
31 марта 1997 |
|
Book - Secrets ZX-Spectrum: Computer Arithmetic.
Chapter 4. C O M P L U T E R N A Z A & R O M E T I K A The unit cell of computer memory Presented at the processor Z80, locates in imagine a single word (B), consisting of 8 digits, each of which can be either 0 or 1. The transition from the binary representation to a decimal is very simple. We write down a number of at a time of 2 ^ 7 2 ^ 6 ,..., 2 ^ 1 2 ^ 0. Then, under each of these numbers, we write single-digit binary representation. Adding together only the number of the upper number under which turned out to be unity, we get the decimal value. For example, the binary number 01001101: 128 64 32 16 8 4 2 1 0 1 0 0 1 1 0 1 ---------------------- 64 8 4 1 = 77 Contents of memory (bytes) can be a positive number between 0 ... 255. Sometimes advantageous to consider these numbers the values of the sign. MSB (leftmost bit) determines the sign of 0, if +, 1 if -. In this interpretation we have the numbers in the range -128 ... 127. However, the computer always executes act only on the natural numbers without sign. Therefore, the ZX-SPECTRUM is used to represent numbers add up to code two. Numbers less than zero are recorded in it as 256 + K. For example, the number of -7 represented as 256-7 = 249. In this system, the most significant bit is interpreted as a sign of a number. Therefore, the problems associated with the arithmetic does not exist. Main arithmetic lead to accurate results regardless of the choice of ways of writing numbers. For example, 246 +1 = 247 is the obvious equation for unsigned numbers, but it is also true equality if considered as 246 -7, since then 247 = 256 + (-6) denotes -6. Using such small numbers is not enough, so large numbers are to be stored in multiple bytes, following one another. In the ZX-SPECTRUM important the role played by the 16-digit number (16 bits). Their figures are divided into 2 groups of 8 bits. Left byte is called the highest, and the right junior. In all computers, organized by Z80, adopted a rule that if two successive byte addresses X, X +1 contain any number, then X is located under the address low byte, and X +1 - Senior. To determine how many contain the cells, must be the most significant byte is multiplied by 256 and add a junior. If this should be a negative number represented in the code two's complement something else subtract 2 ^ 16 = 65536. The 16-bit numbers can store numbers in the range 0 .. 65535 (Unsigned) or -32728 ... 32727 (signed). When programming in machine code often necessary to perform various operations on bits. Using decimal representation in this difficult, and the binary is too cumbersome. Therefore, the most convenient is the 12th record. To record a 16-hexadecimal numbers (geksodetsimalnyh) use the numbers 0 through 9 and letters A through F (10 - a A, 11 B, 12 - C, 13 - D, 14 - E, 15 - F). Recalculation of the 16-hexadecimal representation of 10-ary not difficult. Rule: multiply the next digit to the next level of number 16 and folding the product. For example, 16-decimal number FFFF is represented as: 15 * 16 ^ 3 +15 * 16 ^ 2 +15 * 16 ^ 1 +15 * 16 ^ 0 = 15 * 4096 + +15 * 256 +15 * 16 +15 = 65535 The transition from binary form to a 16-symmetric and back is particularly simple. Divide the number of binary digits into groups of 4 bits and each Four represent the 16-hexadecimal digit. For example, 1001111110 = 0010 0111 1110 = 27E. As can be seen, the main advantage 16 hexadecimal numbers is the ease of transition to a binary representation and vice versa, while high-density recording. Next 16-decimal number will be preceded by # sign. Ways to encode large numbers and floating point numbers for different computers are different. In the ZX-BASIC all numbers are stored in 5 consecutive bytes. Integers in the range -65536 ... 65535 are encoded differently than the other. The first byte in their view is always 0. The last byte of a positive number is 0, and negative 255. In the third and fourth, respectively, will accommodate junior and senior bytes of numbers, negative values are stored in the code add up to 2. For example, the number 38 looks like this: 0 0 0 38 0, and the number 743 = 2 * 256 +231 has the form: 0 0 231 2 0. In turn, the number -1231 is written as 0 255251 49 0, since 256 * 251 +49 = 65536-1231. With the other numbers are all still confusing more. Used the fact that every number can be uniquely represented in the form: 2 ^ N * M, where M - number in the range [1 / 2, 1]. In the first byte of the ZX-SPECTRUM stores the value N +128. In the other 4 placed the number of M in binary form, or rather M * 2 ^ 32, so that the most significant bit, which should always be equal to 1, is used to store the sign. One means negative, and zero - plus. Assume that five consecutive memory cells contain the number 130 212 16 34 178. They are interpreted as a number: -2 ^ (150-128) * (212 / 2 ^ 8 +16 / 2 ^ 16 +34 / 2 ^ 24 + 178 / 2 ^ 32) and bytes 106 112 4 231 78 represent number: 2 ^ (106-128) * ((128 +112) / 2 ^ 8 +4 / 2 ^ 16 +231 / / 2 ^ 24 +78 / 2 ^ 32). The advantage of high-level languages (in including the ZX-BASIC) is that Software released by records represent different numbers in memory.
Other articles:
Similar articles:
В этот день... 21 November