ALP to add array of N hexadecimal numbers stored in the memory. Accept input from the user

, by Prashant Gunjal


1. Write 8086 Assembly language program (ALP) to add array of N hexadecimal numbers stored in the memory. Accept input from the user.


.model small
.data
msg1 db 10,13,"Enter size of array:$"
msg2 db 10,13,"Enter two bit no:$"
msg3 db 10,13,"addtion:$"
arr db 10h dup(?)
n1 db 00h
.code

mov ax,@data
mov ds,ax ;store contents of ax in DS

lea dx,msg1 ;display msg1
mov ah,09h
int 21h

mov ah,01h ;accept the number of elements in array
int 21h

sub al,30h ;subtract 30 from al
cmp al,09h
jbe l4
sub al,07h

l4:
lea si,arr ;stores array contents in si
mov ch,al ;move contents in ch
mov n1,ch ;move ch in n1

l2:
lea dx,msg2 ;display msg 1
mov ah,09h
int 21h

mov ah,01h ;accept 1st number
int 21h

sub al,30h ;subtract 30 from al
cmp al,09h
jbe l5

sub al,07h
l5:
mov bh,al ;mov al contents in bh

mov ah,01h ;accept 2nd number
int 21h

sub al,30h ;subtract 30 from al
cmp al,09h
jbe l6
sub al,07h

l6:
mov bl,al ;mov al content in bl
mov cl,04h ;cl is counter having value 4

rol bh,cl ;rotate bh contents 4 times
add bh,bl ;mov bl contents to bh
mov[si],bh ;mov bh in si offset
inc si

dec ch
jnz l2 ;jump if not zero

lea dx,msg3 ;display msg 3
mov ah,09h
int 21h

mov ch,n1 ;mov n1 to ch
lea si,arr ;mov array content in si
mov bh,[si] ;mov si data to bh

l3: inc si
add bh,[si] ;add si to bh
dec ch
jnz l3 ;jump till ch is zero

mov cx,0204h ;cx is counter

l1: rol bh,cl ;rotate bh contents 4 times
mov bl,bh ;mov bh in bl
and bh,0fh ;anding bh of times
mov dl,bh ;mov bh in dl

cmp dl,09h
jbe l7
add dl,07h
l7: add dl,30h

mov ah,02h ;display number
int 21h

mov bh,bl ;mov bl in bh
dec ch
jnz l1

mov ah,4ch ;termination
int 21h
end

#### Output ###

C:\TASM>tasm ass1.asm
Turbo Assembler  Version 2.0  Copyright (c) 1988, 1990 Borland International

Assembling file:   ass1.asm
Error messages:    None
Warning messages:  None
Passes:            1
Remaining memory:  476k


C:\TASM>tlink ass1.obj
Turbo Link  Version 3.0 Copyright (c) 1987, 1990 Borland International
Warning: No stack

C:\TASM>ass1

Enter size of array:2
Enter two bit no:2C
Enter two bit no:3A
addtion:66
C:\TASM>

0 comments: