<< Chapter < Page Chapter >> Page >
Two's-complement notation is a mathematically convenient way of representing signed numbers in microprocessors. The most significant bit of a two's complement number represents its sign, and the remaining bits represent its magnitude. Fractional arithmetic allows one to multiply numbers on an integer processor without incurring overflow. Fractional arithmetic requires sign-extension of multipliers and multiplicands, and it requires the product of two numbers to be left-shifted one bit.

Two's-complement notation

Two's-complement notation is an efficient way of representing signed numbers in microprocessors. It offers theadvantage that addition and subtraction can be done with ordinary unsigned operations. When a number is written intwo's complement notation, the most significant bit of the number represents its sign: 0 means that the number ispositive, and 1 means the number is negative. A positive number written in two's-complement notation is the same as thenumber written in unsigned notation (although the most significant bit must be zero). A negative number can bewritten in two's complement notation by inverting all of the bits of its absolute value, then adding one to the result.

Consider the following four-bit two's complement numbers (in binary form):

1 0001 -1 1110 1 1111
2 0010 -2 1101 1 1110
6 0110 -6 1001 1 1010
8 1000 -8 0111 1 1000

1000 represents -8, not 8. This is because the topmost bit (the sign bit) is 1, indicating that the number isnegative.

The maximum number that can be represented with a k -bit two's-complement notation is 2 k-1 1 , and the minimum number that can be represented is -2 k-1 . The maximum integer that can be represented in a 16-bit memory register is 32767, and the minimum integer is-32768.

Fractional arithmetic

The DSP microprocessor is a 16-bit integer processor with some extra support for fractional arithmetic. Fractional arithmetic turns out to be very useful for DSP programming, since it frees us from worries about overflow onmultiplies. (Two 16-bit numbers, multiplied together, can require 32 bits for the result. Two 16-bit fixed-pointfractional numbers also require 32 bits for the result, but the 32-bit result can be rounded into 16 bits while onlyintroducing an error of approximately 2 -16 .) For this reason, we will be using fixed-point fractional representation to describe filter taps and inputs throughout this course.

Unfortunately, the assembler and debugger we are using do not recognize this fractional fixed-point representation. For thisreason, when you are using the assembler or debugger, you will see decimal values (ranging from -32768 to 32767) on screeninstead of the fraction being represented. The conversion is simple; the fractional number being represented is simply thedecimal value shown divided by 32768. This allows us to represent numbers between -1 and 1 2 -15 .

1 cannot be represented exactly.

When we multiply using this representation, an extra shift left is required. Consider the two examplesbelow:

fractional 0.5 0.5 0.25
decimal 16384 16384 4096 2 16 : 4096/32768 1/8
hex 4000 4000 1000 2 16
fractional 0.125 0.75 0.093750
decimal 4096 24576 1536 2 16 : 1536/32768 0.046875
hex 1000 6000 0600 2 16

You may wish touse the MATLAB commands hex2dec and dec2hex . When we do the multiplication, we are primarily interested inthe top 16 bits of the result, since these are the data that are actually used when we store the result back into memoryand send it out to the digital-to-analog converter. (The entire result is actually stored in the accumulator, sorounding errors do not accumulate when we do a sequence of multiply-accumulate operations in the accumulators.) As theexample above shows, the top 16 bits of the result of multiplying the fixed point fractional numbers together ishalf the expected fractional result. The extra left shift multiplies the result by two, giving us the correct finalproduct.

The left-shift requirement can alternatively be explained by way of decimal place alignment. Remember that when wemultiply decimal numbers, we first multiply them ignoring the decimal points, then put the decimal point back in the laststep. The decimal point is placed so that the total number of digits right of the decimal point in the multiplier andmultiplicand is equal to the number of digits right of the decimal point in their product. The same applies here; the"decimal point" is to the right of the leftmost (sign) bit, and there are 15 bits (digits) to the right of this point. Sothere are a total of 30 bits to the right of the decimal in the source. But if we do not shift the result, there are 31bits to the right of the decimal in the 32-bit result. So we shift the number to the left by one bit, which effectivelyreduces the number of bits right of the decimal to 30.

