;============================================================================== ;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 tempA DB 20 DUP (0) tempB DB 20 DUP (0) result DB 20 DUP (0) messP DB 'Product = ', '$' messTA DB 'TempA = ', '$' messMul DB '1234567890 X 9876543211 = ' , '$' endPos DW 9 tempEndPos DW 19 carry DB ? carryX DB 0 blank DB ' ', '$' red DB ? counter DW ? ;============================================================================== .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 snake: mov [tempA + bx],0 dec bx cmp bx, 0 jge snake mov bx, tempEndPos mov si, endPos cmp di, 0 jl doneOuterLoop jmp innerWorks innerWorks: mov al, [n1 + si] mov dl, [n2 + di] mul dl ;al = (al)(dl) add al, carryX mov carryX, 0 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, -1 jl nextN2 jmp innerWorks ;di not less < 0 (have not reach end of n1) nextN2: mov counter, 9 sub counter, di ;shift by 9 - di dog: cmp counter, 0 je somePoint 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 dec counter jmp dog 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 add [result + bx - 1], 1 jmp afterCarry1 noCarry1: jmp afterCarry1 afterCarry1: dec bx cmp bx, 0 jl testDi jmp somePoint2 testDi: dec di jmp outerLoop doneOuterLoop: mov bx, 0 mov ah, 0 call newline sPutStr messMul display: mov al, [result + bx] call putdec$ sPutstr blank inc bx cmp bx, 19 ja outP jmp display outP: _Exit ten2 ENDP END ten2