In the 1840's, Charles Babbage designed
a steam-powered computer that he claimed could add two 50-digit numbers
is one second and could multiply two 50-digit numbers in one minute.
Write an assembly language program which demonstrates that we can do 50-digit
arithmetic a little faster than that now. Your program is to prompt for
two unsigned 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 operations that your program must
be able to handle are addition and subtraction; and the subtraction is
only such that the difference is positive. 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 or subtracted as strings; they can be far too long for ReadInt or even ReadLong to handle. Then, convert the digit strings to unpacked decimal form. Use the ADD, ADC and/or AAA instructions to perform addition on the unpacked decimal values. Use the SUB, SBB and/or AAS instructions to perform the subtraction. Then, convert the unpacked decimal result back to normal ASCII digits and display it.
Even though your program is required only to perform addition and subtraction, 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 procedure that does the adding only if the operator is + or call the procedure that does the subtracting only if the operator is -. In this way, the program is designed to be expandable to accommodate operations like multiplication, and division.
Your program must have at least three procedures, in addition to main. One procedure must be used to convert an ASCII digit string to unpacked decimal. One procedure must be used to perform addition on unpacked decimal values. And, one procedure must be used to convert unpacked decimal to an ASCII digit string.
Extra Credit Possibilities:
1) Make subtraction work even when
the difference is negative. Use it in your program to subtract one
very large number from another somewhat smaller number.
2) Make multiplication work. Use the * operator to indicate multiplication. Allow the multiplier and multiplicand to be up to 50 digits and produce a correct product of up to 100 digits. You will need the MUL, AAM, ADD, ADC, and/or AAA instructions to do this.
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 COSC300 on the P drive.
Below is a sample execution in which large numbers are being used.
Program to do arithmetic on two very large operands (positive integers):
First operand (limit
50 digits): 874639987354234590003763623827284
Operation: +
Second operand (limit
50 digits): 99998332934850305938783776633334023
Result: 100872972922204540528787540257161307
First operand (limit
50 digits): 4793822877849445602948423421
Operation: -
Second operand (limit
50 digits): 4793822875489385038500027499
Result: 2360060564448395922
First operand (limit
50 digits): 3892829747992340122
Operation: -
Second operand (limit
50 digits): 10748937648893329455
Result: -6856107900900989333
First operand (limit
50 digits): 123456789012345678901234567890
Operation: *
Second operand (limit
50 digits): 987654321098765432109876543210
Result: 121932631137021795226185032733622923332237463801111263526900
First operand (limit
50 digits):
The last two examples show the extra credit
portions by doing a subtraction resulting in a negative and a multiplication.
Notice that the interface is the same, only the operation changes.