This is intented to be a fun thread where you can post interesting results with ASCII additions.

In the early days of the 8086, one of the main commercial uses of the PC was accounting. Registers being only 16 bits and the co-processor not being a standard addition, some machine instructions (AAA, AAD, AAM, AAS, DAA and DAS) were included to facilitate arithmetic operations with base 10 numbers so that large numbers could be handled.

The published logic of the AAA operation is as follows:

if((AL)&0Fh)>9 or (AF)=1 then
(AL) <- (AL)+6
(AH) <- (AH)+1
(AF) <- 1
(CF) <- (AF)
(AL) <- (AL)&0Fh

When using AAA immediately after adding two numbers, this leaves in AL the (binary) value of the decimal units, and the CF indicates if there was a carry. Because the lower 4 bits of the ASCII decimal numbers are the same as the equivalent binary numbers, and only those 4 bits are taken into consideration by the AAA operation, the ASCII bytes can thus be added directly without converting first to binary. When needed, the result is converted back to the ASCII representation of decimal numbers by simply adding 48 (30h). (Note that AAA will always operate on the lower 4 bits of AL and the AF flag regardless of previous instructions.)

Although AAA was intended to be used after adding two numbers, it can also be used after adding any two bytes. And, any number can be added to the result. This opens up a totally different application. This idea germinated while posting on another thread dealing with "ASCII additions". For example:

adding wars and +CIA, and adding 64 to the results, you get AHEAD,
adding film and stars, and adding 78 to the results, will get you to ROOST,
adding enough and punk\$, and adding 75 to the results, you obtain a QUORUM.

Included in the attached .zip file is a short program for a small dialog box to enter two strings of up to 15 characters each. The two strings are added and the result displayed according to the specified number to be added (if one string is shorter than the other, it is front padded with spaces and redisplayed for alignment, spaces acting as zeros).

The source code (MASM32) and the resource file are also included. A table of the ASCII representation of the keyboard characters (20h-7Eh) is also appended to the source code file.

Enjoy. I decline any responsibility if you get hooked to find the best equation.:grin:


N.B. The dialog box can also be used for simply adding two numbers; use 48 for adding to the results.
Posted on 2003-05-02 15:59:05 by Raymond