In our seventh lab, you and your partner will build a simple ASCII printer program (with specialized output format) in ARM, as described below.
Helpful command: man ascii
This will display a man (manual) page for the ASCII character set, listing the ASCII table. (Note: press "q" to quit a man page)
Find your lab partner. Then:
Read about getInt in the comments of its definition. This function prompts the user for an integer, and stores the integer in r0. The integer may be signed or unsigned. In addition, in r1, the function stores a Boolean value to represent wether the EOF flag was seen (control+D), in which case, your program should end.
toBinary takes the integer stored in r0, converts it to a string of binary digits (represented as a base-10 decimal value), and stores the result in r0. Thus, this "binary" value cannot be treated as a base-2 integer -- but that's OK, you are only printing it. We convert to binary in this way because there is no conversion character for binary (see below).
Conversion Character How the argument is printed %c as a character %d as a decimal integer %X as a hexadecimal integer Format example Output format of argument %08X Eight hex digits %08d Eight decimal digits Generally: %0NX N hex digits %0Nd N decimal digits
Write a program that reads integers until EOF is entered. After each integer is entered, your program will display (1) the binary representation of the integer (8 binary digits), (2) the hexadecimal representation of the integer (2 hex digits), and (3) the character representation of the integer -- separated by a tab character. If the user enters a negative value, your program should alert the user to try again, and ask for an integer again. If the value entered is greater than the range of ASCII (255), then your program should assume the value entered is 255. Follow the output format of the example -- the strings should match (e.g. "Enter a number").
Note: the final input of this example is EOF (Control+D).
Another note: special ASCII values are not readable (looks like a box) when printed as a character, such as EOF (4). This is expected.
Example:
Enter a number: ? 36 0b00100100 0x24 $ Enter a number: ? 39 0b00100111 0x27 ' Enter a number: ? -23 Invalid input. Try again. Enter a number: ? 3 0b00000011 0x03 Enter a number: ? 4 0b00000100 0x04 Enter a number: ? 257 0b11111111 0xFF Enter a number: ? 255 0b11111111 0xFF Enter a number: ? 240 0b11110000 0xF0 p Enter a number: ? 52 0b00110100 0x34 4 Enter a number: ? 55 0b00110111 0x37 7 Enter a number: ?