Question: WRITE THE FUNCTION DESCRIBED IN SECTION 5.8 AND A MAIN ROUTINE TO TEST IT. 5.8 A FUNCTION TO PRINT DECIMAL VALUES RIGHT JUSTIFIED we discuss
WRITE THE FUNCTION DESCRIBED IN SECTION 5.8 AND A MAIN ROUTINE TO TEST IT.

5.8 A FUNCTION TO PRINT DECIMAL VALUES RIGHT JUSTIFIED we discuss an algorithm to print, right justified, the decimal equivalent of a binary num- a 32-bit number (in a0). The output will be a string of printed ber. The input to this function is ers on the monitor. When we implement this code we must determine if the input binary t be number is a negative value. If the number is negative, the ASCII code for a minus sign mus placed in the output buffer immediately to the left of the most significant decimal digit maximum number of decimal digits that will be generated is ten. To hold any integer, the o put buffer (which can be "local" to the routine) would need to be at least twelve characters in length. Specifically, we need a null character at the end of the buffer, possibly ten ASCII codes for ten decimal digits, and possibly a minus sign. For a small positive value, such as nine, there will be 10 leading space characters to ensure that the number appears right justified within a field of eleven characters. ut- The heart of this algorithm can be a do while" control structure. Within each iteration, divide the number by ten. From the remainder, we derive the next ASCII code for the equivalent decimal representation. The quotient becomes the number for the next iteration. The decimal digits are derived one at a time from the least significant digit working toward the most significant digit each iteration. While the number is not equal to zero, we tinue to iterate. When the quotient finally becomes should be preceded by a minus sign, and then all remaining leading character positions filled with the ASCII code for space. Finally, we use the system service to print string in the output buffer. The output buffer size width which defaults to 80 characters. This local buffer can be allocated on the st permanent allocation need be made. con- zero, it is time to check if the number are the ASCII should be limited to no more than the screen ack so that no 5.8 A FUNCTION TO PRINT DECIMAL VALUES RIGHT JUSTIFIED we discuss an algorithm to print, right justified, the decimal equivalent of a binary num- a 32-bit number (in a0). The output will be a string of printed ber. The input to this function is ers on the monitor. When we implement this code we must determine if the input binary t be number is a negative value. If the number is negative, the ASCII code for a minus sign mus placed in the output buffer immediately to the left of the most significant decimal digit maximum number of decimal digits that will be generated is ten. To hold any integer, the o put buffer (which can be "local" to the routine) would need to be at least twelve characters in length. Specifically, we need a null character at the end of the buffer, possibly ten ASCII codes for ten decimal digits, and possibly a minus sign. For a small positive value, such as nine, there will be 10 leading space characters to ensure that the number appears right justified within a field of eleven characters. ut- The heart of this algorithm can be a do while" control structure. Within each iteration, divide the number by ten. From the remainder, we derive the next ASCII code for the equivalent decimal representation. The quotient becomes the number for the next iteration. The decimal digits are derived one at a time from the least significant digit working toward the most significant digit each iteration. While the number is not equal to zero, we tinue to iterate. When the quotient finally becomes should be preceded by a minus sign, and then all remaining leading character positions filled with the ASCII code for space. Finally, we use the system service to print string in the output buffer. The output buffer size width which defaults to 80 characters. This local buffer can be allocated on the st permanent allocation need be made. con- zero, it is time to check if the number are the ASCII should be limited to no more than the screen ack so that no
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
