The MASM Forum Archive 2004 to 2012

Miscellaneous Forums => 16 bit DOS Programming => Topic started by: shagywashere on November 30, 2011, 01:42:11 AM

Title: 10-digit multiplication using arrays
Post by: shagywashere on November 30, 2011, 01:42:11 AM
Using three arrays, have to multiply two 10-digit numbers. I figured out how to put the 10-digits into the array, but I'm having trouble multiplying it. We store the result in the third array. I posted my multiplication procedure, anyone help me out? It just freezes when the cmd prompt when I run it, and I have to restart the prompt to run it again.


.DATA
ARR1 DB 20 DUP (0)
ARR2 DB 20 DUP (0)
ARR3 DB 20 DUP (0)



MULTIPLY PROC NEAR
MOV             CX, 10
MOV DI, 9
.REPEAT
MOV AL, ARR1[DI]
MOV BL, ARR2[DI]
IMUL             BX
.IF AL >= 10
MOV BX, 10
IDIV             BX
MOV REM, AL
.ENDIF
MOV ARR3[DI], DL
MOV BL, REM
ADD ARR3[DI], BL
DEC DI
.UNTILCXZ

MULTIPLY ENDP
Title: Re: 10-digit multiplication using arrays
Post by: raymond on November 30, 2011, 02:06:56 AM
Have a look at the following. It contains many examples (including multiplications) using Binary Coded Decimals, i.e. BCD.
http://www.ray.masmcode.com/BCDtut.html

You may find it a lot easier by using the BCD instructions. They work the same for 16-bit and 32-bit apps.
Title: Re: 10-digit multiplication using arrays
Post by: clive on November 30, 2011, 04:36:21 PM
The routine doesn't have a RET at the end, and CX is never decremented.
Title: Re: 10-digit multiplication using arrays
Post by: shagywashere on December 01, 2011, 12:35:44 AM
CX is decremented automatically using the ".UNTILCXZ" command. But yea no RET must have been what was making it freeze. Thanks.
Title: Re: 10-digit multiplication using arrays
Post by: clive on December 01, 2011, 12:54:11 AM
Sorry, I don't use the high level constructs and couldn't find a quick cite, but yes it appear to assemble to a LOOP rather than JCXZ.