;================================================== ; ; PROGRAM : matrixmul project ; ;PURPOSE : matrix multiplication with files4*4 ; ;================================================== .model small .data m equ 4 k equ 2 n equ 4 xmat dw m*k dup(0) ymat dw k*n dup(0) buffer db m*n*20 dup(0) result dw m*n*2 dup (0) marker db (0) f_input db "input.dat",0 f_output db "output.dat",0 inhandle dw ? outhandle dw ? buffersize dw ? err_open db "couldn't open file !","$" err_creat db "couldn't create the file","$" err_write db "couldn't write the file","$" err_close db "couldn't write the file","$" msg db "Press any key to continue...","$" ;---------------------------------------------------------------------------- .code main: mov ax,@data mov ds,ax call open call read mov di,offset buffer mov si,offset xmat mov cl,m*k call asciitobin mov cl,k*n mov si,offset ymat call asciitobin call matrixmul call bintoascii call creatfile call writefile mov bx,inhandle call closefile mov bx,outhandle call closefile mov dx,offset buffer call err_msg mov dx,offset msg call err_msg mov ah,07h int 21h mov ah,4ch int 21h ;----------------------------------------------------------------------------- open proc near mov ah,3dh mov al,0 mov dx,offset f_input int 21h jc o_error mov inhandle,ax jmp o_exit o_error: mov dx,offset err_open call err_msg o_exit: ret open endp ;------------------------------------------------------------------------------ err_msg proc near mov ah,9h int 21h ret err_msg endp ;------------------------------------------------------------------------------ read proc near mov ah,3fh mov bx,inhandle mov cx,m*n*20 mov dx,offset buffer int 21h ret read endp ;------------------------------------------------------------------------------ asciitobin proc near mov bh,0 mov bp,10d next: mov ax,0 here: mov bl,[di] cmp bl,20h je there sub bl,30h mul bp add ax,bx inc di jmp here there: mov word ptr[si],ax inc di add si,2 dec cl jnz next add di,2 ret asciitobin endp ;------------------------------------------------------------------------------ matrixmul proc near mov si,0 mov di,0 mov cl,m lp2: mov ch,n mov bx,0 lp1: call vectormul mov result[di],ax mov result[di+2],dx add di,4 add bx,2 dec ch jnz lp1 add si,k*2 dec cl jnz lp2 ret matrixmul endp ;-------------------------------------------------- vectormul proc near push si push bx push cx push bp push di mov bp,0 mov di,0 mov cl,k lp: mov ax,xmat[si] mul ymat[bx] add bp,ax adc di,dx add si,2 add bx,2*n dec cl jnz lp mov ax,bp mov dx,di pop di pop bp pop cx pop bx pop si ret vectormul endp ;------------------------------------------------- bintoascii proc near mov si,offset marker sub si,4 mov bx,10 mov cl,m*n mov bp,sp lp4: mov ax,word ptr[si] mov dx,word ptr[si+2] mov ch,0 lp3: div bx add dx,30h push dx inc ch mov dx,0 or ax,ax jnz lp3 push cx sub si,4 dec cl jnz lp4 ;------------------------------------------------------ ; storeing in buffer section ;------------------------------------------------------ mov di,offset buffer mov bl,m mov dx,0 lp7: mov bh,n lp6: pop cx lp5: pop ax mov [di],al inc di inc dx dec ch jnz lp5 mov byte ptr[di],20h inc di inc dx dec bh jnz lp6 mov byte ptr[di],0dh mov byte ptr[di+1],0ah add di,2 add dx,2 dec bl jnz lp7 mov byte ptr[di],'$' mov buffersize,dx mov sp,bp ret bintoascii endp ;------------------------------------------------- creatfile proc near mov ah,3ch mov cx,0 mov dx,offset f_output int 21h jc c_error mov outhandle,ax jmp c_exit c_error: mov dx,offset err_creat call err_msg c_exit: ret creatfile endp ;------------------------------------------------- writefile proc near mov ah,40h mov bx,outhandle mov cx,buffersize mov dx,offset buffer int 21h jnc w_exit mov dx,offset err_write call err_msg w_exit: ret writefile endp ;------------------------------------------------------------------------------ closefile proc near mov ah,3eh int 21h jnc cl_exit mov dx,offset err_close call err_msg cl_exit: ret closefile endp ;------------------------------------------------------------------------------ end main
******************
اخواني هذا الكود لضرب مصفوفتين ووضعه بمصفوفه جديده
ابي اسأل اذا الكود صح او فيه اخطاء
لاني ماعرفت والكومبايلر ماعندي
واشكركم مقدمـآ