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 matrix : $'
    msg5 db 10,13,'     Sum of elements of row $'
    msg6 db 10,13,'     $'
    msg7 db '     $'
    msg9 db ':   $'
    msg8 db 10,13,'   1st Matrix$'
    row db 0
    colum db 0
    matrix1 dw 100 dup(0)
    sum dw 0
    corow dw 1
    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
    
    ;print matrix
    print msg8
    print msg6
    printmat matrix1,loop4,loop5,loop6,jump5
    
    ;row element addition
    mov cx,noe
    mov si,00h
    mov di,00h
    xor ax,ax
loop3:add ax,matrix1[si]
    add si,02h
    inc di
    mov bx,di
    cmp bl,colum
    jne j10
    mov sum,ax
    print msg5
    mov dx,corow
    add dl,30h
    mov ah,02h
    int 21h
    print msg9
    push cx
    printmul sum,loop2,jump4
    pop cx
    inc corow
    xor ax,ax
    mov di,ax
j10:loop loop3
    mov ah,4ch
    int 21h
    
main endp
end
No comments:
Post a Comment