You will be creating a simple Calculator, all it needs to do is add two decimal numbers of a fixed length, and generate
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
You will be creating a simple Calculator, all it needs to do is add two decimal numbers of a fixed length, and generate
You will be creating a simple Calculator, all it needs to do is add two decimal numbers of a fixed length, and generate an output for all possible values of the two number inputs. The calculator must first accept the ASCII keyboard information then convert that information into Binary Coded Decimal (BCD) so that the CPU can calculate a result (just subtract 30h from each number). Also the once the calculation is complete the BCD value must be converted back (add 30h) and sent to the display monitor. To get full credit (50 points): The inputs must be able to accept either no numbers and interpret them as a zero) or two numbers of the SAME lengths at least 5 digits (this insures you will have to use arrays and loops). The output must only display the digits that are part of the output number with no leading zeros. Therefore, the output will be from 1 to N digits depending on the input values to be added. Use subroutines for the conversions from ASCii to BCD and BCD to ASCii or any other repetitive set of code Display the final carry of any two numbers added NOTE: You must use the algorithm as specified in this document (1.E. do not use the Irvine library WriteDec function to do all the work for you this will not get you credit for this project).
For two number A and B of length n and m there is a Sum result of length A. An-1....A1 Ao B. Bm-1... B. Bo G G-1......CC Pseudo Code: Zero any array memory Input A Input B As the digits are being input convert the them from ASCII to Decimal (subtract 30h), and store them in two arrays Find the length of A as n and B as m if n>m then I =n if m>n then I = m ; add the two numbers one digit at a time and take into account the carry For i = 0 to I-1 t = A(i)+B(1)+C1) add two digits plus previous carry lft >= 10 Then C(i)=t-10 C(i+1) = 1 store carry into next place Else Ci=t End If Next Convert the output array to ASCII (Add 30h to each digit) Output C to monitor (include last carry if there is one) In order to use the above algorithm you must reverse the order of the input arrays, then reverse them again in order to print them out in the correct order. Otherwise, you will have to down count your array loop by starting at the array end which contains the LSD down to the beginning which contains the MSD. If you attempt to add numbers of different lengths to get extra credit then reversing the order before adding will make that process much easier(in fact that is all you have to do); however if you reverse the order of the input array to make adding easier then you have to undo the reversal to print them out correctly.