<< Chapter < Page | Chapter >> Page > |
For example, we interpret an 8-bit binary word as an integer in the 2's complement representation, and ranges from ( ) to ( ). Several examples:
binary | decimal |
---|---|
00000000 |
0 |
00000001 |
1 |
01000000 |
64 |
01111111 |
127 |
10000000 |
-128 |
10000001 |
-127 |
11000000 |
-64 |
11111111 |
-1 |
When is a positive (negative) number in 2's complement format, can be found by inverting each bit and adding . For example, is in decimal and is found by first inverting the bits to obtain and adding , thus is as shown in the above table. Because the MSB indicates the sign of the numberrepresented by the binary word, we call this bit the sign bit . If the sign bit is 0, the word represents positive number, while negative numbers have 1as the sign bit.
In 2's compliment representation, subtraction of two integers can be accomplished by usual binary summation bycomputing as . We investigate the operations on the 2's compliment numbers later . However, when you add two 2's complement numbers, you must keep in mind that the 1 inMSB is actually -1.
(2's complement): What are the decimal numbers corresponding to the 2's complement 8-bit binarynumbers; , , , and ?
Intentionally left blank.
Sometimes, you need to convert an 8-bit 2's complement number to a 16-bit number. What is the 16-bit 2's complementnumber representing the same value as the 8-bit numbers and ? The answer is and . For nonnegative numbers (sign bit = 0), you simply addenough 0's to extend the number of bits. For negative numbers, you add enough 1's. This operation is called sign extension . The same rule holds for extending a 16-bit 2's complement number to a 32-bit number.
For the arithmetic assembly instructions, C62x CPU has
different versions depending on how it handles the signs.For example, the load instructions
LDH
and
LDB
load halfword and byte value to
a 32-bit register with sign extension. That is, the loadedvalues are converted to 32-bit 2's complement number and
loaded into a register. The instructions
LDHU
and
LDBU
do
not perform sign extension. They simply fill zeros for theupper 16- and 24-bits, respectively.
For the shift right instructions
SHR
and
SHRU
, the same rule applies. The
ADDU
instruction simply treats the
operands as unsigned values.
Although using 2's compliment integers we can implement both addition and subtraction by usual binary addition (withspecial care for the sign bit), the integers are not convenient to handle to implement DSP algorithms. Forexample, If we multiply two 8-bit words together, we need 16 bits to store the result. The number of required wordlength increases without bound as we multiply numbers together more. Although not impossible, it is complicatedto handle this increase in word-length using integer arithmetic. The problem can be easily handled by usingnumbers between and , instead of integers, because the product of two numbers in are always in the same range.
Notification Switch
Would you like to follow the 'Finite impulse response' conversation and receive update notifications?