<< Chapter < Page Chapter >> Page >

(Q format addition, subtraction): Perform the additions 01001101 11100100 , and 01111001 10001011 when the binary numbers are Q-7 format. Also compute 01001101 11100100 and 10001011 00110111 . In which cases, do you have overflow?

Intentionally left blank.

Multiplication

Multiplication of two 2's complement numbers is a bit complicated because of the sign bit. Similar to themultiplication of two decimal fractional numbers, the result of multiplying twoQ- N numbers is Q- 2 N , meaning that we have 2 N binary digits following the implied binary digit. However, depending on the numbers multiplied, theresult can have either 1 or 2 binary digits before the binary point. We call the digit right before the binarypoint the sign bit and the one proceeding the sign bit (if any) the extended sign bit .

The following is the two examples of binary fractional multiplications:

0.110 0.75 Q-3 X 1.110 -0.25 Q-3-------------------------- 00000110 01101010 -------------------------------1110100 -0.1875 Q-6

Above, all partial products are computed and represented in Q-6 format for summation. For example, 0.110*0.010 =0.01100 in Q-6 for the second partial product. For the 4th partial product, caremust be taken because in 0.110*1.000 , 1.000 represents -1 , so the product is -0.110 = 1.01000 (in Q-6 format) that is 2's complement of 0.11000 . As noticed in this example, it is important to represent eachpartial product in Q-6 (or in general Q- 2 N ) format before adding them together. Another example makes this point clearer:

1.110 -0.25 Q-3 X 0.110 0.75 Q-3------------------------- 0000111110 111100000 -----------------------------11110100 -0.1875 Q-6

For the second partial product, we need 1.110*0.010 in Q-6 format. This is obtained as 1111100 in Q-6 (check!). A simple way to obtain it is to first perform themultiplication in normal fashion as 1110*0010 = 11100 ignoring the binary points, then perform sign extension by putting enough 1s (if the result is negative) or 0s (if the result isnonnegative), then put the binary point to obtain a Q-6 number. Also notice that we need to remove the extra signbit to obtain the final result.

In C62x, if we multiply two Q-15 numbers using one of multiply instruction (for example MPY ), we obtain 32 bit result in Q-30 format with 2 sign bits. To obtain the result back inQ-15 format, (i) first we remove 15 trailing bits and (ii) remove the extended sign bit.

(Q format multiplication): Perform the multiplications 01001101*11100100 , and 01111001*10001011 when the binary numbers are Q-7 format.

Intentionally left blank.

Assembly language implementation

When A0 and A1 contain two 16-bit numbers in the Q-15 format, we can perform the multiplications using MPY followed by a right shift.

1 MPY .M1 A0,A1,A2 2 NOP3 SHR .S1 A2,15,A2 ;lower 16 bit contains result 4 ;in Q-15 format

Rather than throwing away the 15 LSBs of the multiplication result by shifting, you can round up the result by adding 0x4000 before shifting.

1 MPY .M1 A0,A1,A2 2 NOP3 ADDK .S1 4000h,A6 4 SHR .S1 A2,15,A2 ;lower 16 bit contains result5 ;in Q-15 format

C language implementation

Let's suppose we have two 16-bit numbers in Q-15 format, stored in variable x and y as follows:

short x = 0x0011; /* 0.000518799 in decimal */ short y = 0xfe12; /* -0.015075684 in decimal */short z; /* variable to store x*y */

The product of x and y can be computed and stored in Q-15 format as follows:

z = (x * y) >> 15;

The result of x*y is a 32-bit word with 2 sign bits. Right shifting it by 15 bits ignores the last15 bits, and storing the shifted result in z that is a short variable (16 bit) removes the extended sign bit by taking only lower 16 bits.

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Finite impulse response. OpenStax CNX. Feb 16, 2004 Download for free at http://cnx.org/content/col10226/1.1
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Finite impulse response' conversation and receive update notifications?

Ask