Assignment 5: Medium ARM -- 02/24/2020

COSC 2200, Spring 2020

Marquette University, Department of Computer Science

Due: (deadline extended) Tuesday, March 3rd, 2020 at 11:59PM
Submit: Turn in your three source files using the turnin command on Morbius. Please name your files "main-ascii.S", "main-change.S", and "main-lcm.S". Failure to follow this simple convention will cause TA-Bot to fail. What is TA-Bot?
Remember, your final turnin command (to submit your final changes) will look like this:

turnin -c cosc2200 main-ascii.S main-change.S main-lcm.S

Work may be completed in teams of two. The names of both partners must appear in a comment block at the top of your file for credit to be given. I strongly recommend that you take the time to meet with your partner in person and work together on these projects, rather than work separately and try to integrate at the last minute. Use the command hook "TA-BOT:MAILTO" in a comment in your source files to designate mail addresses for TA-Bot output. An example of this hook is included for you at line 1 of the "main.S" template (in pi3Playground).

This UNIX tutorial may be of some assistance.

Preparation

You are now familiar with basic UNIX tools. You will use your knowledge of UNIX commands to proceed.

This untars the files into your working directory, in a subdirectory called pi3Playground/. For more information on tar, please see the UNIX man pages (e.g. man tar)

Updated main.S template

The playground template file has been updated to include getInt, a new function necessary to solve this assignment. You can read about getInt in the comments where it is defined. Essentially, getInt is similar to getnum. But getInt is capable of getting signed integers (still storing integers in r0), and storing a boolean (in r1) to represent whether input is equal to EOF (end of file / ctrl+D).

Another new function, called toBinary has been included for you. You will use this function in Q1 (ASCII) to convert an integer into binary.

Printing with kprintf

See the Lab 7 web page for a helpful explanation about using kprintf and formatted strings. In this assignment, you are tasked with printing characters in a greater range than what printnum can currently provide. Therefore, you must now use kprintf, which prints the formatted string in r0, and any other values in r1, r2, or r3 (if the string specifies more values). Thus, the string must be loaded into r0 before calling kprintf. To define values to print (as strings), place them in the bottom of the file in the .data section (used for non-code entities). The template contains an example of this.

Q1 - ASCII

Note: this question is similar to that of Lab 7, but this program requires a range of values to be printed (with boundary checking).

Write an assembler program that takes two values -- low and high -- representing a range of ASCII values (input prompt should match the example). Print the values in this range, inclusively, with the following format (decimal, hex, binary, character - if any), separated by tab characters for clean output. If EOF (Ctrl+D) is entered (instead of a low/high value), then your program should end. If the low value is less than zero, then it should be corrected and set to zero. Similarly, if the high value is greater than 255 (the ASCII range), then it should be corrected and set to 255.
Important note about formatting: As you can see in the examples below, eight binary digits should be printed. Three decimal digits (the first ASCII value) should be printed. And two hex digits should be printed.

Example 1:

low? 30
high? 36
 30	0x1E	0b00011110
 31	0x1F	0b00011111
 32     0x20    0b00100000	 
 33     0x21    0b00100001	!
 34     0x22    0b00100010      "
 35     0x23    0b00100011      #
 36     0x24    0b00100100      $

All user process have completed.

Example 2:

low? 98
high? 102
98	0x62	0b01100010	b
99	0x63	0b01100011	c
100     0x64    0b01100100      d
101     0x65    0b01100101      e
102     0x66    0b01100110      f

All user process have completed.

Example 3:

low? -3
high? 7
  0     0x00    0b00000000
  1     0x01    0b00000001      
  2     0x02    0b00000010      
  3     0x03    0b00000011      
  4     0x04    0b00000100      
  5     0x05    0b00000101      
  6     0x06    0b00000110      
  7     0x07    0b00000111

All user process have completed.

Q2 - Change Maker

Write an assembler program that reads an integer (representing pennies) until EOF, and returns the equivalent in dollar coins, quarters, dimes, nickels, and pennies. The minimal amount of coins must be used. You must adhere to the input and output style that the example shows. In addition, output must have appropriate grammar. For example, "dollars" is used if the integer is zero or greater than one. Otherwise, if there is 1 dollar, then "dollar" is used in the output. If the user enters a negative integer, the result is printed in negative pennies. You may assume that overflow and underflow do not occur.

Example:

? 93
Change:
0 dollars,
3 quarters,
1 dime,
1 nickel,
3 pennies.
? 144
Change:
1 dollar,
1 quarter,
1 dime,
1 nickel,
4 pennies.
? 15
Change:
0 dollars,
0 quarters,
1 dime,
1 nickel,
0 pennies.
? -15
Change:
0 dollars,
0 quarters,
0 dimes,
0 nickels,
-15 pennies.
?  

All user process have completed.

Note: The last input in this example is EOF (Control+D)

Q3 - LCM

Write an assembler program that reads two integers until EOF, and prints the Least Common Multiple of the two integers. Your input and output must match the example. Your program should ignore negative integers if they are inputted.. You may assume that overflow and underflow do not occur.

Example:

LCM Calculator
? -22
? 15
? 12
LCM of 15 and 12 is 60
? 4
? 6
LCM of 4 and 6 is 12
? 23
? 30
LCM of 23 and 30 is 690
? 0
? 5
LCM of 0 and 5 is 0
? 

All user process have completed.

Note: The last input in this example is EOF (Control+D)