Subtracting Numbers with DOS Alone |
A subtraction routine is easily derived from the addition routine presented in the Real Math article. If you understand it, the changes needed to create a subtraction routine aren't too hard to understand.The first part of the routine, up through the counting on the number line for the first number is nearly identical in both routines. The first significant difference is that the number line arguments are reversed on the recursive command line. Second, the shifter for the first number is also reversed to make the number of ticks left on the command line be equal to the first number. The third difference is that the carry flag is handled slightly differently, being included with the processing of the second number. Finally, a leading zero processor needed to be added at the end of the routine to give a consistent output format.
:: SUBTRACT.BAT - An efficient DOS routine that finds the unsigned difference
|
Some Caveats |
The subtraction routine returns an unsigned number. That is, it assumes the first number is equal to or less than the second number. Unexpected results will occur if this is not true. Use the Comparison routine before calling SUBTRACT to insure proper results.Input strings containing more than eight characters will also give unexpected results, while strings with non-number characters return an error message and the named result variable is empty. Use that fact for error handling in the calling routine.