IUP Computer Science
COSC 300    Spring 2002
 

Project #5
(Due  15  April 2002)


Write an assembly language program that can perform simple arithmetic on positive integers containing up to 60 digits.  Your program is to prompt for two values and an operation to perform upon them.  It must then perform the operation on the two numbers, produce a result, and display that result.  Initially, the only operation that your program must be able to handle is addition, indicated by the + symbol when reading in the operation.  You may choose to have the program also perform subtraction for extra credit.  The program should repeatedly prompt for two values and an operator and show the result.  When an empty string is entered for the first number, the program should end.

The program must read the values to be added as strings; they can be far too long for ReadInt or even ReadLong to handle.  Then, convert the digit strings to packed decimal form.  Using the ADD, ADC and DAA instructions, perform addition on the packed decimal values.  Then, convert the packed decimal sum back to normal ASCII digits and display it.

Even though your program is required only to perform addition, the structure of main should be like that of a calculator, prompting for two operands and an operator.  main should also examine the operator and call the function that does the adding only if the operator is +.  In this way, the program is designed to be expandable to accommodate operations like subtraction, multiplication, and division.

Your program must have at least three functions, in addition to main.  One function must be used to convert an ASCII digit string to packed decimal.  One function must be used to perform addition on packed decimal values.  And, one function must be used to convert packed decimal to an ASCII digit string.

Extra Credit:  Make another function to perform subtraction on packed decimal values.  Use it in your program to subtract one very large number from another.  You must use the SUB, SBB and DAS instructions in performing the subtraction.

Hand in a printout of your source program.  Note:  I am not asking for the .lst printout; the .asm file is sufficient.  Also, after renaming the file containing the source to  yourname5.asm and the executable to yourname5.exe, copy the source program and the executable file to the hand-in folder for your section of COSC300 on the P drive.

Below is a sample execution in which two pairs of numbers are being added

Program to do arithmetic on two very large operands (positive integers):

First operand: 37546392220291978430027
Operation: +
Second operand: 783945836622018381887

Result: 38330338056913996811914

First operand: 46799
Operation: +
Second operand: 82001
Result: 128800

First operand: 763920387333520029987212
Operation: -
Second operand: 8920380933520026654213
Result: 755000006400000003332999

First operand:

The last example is shows the extra credit portion by doing a subtraction.  Notice that the interface is the same, only the operation changes.