The MASM Forum Archive 2004 to 2012

Miscellaneous Forums => 16 bit DOS Programming => Topic started by: amrac on December 15, 2009, 11:08:51 PM

Title: A simple multiplication
Post by: amrac on December 15, 2009, 11:08:51 PM
I'm  doing a program in which I read two numbers from a file, sum them and then send the result back to the file. I have to do the convertion from ASCII to decimal and from decimal to ASCII. Each number has 4 digits. But when I multiply, for example 120 in decimal to 1200, I get the wrong result. I do this by doing
mul cx

cx has the value 10 and ax has the value 120. This is because I have a multiplication of a value that is a byte that results in a word.
The question is: how can I correctly make a multiplication if I have to pay attention to the carry flag and to the overflow flag?
Title: Re: A simple multiplication
Post by: jj2007 on December 15, 2009, 11:13:32 PM
You won't get answers if you don't post your complete code...
Title: Re: A simple multiplication
Post by: dedndave on December 15, 2009, 11:27:20 PM
well - i can venture a guess - lol
the resulting values are binary
120 x 1200 is 144000, or 23280h
you need to split that up into individual decimal digits prior to converting back to ASCII
the simplest way to do that is to divide by 10, and take the remainder for the new low order digit
divide the quotient by 10 again to get the next digit, and so on
my guess is that the original conversion from ASCII to binary isn't right either
Title: Re: A simple multiplication
Post by: amrac on December 16, 2009, 07:06:36 PM
The problem was that I wasn't doing
mov ax,0 before I did the multiplication so I got the wrong result. But thanks for your answer.
Title: Re: A simple multiplication
Post by: dedndave on December 16, 2009, 07:09:58 PM
no need to worry about overflow !