The Program given below receives N numbers from console,computes the sum of those numbers and prints the result.
print macro msg
mov ah,09h
mov dx,offset msg
int 21h
endm
readnum macro num
mov ah,01h
int 21h
sub al,'0'
mov bh,0ah
mul bh
mov num,al
mov ah,01h
int 21h
sub al,'0'
add num,al
endm
data segment
cr equ 0dh
lf equ 0ah
msg1 db 'Enter the limit:','$'
msg3 db cr,lf,'Enter the no:','$'
msg2 db cr,lf,'sum=','$'
lmt db ?
temp db ?
arr db 15 dup(0)
rslt db 2 dup(0)
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
print msg1
readnum lmt
mov ch,00h
mov cl,lmt
mov si,00h
l1:print msg3
readnum temp
mov al,temp
mov arr[si],al
inc si
loop l1
mov ch,00h
mov cl,lmt
mov bx,00h
mov si,00h
mov ax,0000h
l2: mov bh,00h
mov bl,arr[si]
add ax,bx
mov rslt,al
inc si
loop l2
mov si,offset rslt
call hexa2asc
print msg2
print rslt
mov ah,4ch
mov al,00h
int 21h
hexa2asc proc near
push ax
push bx
push cx
push dx
push si
mov cx,00h
mov bx,0ah
rpt1: mov dx,00h
div bx
add dl,'0'
push dx
inc cx
cmp ax,0ah
jge rpt1
add al,'0'
mov [si],al
rpt2:
pop ax
inc si
mov [si],al
loop rpt2
inc si
mov al,'$'
mov [si],al
pop si
pop dx
pop cx
pop bx
pop ax
ret
hexa2asc endp
code ends
end start
No comments:
Post a Comment