;============================================================================== ;file :ten.asm ;author :Andre Long ;due :May 15, 2006 ;description :This program will multiply two ten digit numbers with arrays ;============================================================================== ;procedures to INCLUDE Pcmac.inc EXTRN NEWLINE:FAR ;display a new line EXTRN GETDEC$:FAR ;gets 16 bit decimal value unsigned EXTRN PUTDEC$:FAR ;display 16 bit value unsigned EXTRN PUTSTRNG:FAR ;display charactor string ;============================================================================== .MODEL SMALL .586 .STACK 100h .DATA ;n1 DB 1,2,3,4,5,6,7,8,9,0 ;n2 DB 9,8,7,6,5,4,3,2,1,1 n1 DB 1,1,1,1,1,1,1,1,1,1 n2 DB 0,9,8,7,6,5,4,3,2,1 tempA DB 20 DUP (0) tempB DB 20 DUP (0) result DB 20 DUP (0) messP DB 'Product = ', '$' messTA DB 'TempA = ', '$' messTB DB 'TempB = ', '$' endPos DW 9 tempEndPos DW 19 carry DB ? carryX DB 0 blank DB ' ', '$' red DB ? counter DB ? ;============================================================================== .CODE ten2 proc _Begin mov ax, 0 mov bx, 0 mov cx, 0 mov dx, 0 mov si, endPos mov di, endPos mov bx, tempEndPos outerLoop: mov bx, tempEndPos mov si, endPos cmp di, 8 jl doneOuterLoop jmp innerWorks innerWorks: mov al, [n1 + si] mov dl, [n2 + di] mul dl ;al = (al)(dl) add al, carryX ptA: cmp al, 9 jg carryM jmp noCarryM carryM: mov red, 10 div red ;al / 10 mov [tempA + bx], ah ;remainder to current end position mov carryX, al ;store the quotient jmp afterCarryM noCarryM: mov [tempA + bx], al jmp afterCarryM afterCarryM: dec bx dec si cmp si, 0 jl nextN2 jmp innerWorks ;di not less < 0 (have not reach end of n1) nextN2: push di sub di, 9 mov counter, di ;counter = di - 9 pop di cmp di, 9 je somePoint jmp nextN22 nextN22: mov bx, 0 nextN222: mov cl, [tempA + bx] ;shift logic mov [tempA + bx -1], cl inc bx cmp bx, 19 jg somePoint3 jmp nextN222 somePoint3: mov [tempA + 19], 0 somePoint: mov bx, tempEndPos somePoint2: mov cl, [tempA + bx] add [result + bx], cl cmp [result + bx], 9 jg carry1 jmp noCarry1 carry1: sub [result + bx], 10 ;cl - 10 mov carry, 1 ;carry = 1 mov dl, carry add [result + bx - 1], dl jmp afterCarry1 noCarry1: jmp afterCarry1 afterCarry1: dec bx cmp bx, 0 jl testDi jmp somePoint2 testDi: dec di jmp outerLoop doneOuterLoop: mov bx, 0 call newline display: mov al, [result + bx] call putdec$ sPutstr blank inc bx cmp bx, 19 ja outP jmp display outP: _Exit ten2 ENDP END ten2