SE Comp Sem-II MIL Prac-4 (Addition of Array)

;addition of array elements

disp macro msg
    lea dx,msg
    mov ah,09h
    int 21h
endm


.model small
.stack
.data
   arr    db 20 dup(0)
   temp   db 20 dup(0)
   m0   db 10,13,'---------MENU----------$'
   m1     db 10,13,'1.INPUT NEW NO.s $'
   m2     db 10,13,'2.ADDITION $'
   m3     db 10,13,'3.EXIT $'
   msgn   db 10,13,'$'
   msg0   db 01,13,'ENTER HOW MANY NUMBERS: $'
   msg1   db 10,13,'ENTER NO: $'
   msg2   db 10,13,'SUM: $'
   sum    dw 0000h
   count  db 00h

.code
     main proc
        mov ax,@data
        mov ds,ax

m:      disp m0
        disp m1
        disp m2
        disp m3
        disp msgn
        mov ah,01h
        int 21h

        cmp al,'1'
        je inp
        cmp al,'2'
        je ad
        cmp al,'3'
        je ex
inp:    call input
        jmp m
ad:    call addi
        call hex
        jmp m
ex:     mov ax,4c00h
        int 21h
  endp main

;input proc
input proc near
push ax
push bx
push cx
push di
push si
            disp msgn        ;new line
            disp msg0        ; how many no's
            mov ah,01h
            int 21h
            sub al,30h
            mov ch,al
            mov count,ch

         a1:
              lea si,arr
            a2:
                disp msg1
                mov cl,00h
                lea bx,temp
                a3:
                    mov ah,01h
                    int 21h
                    cmp al,0DH
                    je a4
                    inc cl
                    sub al,30h
                    mov [bx],al
                    inc bx
                    jmp a3
                a4:
                    lea bx,temp
                    mov ax,00h
                    mov di,0AH
                      a5:
                          add ax,[bx]
                          cmp cl,01h
                          je a6
                          mul di
                          dec cl
                          inc bx
                          jmp a5
              a6:
                 mov [si],al
                 inc si
                 dec ch
                 jnz a2

pop si
pop di
pop cx
pop bx
pop ax

ret
endp

;addition
addi proc near
push bx
push cx
push dx
               mov cl,count
               lea si,arr
               mov dx,0000h
           b1:
               add dx,[si]
               inc si
               dec cl
               jnz b1
             mov sum,dx

pop dx
pop cx
pop bx

ret
endp

;hex to decimal conv
hex proc near
push ax
push bx
push cx
push dx
              disp msgn        ;new line
              disp msg2        ;sum:
              mov cl,00h
              mov ax,sum
              mov ah,00h
              mov bx,0AH
       d1:
              mov dx,00h
              div bx
              push dx
              inc cl
              cmp ax,00h
              jne d1
      d2:
              pop dx
              add dl,30h
              mov ah,02h
              int 21h
              dec cl
              jnz d2
pop dx
pop cx
pop bx
pop ax

ret
endp

end

No comments:

Post a Comment