News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

A simple multiplication

Started by amrac, December 15, 2009, 11:08:51 PM

Previous topic - Next topic

amrac

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?

jj2007

You won't get answers if you don't post your complete code...

dedndave

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

amrac

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.

dedndave

no need to worry about overflow !