Click here to Skip to main content
16,018,158 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm having trouble understanding how to get a sum of two numbers that are in ascii format.

Im using the following interrupt to get two 8 digit numbers from the user:

ASM
MOV AH, 0AH
MOV DX, OFFSET numset1
INT 21H


The inputs are stored in two variables as numset1 & numset2

I need to add those two inputs together to get the sum. The problem that I am having is I can't wrap my head around how to add them together when they are in ascii format. I tried to use an AND instruction to drop the 3 from the ascii number representation to get just the actual number value.
ASM
AND 31H, 0Fh = 03H

I literally have no idea what I'm doing with this so if anyone has the slightest clue how I'm to go about this algorithm it would be much appreciated.
Posted
Comments
Ishpreet Kaur 7-May-14 2:17am    
It seems this is assembly language for microprocessor......

In microprocessor, the inputs are stored in registers, not in variables.

This sounds seriously like homework, so I'll give you no code!

But it isn't complex, what you need to do is convert each string you read from the use into an integer, then add them, them convert them back to a strong to output them. Clearly, you are having difficulty with the first bit! :laugh:

It's not to complex, really. Just create a function that takes a null terminated string as a parameter, and which returns an integer.
Inside the function, start by zeroing the integer, then loop through all characters in the string until you get to the null byte.
For each non-null, check it's a digit: other wise it gets confusing...
If it is, then subtract 0x30 from the character, multiply the integer total by 10, than add the value.
At the end, return the integer.
 
Share this answer
 
Just had to convert both inputs to BCD by subtracting 30 from each byte.

Then add the BCD together.

Then convert the BCD sum back to Ascii bu using an AND AX, 03030H to add 30 to each byte.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900