Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Background Binary coded decimal (BCD) is a representation scheme used primarily to pre- cisely represent fixed point numbers, usually dollars and cents. As such, it

image text in transcribedimage text in transcribedimage text in transcribed

Background Binary coded decimal (BCD) is a representation scheme used primarily to pre- cisely represent fixed point numbers, usually dollars and cents. As such, it has a long history, dating back to the IBM 360, and still carried out natively in assembly) in many computer systems. Versions exist to represent floating point numbers, as well. Some current systems, such as the ARM, do not support BCD directly. Of course, many applications in business computing still require it. The encoding follows a table (some examples are provided here): Decimal BCD 0 0000 BCD XS3 Aiken BCD 5421 0011 0000 0000 0100 0001 0001 0101 0010 0010 0110 0011 0011 0111 0100 0100 1000 1011 1000 1100 1001 1010 1101 1010 1011 1110 1011 1100 1111 1100 0010 0011 0100 0101 0110 0111 1000 1001 5 9 Note that: For BCD, it is standard to represent decimal numbers in the binary system, where each decimal digit is coded as a sequence of 4 bits. This is sometimes called the "8421" BCD. For BCD XS3, the conversion is done by adding '3' to the decimal number that we want to represent. The XS3 is pronounced as "excess 3" BCD. For Aiken and BCD 5421, the representation is similar to BCD where the "weights" or "values" are distributed differently. Note that the 5421 is the weighting of the bits: 1100 = 1 * 5+1% 4+0 x 2 + 0 x1= 9 - Note that the Aiken weighting of the bits is "4 2 2 1" Other weightings are possible, e.g. "7 4 2 1" The names of the codes sometimes change (as should be clear from our discussion to this point). You must know whether the code is packed" or "unpacked." A packed code will place two 4-bit decimals into one byte, whereas an unpacked code will place only one 4-bit decimal into one byte. Packed codes require the use of masks and shifts. There are many ways to represent the sign of the number. For instance, in BCD, the 1100 code for positive, and the 1101 code for negative are often used. IBM will use the 1010 and 1011 for + and -, respectively. Because the sign requires 4 bits, all BCD numbers will have an odd number of digits, so that the sign with the digits will occupy a full multiple of one byte. For example, a 7 digit number plus the sign will use either 8 bytes for an unpacked BCD, or 4 bytes for a packed BCD. The decimal point is ignored by the code, it must be interpreted by the application. So, for example, a financial program will almost always pro- duce only 2 digits to the "right of the decimal point," and all others are to the left of the decimal point. So, the number 133.27 will use 3 or 6 bytes depending on whether it is packed or unpacked. To do: I want you to: write C-code and native Assembly for the MSP430 to convert an array of signed decimals, with 5 digits before the decimal point and 2 digits after. You should write: packed and unpacked BCD versions You should write the "inverse" code to reproduce the original input to check each of your codes (packed and unpacked). Then, I want you to compare the assembly produced by CCS to your native assembly. - How efficient is your assembly when compared to the CCS-produced assembly? You may also convert your codes to the Aiken or the 5421 codes for extra credit. * Discuss your coding process to make the conversion of your code to the Aiken or 5421 codes easier. * Did you think about this conversion before, or after, you wrote To turn in: 1. C for your subroutines (this must be well-commented) 2. Assembly (native) for your subroutines 3. Assembly listing produced by CCS 4. A discussion of the (relative) efficency of your codes 5. A screen capture showing that your code works properly Background Binary coded decimal (BCD) is a representation scheme used primarily to pre- cisely represent fixed point numbers, usually dollars and cents. As such, it has a long history, dating back to the IBM 360, and still carried out natively in assembly) in many computer systems. Versions exist to represent floating point numbers, as well. Some current systems, such as the ARM, do not support BCD directly. Of course, many applications in business computing still require it. The encoding follows a table (some examples are provided here): Decimal BCD 0 0000 BCD XS3 Aiken BCD 5421 0011 0000 0000 0100 0001 0001 0101 0010 0010 0110 0011 0011 0111 0100 0100 1000 1011 1000 1100 1001 1010 1101 1010 1011 1110 1011 1100 1111 1100 0010 0011 0100 0101 0110 0111 1000 1001 5 9 Note that: For BCD, it is standard to represent decimal numbers in the binary system, where each decimal digit is coded as a sequence of 4 bits. This is sometimes called the "8421" BCD. For BCD XS3, the conversion is done by adding '3' to the decimal number that we want to represent. The XS3 is pronounced as "excess 3" BCD. For Aiken and BCD 5421, the representation is similar to BCD where the "weights" or "values" are distributed differently. Note that the 5421 is the weighting of the bits: 1100 = 1 * 5+1% 4+0 x 2 + 0 x1= 9 - Note that the Aiken weighting of the bits is "4 2 2 1" Other weightings are possible, e.g. "7 4 2 1" The names of the codes sometimes change (as should be clear from our discussion to this point). You must know whether the code is packed" or "unpacked." A packed code will place two 4-bit decimals into one byte, whereas an unpacked code will place only one 4-bit decimal into one byte. Packed codes require the use of masks and shifts. There are many ways to represent the sign of the number. For instance, in BCD, the 1100 code for positive, and the 1101 code for negative are often used. IBM will use the 1010 and 1011 for + and -, respectively. Because the sign requires 4 bits, all BCD numbers will have an odd number of digits, so that the sign with the digits will occupy a full multiple of one byte. For example, a 7 digit number plus the sign will use either 8 bytes for an unpacked BCD, or 4 bytes for a packed BCD. The decimal point is ignored by the code, it must be interpreted by the application. So, for example, a financial program will almost always pro- duce only 2 digits to the "right of the decimal point," and all others are to the left of the decimal point. So, the number 133.27 will use 3 or 6 bytes depending on whether it is packed or unpacked. To do: I want you to: write C-code and native Assembly for the MSP430 to convert an array of signed decimals, with 5 digits before the decimal point and 2 digits after. You should write: packed and unpacked BCD versions You should write the "inverse" code to reproduce the original input to check each of your codes (packed and unpacked). Then, I want you to compare the assembly produced by CCS to your native assembly. - How efficient is your assembly when compared to the CCS-produced assembly? You may also convert your codes to the Aiken or the 5421 codes for extra credit. * Discuss your coding process to make the conversion of your code to the Aiken or 5421 codes easier. * Did you think about this conversion before, or after, you wrote To turn in: 1. C for your subroutines (this must be well-commented) 2. Assembly (native) for your subroutines 3. Assembly listing produced by CCS 4. A discussion of the (relative) efficency of your codes 5. A screen capture showing that your code works properly

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial Accounting An Introduction To Concepts Methods And Uses

Authors: Clyde P. Stickney, Roman L. Weil

8th Edition

0030182689, 978-0030182686

More Books

Students also viewed these Accounting questions

Question

How would you describe the work atmosphere?

Answered: 1 week ago

Question

What are the general types of interviews? Explain each.

Answered: 1 week ago

Question

6 How can HRM contribute to ethical management and sustainability?

Answered: 1 week ago