To the ineffable ALL,

Believe it or not, it's easy to add two decimal ASCII strings in DWORD gulps without converting each byte into BCD, or the string into binary, or any other such nonsense. It's four bytes for each pass through the routine. What's more, the sum remains in ASCII. The length of the two strings to be added is limited only by the available memory. Don't believe it? Then look at the code below for one DWORD. Naturally, the method can be extended to any length you want. You can see an example of that if you download the ZIP. The catch is that there is no checking for bogus non decimal characters in the string. That means there cannot be any nulls, periods, commas, dollar or pound signs, or any other punctuation. It's hard to describe in the code notes how it works, but it becomes clearer if you run a few examples with a good debugger and see those registers add up the way you want them to. Try it, you will probably like it. Anybody want to tackle subtraction? Ratch

;EDX = 1 if carry flag from previous addition present, else 0
LEA EAX,[EDX+096969696H] ;add carry flag to "carry constant"
BSWAP ECX ;&%@#*$ Intel to hell, need to switch it around from little endian
ADD EAX,ECX ;add carry constant to first number
BSWAP ECX ;&%@#*$ Intel to hell, need to switch it around from little endian
ADD EAX,ECX ;add the second number to the mix, '0'+'9'+96H = FFH
SETC DL ;store carry flag from present addition

;we just did the sum, now comes the fun
;retrieve the ASCII decimal digits
AND ECX,0F0F0F0F0H ;mask out all the sign extensions
SUB EAX,ECX ;remove the sign extensions for each digit
SHR ECX,4 ;switch the mask over one nibble
AND ECX,006060606H ;adjust mask for sign extensions only
SUB EAX,ECX ;subtract the 6 from previous 96H addition if sign extension present
OR EAX,030303030H ;only decimal numbers left in each byte, fill in with '0's to make ASCII numeric
Posted on 2004-02-14 22:36:11 by Ratch
hey ratch :alright:

well i thought ill try the sub loaded this olly and did these corrections seems to work for your data dont know if this work for all datas didnot test it

00401000 8D02 LEA EAX, DWORD PTR DS: <--removed that 96**
00401002 90 NOP
00401003 90 NOP
00401004 90 NOP
00401005 90 NOP
00401006 |. 8B8E 02304000 MOV ECX, DWORD PTR DS:
0040100C |. 0FC9 BSWAP ECX
0040100E 03C1 ADD EAX, ECX
00401010 |. 8B8E 11304000 MOV ECX, DWORD PTR DS:
00401016 |. 0FC9 BSWAP ECX
00401018 2BC1 SUB EAX, ECX changed this to sub

all else is same

result is as follows
|hOwner = NULL
|Text = " 178569829643-123456789012=055113040631"
|Title = "RESULTS"

hope i passed it ;)
Posted on 2004-02-15 11:59:26 by bluffer
Have you tried it with subtracting a larger number from a smaller number? Every one of the digits in your example is a smaller or equal value from a larger one. That doesn't happen in the real world. You have to handle the carry propagation too. Ratch
Posted on 2004-02-15 12:30:53 by Ratch
hey ratch ,
i already said i tested your value only no other values
any way the reason for this post is to ask how

Every one of the digits in your example is a smaller or equal value from a larger one.

not every value i think


ill do some tests after wards i just posted this after ten minutes of hackwork yesterday
Posted on 2004-02-15 23:41:14 by bluffer

You are correct. My mistake, one digit was larger than the other. Still, your modification does not work because it does not propagate the carry across the DWORD boundary correctly. This can be easily seen if you substract any of the strings from a ASCII string of zero characters. Look for my posting of a ASCII decimal character subtraction method shortly. Ratch
Posted on 2004-02-16 01:35:21 by Ratch