Before the numbers are multiplied by the ALU, each term is sign-extended generating a 17-bit number from the 16-bit input. Because the examples presented above are allpositive, the effect of this sign extension is simply adding an extra "0" bit at the top of the register( i.e. , positive numbers are not affected by the sign extension). As the following example illustrates,not including this sign-bit for negative numbers produces erroneous results.

fractional -0.5 0.5 -0.25
decimal 49152 16384 12288 2 16 : 12288/32678 0.375
hex C000 4000 30000000 3000 2 16

Note that even after the result is left-shifted by one bit following the multiply, the top bit of the result is still"0", implying that the result is incorrectly interpreted as a positive number.

To correct this problem, the ALU sign-extends negative multipliers and multiplicands by placing a "1" instead of a"0" in the added bit. This is called sign extension because the sign bit is "extended" to the left another place, addingan extra bit to the left of the number without changing the number's value.

fractional -0.5 0.5 -0.25
hex 1C000 4000 70000000 7000 2 16

Although the top bit of this result is still "0", after the final 1-bit left-shift the result is E000 000h which is a negative number (the top bit is "1"). To check the final answer, we can negate the product using the two'scomplement method described above. After flipping all of the bits we have 1FFF FFFFh , and adding one yields 2000 0000h , which equals 0.25 when interpreted as an 32 bit fractional number.

Questions & Answers

A golfer on a fairway is 70 m away from the green, which sits below the level of the fairway by 20 m. If the golfer hits the ball at an angle of 40° with an initial speed of 20 m/s, how close to the green does she come?
Aislinn Reply
cm
tijani
what is titration
John Reply
what is physics
Siyaka Reply
A mouse of mass 200 g falls 100 m down a vertical mine shaft and lands at the bottom with a speed of 8.0 m/s. During its fall, how much work is done on the mouse by air resistance
Jude Reply
Can you compute that for me. Ty
Jude
what is the dimension formula of energy?
David Reply
what is viscosity?
David
what is inorganic
emma Reply
what is chemistry
Youesf Reply
what is inorganic
emma
Chemistry is a branch of science that deals with the study of matter,it composition,it structure and the changes it undergoes
Adjei
please, I'm a physics student and I need help in physics
Adjanou
chemistry could also be understood like the sexual attraction/repulsion of the male and female elements. the reaction varies depending on the energy differences of each given gender. + masculine -female.
Pedro
A ball is thrown straight up.it passes a 2.0m high window 7.50 m off the ground on it path up and takes 1.30 s to go past the window.what was the ball initial velocity
Krampah Reply
2. A sled plus passenger with total mass 50 kg is pulled 20 m across the snow (0.20) at constant velocity by a force directed 25° above the horizontal. Calculate (a) the work of the applied force, (b) the work of friction, and (c) the total work.
Sahid Reply
you have been hired as an espert witness in a court case involving an automobile accident. the accident involved car A of mass 1500kg which crashed into stationary car B of mass 1100kg. the driver of car A applied his brakes 15 m before he skidded and crashed into car B. after the collision, car A s
Samuel Reply
can someone explain to me, an ignorant high school student, why the trend of the graph doesn't follow the fact that the higher frequency a sound wave is, the more power it is, hence, making me think the phons output would follow this general trend?
Joseph Reply
Nevermind i just realied that the graph is the phons output for a person with normal hearing and not just the phons output of the sound waves power, I should read the entire thing next time
Joseph
Follow up question, does anyone know where I can find a graph that accuretly depicts the actual relative "power" output of sound over its frequency instead of just humans hearing
Joseph
"Generation of electrical energy from sound energy | IEEE Conference Publication | IEEE Xplore" ***ieeexplore.ieee.org/document/7150687?reload=true
Ryan
what's motion
Maurice Reply
what are the types of wave
Maurice
answer
Magreth
progressive wave
Magreth
hello friend how are you
Muhammad Reply
fine, how about you?
Mohammed
hi
Mujahid
A string is 3.00 m long with a mass of 5.00 g. The string is held taut with a tension of 500.00 N applied to the string. A pulse is sent down the string. How long does it take the pulse to travel the 3.00 m of the string?
yasuo Reply
Who can show me the full solution in this problem?
Reofrir Reply
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Dsp laboratory with ti tms320c54x. OpenStax CNX. Jan 22, 2004 Download for free at http://cnx.org/content/col10078/1.2
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Dsp laboratory with ti tms320c54x' conversation and receive update notifications?

Ask