; Program of adding the elements from the array
;---------------------------------------------------------------------------
.model small
.data
message_disp macro msg ; macro for message display
mov dx,offset msg
mov ah,09h
int 21h
endm
msg1 db 10,13, "Array Addition's Program $"
msg2 db 10,13, "How many elements you want to add ? $"
msg3 db 10,13, "Enter Number $"
msg4 db 10,13, "Addition is $"
no_of_elements db ?
array db 0Ah dup(0)
result db 0
fd db 0
.code
mov ax,@data
mov ds,ax
message_disp msg1 ; display message 1
message_disp msg2 ; display message 2
mov ah,01h ; take no. of elements i/p
int 21h
cmp al,39h
jbe dnt_sub
sub al,07h
dnt_sub: sub al,30h
mov no_of_elements,al
mov bh,no_of_elements
lea si,array ; load base address of array
; in si register
accept_number:
message_disp msg3
call accept
mov [si],bl
inc si
dec bh
jnz accept_number
lea si,array
mov bh,no_of_elements
mov ch,00h
addition:
add ch,[si]
adc fd,00h
inc si
dec bh
jnz addition
call disply
mov ah,4ch ;terminate program
int 21h
disply proc near
message_disp msg4
mov dl,fd
add dl,30h
mov ah,02h
int 21h
mov cl,04h
mov dh,02h
mov bh,ch
shr ch,cl
disp_bit: and ch,0Fh
cmp ch,09h
jbe dnt_add1
add ch,07h
dnt_add1: add ch,30h
mov dl,ch
mov ah,02h
int 21h
mov ch,bh
dec dh
jnz disp_bit
endp
accept proc near
mov cl,04h
mov ah,01h
int 21h
cmp al,39h
jbe dnt_sub1
sub al,07h
dnt_sub1: sub al,30h
shl al,cl
mov bl,al
mov ah,01h
int 21h
cmp al,39h
jbe dnt_sub2
sub al,07h
dnt_sub2: sub al,30h
or bl,al
ret
endp
end
;----------------------------------------------------------------------------
; program done by Prof. Dhumane A.V. VIIT, Pune
No comments:
Post a Comment