print macro msg
        lea dx,msg
        mov ah,09h
        int 21h
    endm
    reads macro m
        mov ah,01h
        int 21h                     
        sub al,30h
        mov m,al
    endm
    read macro n,j1,j2
    j1:mov ah,01h
        int 21h                     
        cmp al,0dh
        je j2
        sub al,30h
        mov bl,al
        mov ax,n
        mov dx,0ah
        mul dx
        xor bh,bh
        add ax,bx
        mov n,ax
        jmp j1
    j2 :nop
    endm
    readmat macro mat,l1,j3,j4,newmsg
        mov cx,noe
        mov si,00h
        print msg6
    l1:print newmsg
        ;read a multidigit number
        read mat[si],j3,j4
        add si,02
        loop l1 
    endm
    printmul macro n1,l2,l3
    
        mov bx,000ah
        mov ax,n1
        xor cx,cx
    
        ;push into stack
    l2:xor dx,dx
        div bx
        push dx
        inc cx
        cmp ax,0000h
        jne l2
        ;pop from stack
    l3:pop dx
        add dl,30h
        mov ah,02h
        int 21h
        loop l3
    endm
    printmat macro mat1,l4,l5,l6,j5
        mov cx,noe
        mov si,00h
    l4: push cx
        print msg7
        printmul mat1[si],l5,l6
        add si,02h
        inc f
        mov bl,f
        cmp bl,colum
        jne j5
        print msg6
        mov f,00h
    j5: pop cx
        loop l4
    endm
    
    .model small
    .stack 100h
    .data
        msg1 db 10,13,'Enter the no of rows: $'
        msg2 db 10,13,'Enter the no of column: $'
        msg3 db 10,13,'Enter the element of matrix1 : $'
        msg4 db 10,13,'Enter the element of matrix2 : $'
        msg5 db 10,13,'   Sum Matrix $'
        msg6 db 10,13,'     $'
        msg7 db '     $'
        msg8 db 10,13,'   1st Matrix$'
        msg9 db 10,13,'   2nd Matrix$'
        row db 0
        colum db 0
        matrix1 dw 100 dup(0)
        matrix2 dw 100 dup(0)
        matrix3 dw 100 dup(0)
        sum dw 0
        f db 0
        noe dw 0
        
    .code
    main proc
        mov ax,@data
        mov ds,ax
    
        ;read no of rows
        print msg1
        reads row
    
        ;read no of column
        print msg2
        reads colum
    
        ;calculating total no of elements
        mov al,row
        mov bl,colum
        mul bl
        mov noe,ax
    
        ;read 1st matrix elements
        readmat matrix1,loop1,jump1,jump2,msg3
        
        ;read 2nd matrix elements
        readmat matrix2,loop2,jump3,jump4,msg4
    
        ;matrix addition
        mov cx,noe
        mov si,00h
    loop3:mov ax,matrix1[si]
        add ax,matrix2[si]
        mov matrix3[si],ax
        add si,02h
        loop loop3
    
        ;print 1st matrix
        print msg8
        print msg6
        printmat matrix1,loop4,loop5,loop6,jump5
    
        ;print 2nd matrix
        print msg9
        print msg6
        printmat matrix2,loop7,loop8,loop9,jump6
    
        ;print Sum matrix
        print msg5
        print msg6
        printmat matrix3,loop10,loop11,loop12,jump7
    
        mov ah,4ch
        int 21h
    
    main endp
    end
No comments:
Post a Comment