Assignment 1

Assignment goals:

Further proficiency in 80X86 assembly language programming, including modularity required to handle a slightly larger program. Exercising the following specific topics: logical and arithmetic operations, procedure calls - including high-level language conventions (C).

Program goal:

You are to write a program for implementing a simplified reverse Polish notation calculator for complex numbers.

Program description:

Recall that a complex number has two components, and is represented as follows:

            X = a + b * i 

where X is the complex number, a is the real component, and b is the imaginary component (i is the square root of -1).

For simplicity, the program will only work on numbers with integral real and imaginary components. Operations to be implemented are addition, negation, and multiplication. Again, for reference, the operations are defined as follows, with X=a+b*i and Y=c+d*i:

           X + Y =  (a+c) + (b+d) * i
             - X =   -a - b*i
           X * Y =  (a*c - b*d) + (a*d + b*c) * i

In order to exercise logical and bit operations, the internal representation of each complex number will be in SIX bytes. The 24 high-order bits represent the REAL component, and the 24 lower-order bits represent the IMAGINARY component. Each Component will thus be represented as a 24-bit 2-s complement number.

The calculator will use reverse Polish notation (RPN), where each number or operator is entered in a separate line. The format for entering a number will be:

   real-component i imaginary-component 

where real-component and imaginary-component are integers entered in decimal, followed by optional "-" signs (each negating their respecive component) i is a separator denoting start of imaginary component. Space characters in the above are for readability only, and not part of the input. Example of complex number entry, to enter the number 34-8*i the user types:

34i8-
You may assume that each component results in a number that can be represented in 24 bits.

Operations are performed as is standard for an RPN calculator: any complex number seen is pushed onto an operand stack, represented as an array (NOT the 80X86 machine stack), and each operation is performed is on operands from the stack (one for negation, two for addition and multiplication). The result is pushed onto the stack and displayed. If an operation causes an overflow, display the string "overflow". You should print out "stack overflow" if the calculation attempts to push too many operands on the stack, and "stack empty" if an operation attempts to pop an empty stack. Your program should also count the number of operations performed.

Additional Requirements

Modularity is a requirement in this assignment. Thus, calculator functions, as well as input and output functions, must be programmed as procedures (subroutines). Additionally, printout of results should use the C library function printf(), and getting a line by using gets(). You will be linking your code to a C main program (that you also need to write) that calls my_calc that is your main procedure, and prints out the number of operations performed by my_calc. (Note that my_calc should count and return that number). If the user enters "quit" at any time during the run of the program, your program should exit gracefully, by having my_calc returning the total number of operations performed, and using RET to return to the calling C-generated code (which should print out that number before exiting).

Assumptions:

Illegal characters may be ignored. You may assume that the number entry format is correct, but as the user may try to enter numbers that are too big, a provision to handle that as shown above must be made, i.e. you can ignore the entry or flag an error, but do NOT crash!

Due date: Thursday, November 27, 2003.