CSE 2312 - Assignments - Assignment 10

The assignment will be graded out of 100 points. Submit your source code for each task, in files called task1.s, task2.s, and so on. Each task specifies whether you should include only functions, or submit the entire program. Submit your solutions to Blackboard before the deadline. You will be able to revise your answers until the deadline with no penalty.


Task 1 (20 points)

Consider the strcmp function in C:
/* ASCII-based comparison of the two strings. 
 * Return values:
 * 0, if the two srings have the same contents.
 * less than 0, if the ASCII code of s1 is less than the ASCII code
 *     of s2 at the first position where s1 and s2 differ.
 * greater than 0, if the ASCII code of s1 is greater than the ASCII code
 *     of s2 at the first position where s1 and s2 differ.
 */
int strcmp(char * s1, char * s2)
{
   int counter = 0;
   while (s1[counter] != 0)
   {
      if (s1[counter] != s2[counter])
      {
         break;
      }
      counter++;
   }
   
   return s1[counter] - s2[counter];
}
Implement this function in assembly. Submit a file task1.s that includes ONLY your definition of the function (and possibly other functions that you are using), but NOT the main program.


Task 2 (20 points)

Write a function string_to_int that takes as argument a string (i.e., the argument is the memory address to the first character of the string), and, assuming that the string is a valid representation of an integer in decimal, converts that string into the corresponding integer. This function returns two values, in registers r0 and r1: Your function should be able to handle strings that satisfy the following two assumptions:
  1. The first character is a digit from '0' to '9', or a minus sign '-'.
  2. All other characters are digits from '0' to '9'.
If the argument string obeys those assumptions, the function should be able to successfully convert it into an integer. If the argument string does not obey those assumptions, then your function should report that the conversion was not successful.

Remember, all strings are terminated with the null character (which has ASCII code 0).

Submit a file task2.s that includes ONLY your definition of the function (and possibly other functions that you are using), but NOT the main program.


Task 3 (60 points)

Write a calculator program, that behaves as follows: You will probably find it useful to use the following functions defined in file get_line.s:

The following text displays input and output for an example run of my solution. Given the same input as shown here, your program output should match EXACTLY the output shown here (even the white spaces should match).

Starting calculator program

Accumulator = 0

+25
invalid string
Accumulator = 0

+ 25
Accumulator = 25

+ -10
Accumulator = 15

- -1
Accumulator = 16

^ 3
Accumulator = 4096

% 1000
Accumulator = 96

/ 30
Accumulator = 3

* 7
Accumulator = 21

^ -8
Accumulator = 21

* -4
Accumulator = -84

Hello
invalid string
Accumulator = -84

& 0
invalid string
Accumulator = -84

quit
invalid string
Accumulator = -84

q
Exiting calculator

Submit a complete program, that includes all the functions you are using.


Back to the list of assignments.