Thursday, January 21, 2010

8086 or MASM PROGRAM to input 9 digits and display the second biggest number that can be formed using those digits

assume ds:data1,cs:code1,ss:stack1
stack1 segment
store1 db 10,0,10 dup('$')
stack1 ends
data1 segment
msg db 0ah,0dh,'enter the 9 digit number$'
number db 12,0,12 dup('$')
msg1 db 0ah,0dh,'the rearranged order is=$'
data1 ends
stack1 segment
store db 10,0,10 dup('$')
stack1 ends
code1 segment
start;mov ax,seg data1
mov ds,ax
lea dx,msg
mov ah,09h
int 21h
lea dx,number
mov ah,0ah
int 21h
mov cx,0008h
pass:push cx
mov cx,0008h
lea dx,number+2
mov si,dx
again:mov al,[si]
cmp al,[si+1]
jnc down
xchg al,[si+1]
xchg al,[si]
down:
inc si
loop again
pop cx
loop pass
mov al,[si]
xchg al,[si-1]
xchg al,[si]
lea dx,msg1
mov ah,09h
int 21h
lea dx,number+2
mov ah,09h
int 21h
mov ah,4ch
int 21h
code1 ends
end start

8086 or MASM PROGRAM to display the multiplication table (first 10 values) for a number N(<10d)

assume ds:data1,cs:code1
data1 segment
msg db 0ah,0dh,'enter the number$'
number db 2,0,2 dup('$')
decimal db '0','1','2','3','4','5','6','7','8','9'
ans db 0ah,'0','*','0','=','0','0','$'
data1 ends
code1 segment
start;mov ax,seg data1
mov ds,ax
lea dx,msg
mov ah,09h
int 21h
mov cx,000ah
mov dl,0ah
mov ah,02h
int 21h
lea dx,number
mov ah,0ah
int 21h
lea dx,number
inc dx
inc dx
mov di,dx
mov bl,[di]
and bl,0fh
lea dx,ans
inc dx
mov si,dx
mov dl,[di]
mov [si],dl
lea dx,ans
inc dx
mov di,dx
lea dx,decimal
mov si,dx
again:lea dx,ans
inc dx
mov di,dx
mov al,[si]
inc di
inc di
mov [di],al
mov bh,[si]
mov ax,0000h
and bh,0fh
mov al,bh
mul bl
aam
add ax,03030h
inc di
inc di
mov [di],ah
inc di
mov [di],al
lea dx,ans
mov ah,09h
int 21h
inc si
loop again
mov ah,4ch
int 21h
code1 ends
end start

8086 OR MASM PROGRAM TO CONVERT THE Given temperature in Centigrade(<100°C) to Fahrenheit and Kelvin and display it (i/p and o/p as Decimal numbers)

assume ds:data1,cs:code1
data1 segment
msg db 0ah,0dh,'enter the temperature in degree celsius',0ah,'$'
msg1 db 0ah,0dh,'error! enter a temperature less than 99 degree C$'
msg2 db 0ah,0dh,'the temperature in kelvin scale is=$'
msg3 db 0ah,0dh,'the temperature in farenheit scale is approximately=$'
msg4 db 0ah,0dh,'the temperature in celsius scale is=$'
temp db 6,0,6 dup('$')
result db 20,0,20 dup('$')

data1 ends
code1 seg
start:mov ax,seg data1
mov ds,ax

lea dx,msg
mov ah,09h
int 21h

mov ch,02h

ask:
lea dx,temp
mov ah,0ah
int 21h

lea dx,msg4
mov ah,09h
int 21h

lea dx,temp+2
mov ah,09h
int 21h

do:
lea bx,temp+1
mov cl,[bx]
inc bx
mov ah,[bx]
dec cl
jz down
mov al,[bx+1]
dec cl
jz down1
lea dx,msg1
mov ah,09h
int 21h
jmp ask

down:
mov al,ah
mov ah,00h
down1:
and ax,0f0fh
aad
dec ch
jz second
add ax,0111h;273 addition
call display
lea dx,msg2
call show
jmp do
second:
mov cl,09h
mul cl
mov cl,05h
div cl
mov ah,00h
add al,20h;hex equivalent of 32
call display
lea dx,msg3
call show
jmp over

display:lea bx,result+4
mov dl,03h
mov cl,0ah
again:
div cl
add ah,30h
mov [bx],ah
dec bx
mov ah,00h
dec dl
jnz again
ret

show:
mov ah,09h
int 21h
lea dx,result+2
mov ah,09h
int 21h
ret
over:
mov ah,4ch
int 21h
code1 ends

8086 OR MASM PROGRAM TO Count and display the number of occurrances of (i) vowels (ii) a given word from a given string

assume ds:data1,cs:code1
data1 segment
msg db 0ah,0dh,'enter the word in small letters',0ah,'$'
msg1 db 0ah,0dh,'the number of vowels in the given string is=$'
msg2 db 0ah,0dh,'the number of occurance of the word in the given string is=$'
vowel db 'a','e','i','o','u'
enter db 'is is is$'
get db 20,0,20 dup('$')
data1 ends
code1 segment
start:mov ax,seg data1
mov ds,ax
lea dx,msg1
mov ah,09h
int 21h
lea bx,enter
mov si,bx
mov bl,00h
check:
lea dx,vowel
mov di,dx
mov dx,0005h
mov al,[si]
repeat1:cmp al,[di]
jz down
inc di
dec dl
jnz repeat1
jmp have
down:inc bl
have:inc si
mov dh,'$'
cmp [si],dh
jnz check
mov dl,bl
add dl,30h
mov ah,02h
int 21h

lea dx,msg
mov ah,09h
int 21h

lea dx,get
mov ah,0ah
int 21h

lea dx,msg2
mov ah,09h
int 21h

lea dx,enter
mov si,dx
mov dx,0000h
again:
lea bx,get+1
mov cl,[bx]
inc bx
mov di,bx
again1:
mov al,[si]
cmp al,[di]
jnz under
inc si
inc di
loop again1
mov bl,20h
cmp [si],bl;ASCII OF SPACE
jz found
mov bl,24h
cmp [si],bl;ASCII of $
jz found
under:inc si
mov bl,20h
cmp [si],bl
jz do
mov bl,24h
cmp [si],bl
jz over
jmp under
found:
inc dl
do:inc si
mov bl,24h
cmp [si],bl
jz over
jmp again
over:add dl,30h
mov ah,02h
int 21h
mov ah,4ch
int 21h
code1 ends

8086/MASM PROGRAM TO CHECK WHETHER THE MOBILE NUMBER ENTERED THROUGH KEYBOARD IS DIVISIBLE BY NINE

assume ds:data,cs:code
data segment
msg db 0ah,0dh,'enter the mobile number$'
number db 20,0,20 dup('$')
yes db 0ah,0dh,'YES$'
no db 0ah,0dh,'NO$'
data ends
code segment
start:mov ax,seg data
mov ds,ax

lea dx,msg
mov ah,09h
int 21h

lea dx,number
mov ah,0ah
int 21h

lea dx,number
mov sl,dx
inc si
inc si
mov cx,000ah

again:mov al,[si]
and al,0fh
mov [si],al
inc si
loop again

lea dx,number
mov si,dx
inc si
inc si
mov cx,0009h
mov ax,0000h
mov ai,[si]
adding:add al,[si+1]
inc si
loop adding
mov bl,03h
div bl
and ah,0ffh
jz yess

lea dx,no
mov ah,09h
int 21h
jmp down

yess:lea dx,yes
mov ah,09h
int 21h

down: mov ah,4ch
int 21h
code ends