Mml Lab Code_bit
Mml Lab Code_bit
1) Write an 8086 assembly language program to get an 8 bit data as user input
and display the Fibonacci series in decimal until the user input has reached. For
every display a delay of 5 secs is to be generated.
#start=led_display.exe#
name "led"
#make_bin#
jmp start
msg db "Enter a number:","$"
start:
mov bh,0
mov bl,10d
lea dx,msg
mov ah,9
int 21h
input:
mov ah,1
int 21h
cmp al,13
jne number
je fibo
number:
sub al,30h
mov cl,al
mov al,bh
mul bl
add al,cl
mov bh,al
jmp input
fibo:
mov al,1
mov bl,1
mov dl,bh
jmp generate
generate:
out 199,al
add al, bl
xchg al, bl
mov cx, 5bh
mov ah, 86h
int 15h
cmp al,dl
jg exit
jne generate
exit:
mov ah,4ch
int 21h
2) Write a 8086 AIP to add an array of 16 bit numbers and store the result as
unpacked number as ASCII for example if the output is 47 it should be stored as
34 & 37 in consecutive locations. And display the number as on the LED with
day causing INT
#start=led_display.exe#
name="led"
org 100h
.data
array db 10, 10, 10, 10,7
count dw 5
result db ?
ascii_result db ?, ?
.code
start:
xor ax, ax
mov cx, count
lea si, array
sum_loop:
MOV bl,[si]
add al, bl
inc si
loop sum_loop
mov result, al
mov bl, 10
div bl
add al, 30
mov ascii_result, al
add ah, 30
mov ascii_result + 1, ah
lea si,ascii_result
mov cx, 2
display_loop:
MOV al,[si]
out 199, al
MOV bx,cx
push bx
MOV cx , 150
wait2:
NOP
loop wait2
pop bx
MOV cx,bx
inc si
loop display_loop
3) Construct digital calculator by getting an input from the user where, for 0
copy the block data, 1 -> sorting, 2 -> find the data that match and display
them, 3 -> do nothing
#start=simple.exe#
name ="simple"
#make_bin#
#start=led_display.exe#
name ="led"
#make_bin#
.stack 100h
jmp start
#start=Traffic_Lights.exe#
name "traffic"
#make_bin#
jmp start:
sit_A dw 0000_0011_0000_1100b
sit_B dw 0000_1000_0110_0001b
sit_C dw 0000_0100_1001_0010b
all_red dw 0000_0010_0100_1001b
msg db 10,13,"Enter the character :$"
start:
MOV ax,all_red
out 4,ax
input:
lea dx,msg
MOV ah,09h
int 21h
MOV ah,1
int 21h
cmp al,'A'
je north_south_south_north
cmp al,'B'
je east_west_west_east
cmp al,'C'
je all_yellove
jmp input
north_south_south_north:
MOV ax,sit_A
OUT 4,ax
MOV cx,4Ch
MOV dx,4B40h
MOV ah,86h
int 15h
jmp start
east_west_west_east:
MOV ax,sit_B
OUT 4,ax
MOV cx,4Ch
MOV dx,4B40h
MOV ah,86h
int 15h
jmp start
all_yellove:
MOV ax,sit_C
OUT 4,ax
MOV cx,4Ch
MOV dx,4B40h
MOV ah,86h
int 15h
jmp start:
5) Write an Assembly Language program using 8086 to interface stepper motor
and perform the following operations : rotate the motor in the clockwise
direction for 10 times and rotate the motor in anti-clockwise direction for 10
times. Display the count in data field.
#start=stepper_motor.exe#
name "stepper"
#make_bin#
#start=led_display.exe#
#make_bin#
name "led"
jmp start
datcw_fs db 0000_0001b
db 0000_0011b
db 0000_0110b
db 0000_0000b
dataccw_fs db 0000_0100b
db 0000_0110b
db 0000_0011b
db 0000_0000b
msg db "HALT","$"
flg dw 0
start:
mov dx,0
mov ax,dx
out 199,ax ; clearing the led
mov bx, offset datcw_fs ;stepper motor operation
l1:
mov si, 0
mov cx, 0
next_step:
wait: in al, 7
test al, 10000000b
jz wait
mov al, [bx][si]
out 7, al
inc si
cmp si, 4
jb next_step
mov si, 0
inc cx ; 4 si = 1 cx
cmp cx, 08 ; cx=8 corresponds to one complete rotation
je dis
jne next_step
dis:
inc dx
MOV ax,dx
out 199,ax
cmp dx,0Ah ;10 rotations per direction yall
jne l1
MOV bx,offset dataccw_fs
inc flg
xor dx,dx
cmp flg,02h
je end
jmp l1
end:
MOV ah,09h
lea dx,msg
int 21h
ret
hlt
6) Write an 8086 ALP to read a string as input and extract the EVEN and ODD
positioned characters and coin as the words separately. Example "HELLODEAR",
to be extracted I as "ELDA" and "HLOER' and find the length of the new strings
if the length of both strings are equal compare the strings and display the
result else reverse the original string and print(use INT for string display).
data segment
msg db "Enter a string:","$"
msg1 db 10,13,"Both the new strings have equal length","$"
msg2 db 10,13,"Both the new strings have unequal length","$"
msg3 db 10,13,"Comparison: Both are equal","$"
msg4 db 10,13,"Comparison: Both are unequal","$"
msg5 db 10,13,"Reversed string is:","$"
msg6 db 10,13,"Odd index string:","$"
msg7 db 10,13,"Even index string:","$"
arr db 15 dup('$')
arr1 db 15 dup('$')
arr2 db 15 dup('$')
rev db 15 dup('$')
ends
code segment
start:
mov ax, data
mov ds, ax
mov es,ax
lea dx,msg
mov ah,9
int 21h
lea si,arr
l1:
mov ah,1
int 21h
cmp al,13
jz odd
mov [si],al
inc si
jmp l1
odd:
lea si,arr
lea di,arr1
l2:
cmp [si],'$'
jz even
mov al,[si]
mov [di],al
add si,2
inc di
jmp l2
even:
lea si,arr+1
lea di,arr2
l3:
cmp [si],'$'
jz dis
mov al,[si]
mov [di],al
add si,2
inc di
jmp l3
dis:
mov ah,9
lea dx,msg6
int 21h
lea dx,arr1
int 21h
lea dx,msg7
int 21h
lea dx,arr2
int 21h
count:
mov bx,0
mov dx,0
lea si,arr1
lea di,arr2
l4:
cmp [si],'$'
jz l5
inc si
inc bx
jmp l4
l5:
cmp [di],'$'
jz compare
inc di
inc dx
jmp l5
compare:
cmp bx,dx
jz eq
jmp uneq
eq:
lea dx,msg1
mov ah,9
int 21h
cld
lea si,arr1
lea di,arr2
mov cx,bx
repe cmpsb
jnz note
lea dx,msg3
mov ah,9
int 21h
jmp exit
note:
lea dx,msg4
mov ah,9
int 21h
jmp exit
uneq:
add bx,dx
mov cx,bx
dec bx
lea si,arr
lea di,rev
add si,bx
l:
mov al,[si]
mov [di],al
dec si
inc di
dec cx
cmp cx,0
jnz l
lea dx,msg2
mov ah,9
int 21h
lea dx,msg5
mov ah,9
int 21h
lea dx,rev
mov ah,9
int 21h
exit:
ends
end start
7) Write an 8086 Assembly Program to read a character as input from the user
and perform the specified operations on a given string. If the character is 'a',
sort the string in ascending order (i/p - EXAM, o/p - AEMX), if the character is
'd', sort the string in descending order (i/p - EXAM, XMEA) and if the character
is 'e', extract a character and then print the string (CH = 'A', o/p - EXM).
org 100h
jmp start
msg2 db 10, 13, "Enter the operation ('a' for ascending, 'd' for descending, 'e'
for extraction): $"
msg3 db 10, 13, "Enter the character to extract: $"
msg4 db 10, 13, "Result: $"
str_arr db 'E','X','A','M'
str2 db ?,?,?,?
len db 4 ; String length
char db ? ; Character input for operation
extract db 'A' ; Character to extract
start:
lea dx, msg2
mov ah, 09h
int 21h
mov ah, 01h ; Read operation character
int 21h
mov char, al
cmp char, 'a'
je sort_asc
cmp char, 'd'
je sort_desc
cmp char, 'e'
je extract_char
jmp end_program ; Exit for invalid input
sort_asc:
mov cl,len
outer:
lea si,str_arr
mov dl,len
dec dl
inner:
mov al, [si]
mov ah, [si + 1]
cmp al, ah
jbe no_swap ; Skip if in order
xchg al, ah ; Swap characters
mov [si], al
mov [si + 1], ah
no_swap:
inc si
dec dl
jnz inner
dec cl
jnz outer
jmp end_program
sort_desc:
mov cl, len
outerd:
lea si,str_arr
mov dl,len
dec dl
innerd:
mov al, [si]
mov ah, [si + 1]
cmp al, ah
jbe no_swapd ; Skip if in order
xchg al, ah ; Swap characters
mov [si], al
mov [si + 1], ah
no_swapd:
inc si
dec dl
jnz innerd
dec cl
jnz outerd
rev:
lea si,str_arr
lea di,str2
MOV cx,4
dec cx
add si,cx
MOV cx,4 ; reverse for desending yall
l2:
MOV al,[si]
MOV [di],al
dec si
inc di
dec cx
jnz l2
jmp end_program
extract_char:
lea si,str_arr
lea di,str2
MOV cx,4
ex1:
MOV al,[si]
cmp al,extract
je skip
MOV [di],al
inc si
inc di
loop ex1
jmp end_program
skip:
inc si
jmp ex1
end_program:
ret
mov ah,4Ch
int 21h
8) Write an 8086 ALP to interface I/O to read the key press, if the key pressed is
'0' implement digital clock for only secs display on the LED in decimal. If key
pressed is '2' get an array as input and swap the higher order bits with lower
order bits eg. 23,56,89 etc...o/p 32,65,98.... Other than 0 & 2 as input-program
should not respond.
#start=led_display.exe#
name "led"
#make_bin#
#start=simple.exe#
name "simple"
#make_bin#
jmp start
msg db 10,13, "Enter 0-> digital clock 2-> Array swap in I/O port 110$"
msg1 db 10,13,"Enter number:$"
arr1 db 10 dup(0)
arr2 db 10 dup(0)
len db 5
start:
MOV ah,9
lea dx,msg
int 21h
in al,110
cmp al,2
je array
cmp al,0
je clock
jmp exit
array:
MOV ch,len
lea si,arr1
lp1:
MOV bl,10d
MOV bh,0
MOV ah,09h
lea dx,msg1
int 21h
inp:
MOV ah,1
int 21h
cmp al,13
jne store
jmp next_ele
store:
sub al,30h ; convert ascii to number digit
MOV cl,al
MOV al,bh
mul bl
add al,cl
MOV bh,al
jmp inp
next_ele:
MOV [si],bh
inc si
dec ch
jz swap
jmp lp1
swap:
lea si,arr1
lea di,arr2
MOV cx,5
lp3:
MOV al,[si]
MOV bl,10
MOV ah,0
div bl
MOV bl,ah ;swap digits
MOV dl,al
MOV al,10
mul bl
add al,dl
MOV [di],al
inc si
inc di
loop lp3
jmp exit
clock:
MOV al,0
OUT 199,al
MOV bl,1
lp4:
MOV al,bl
OUT 199,al
inc bl
MOV cx,0Ch
MOV dx,4B40h ; delay
MOV ah,86h
int 15h
cmp bl,20
je exit
jmp lp4
exit:
MOV ah,4ch
int 21h
9) Write a 8086 ALP to read a key press using interrupt If key pressed is 'S' read
a sentence and identify the number of spaces in the sentences. If key pressed is
'V', count the number of vowels.
org 100h
jmp start:
msg1 db 10,13,"Enter sentence :$"
msg2 db 10,13,"Enter S--> space count V-> Vowel count : $"
vow_count db EQU 0
space_count db EQU 0
start:
MOV ah,09h
lea dx,msg2
int 21h
MOV ah,1
int 21h
cmp al,'S'
je space_countl
cmp al,'V'
je vowel_count
jmp exit
space_countl:
MOV ah,09h
lea dx,msg1
int 21h
input:
MOV ah,1
int 21h
cmp al,13
je exit
cmp al,' '
je inc_space
jmp input
inc_space:
inc space_count
jmp input
vowel_count:
MOV ah,09h
lea dx,msg1
int 21h
input2:
MOV ah,1
int 21h
cmp al,13
je exit
cmp al,'a'
jz inc_vow
cmp al,'A'
jz inc_vow
cmp al,'e'
jz inc_vow
cmp al,'E'
jz inc_vow
cmp al,'i'
jz inc_vow
cmp al,'I'
jz inc_vow
cmp al,'o'
jz inc_vow
cmp al,'O'
jz inc_vow
cmp al,'u'
jz inc_vow
cmp al,'U'
jz inc_vow
jmp input2
inc_vow:
inc vow_count
jmp input2
exit:
MOV ah,4ch
int 21h
10) Write an 8086 ALP to get input from I/O ports for temperature monitoring
system: if input is not within the range of 40 to 80 display an error msg and
repeat reading the input until it falls in the required range. When the
temperature reaches >=80 rotate the stepper in clockwise for 3 times and
display the msg as 'motor started' . Again, if the temperature goes down
#start=stepper_motor.exe#
name "stepper"
#make_bin#
#start=thermometer.exe#
name "thermo"
#make_bin#
jmp start:
motorcw_fs db 0000_0001b
db 0000_0011b
db 0000_0110b
db 0000_0000b
motorccw_fs db 0000_0100b
db 0000_0110b
db 0000_0011b
db 0000_0000b
msg db 10,13, "Error$"
msgg db 10,13, "OK!$"
msg1 db 10,13 ,"Motor rotating clockwise...$"
msg2 db 10,13 ,"Motor rotating counter clockwise...$"
start:
input:
MOV cx ,150
wait3:
NOP
dec cx
jnz wait3
in al,125 ; get thermometer value
cmp al,40
jl low
cmp al,80
jg high
lea dx,msgg
MOV ah,09h
int 21h
jmp input
low:
lea dx,msg
MOV ah,09h
int 21h
lea dx,msg2
MOV ah,09h
int 21h
MOV bx,offset motorccw_fs
MOV dx,0
MOV si,0
rot:
wait1:
in al,7
test al,10000000b
jz wait1
MOV al,[bx][si]
out 7,al
inc si
cmp si,4
jne rot
MOV si,0
inc dx
cmp dx,24 ; 8 x 3 ( 3 rotations )
jne rot
jmp input
high:
lea dx,msg
MOV ah,09h
int 21h
lea dx,msg1
MOV ah,09h
int 21h
MOV bx,offset motorcw_fs
MOV si,0
MOV dx,0
rot2:
wait2:
in al,7
test al,10000000b
jz wait2
MOV al,[bx][si]
out 7,al
inc si
cmp si,4
jne rot2
MOV si,0
inc dx
cmp dx,24
jne rot2
jmp input
11) Write an assembly language program using 8086 to interface stepper motor
and perform the following operations. Get the number of rotations as user
input, for every rotation count should be displayed on the LED, when the count
reaches desired input, rotate the motor towards anticlockwise direction and
decrement the count for every complete rotation stop the motor when count
reaches 0
#start=stepper_motor.exe#
name "stepper"
#make_bin#
#start=led_display.exe#
#make_bin#
name "led"
jmp start
msg1 db 10,13,'Enter the number of rotations:$'
str1 db 10,13,'HALT$'
datcw_fs db 0000_0001b
db 0000_0011b
db 0000_0110b
db 0000_0000b
datccw_fs db 0000_0100b
db 0000_0110b
db 0000_0011b
db 0000_0000b
start:
mov ax,0
out 199,ax
mov dx,0
lea dx,msg1
mov ah,09h
int 21h
mov dh,0
mov dl,10d
input:
mov ah,1
int 21h
cmp al,13
jne number
mov dl,0
mov ah,0
jmp next
number:
sub al,30h
mov cl,al
mov al,dh
mul dl
add al,cl
mov dh,al
jmp input
next:
mov bx, offset datcw_fs
l1:
mov si, 0
mov cx, 0
next_step:
wait: in al, 7
test al, 10000000b
jz wait
mov al, [bx][si]
out 7, al
inc si
cmp si, 4
jb next_step
mov si, 0
inc cx
cmp cx,8
jz dis
jmp next_step
next1:
mov bx,offset datccw_fs
l2:
mov si,0
mov cx,0
next_step1:
wait1: in al, 7
test al, 10000000b
jz wait1
mov al, [bx][si]
out 7, al
inc si
cmp si, 4
jb next_step1
mov si, 0
inc cx
cmp cx,8
jz dis1
jmp next_step1
dis:
inc dl
mov al,dl
out 199,ax
cmp dh,dl ; same move on to anticlockwise
jz next1
jmp l1
dis1:
dec dl
mov al,dl
out 199,al
cmp dl,0
jz halt
jmp l2
halt:
lea dx,str1
mov ah,09h
int 21h
mov ah,4ch
int 21h
12) Write a program using 8086 instruction set to compare the two blocks of
memory and store the number of matches and mismatches at diAerent
locations. Print the count of matching and mismatching on the LED with a
delay.
#start=led_display.exe#
#make_bin#
name "led"
arr1 db 1,2,3,4,5
arr2 db 1,2,3,8,5
cnt dw 5
mov ax,00h
out 199,ax
lea si,arr1
lea di,arr2
mov cx,cnt
mov bx,0
compare:
mov al,[si]
cmp al,[di]
jz eq
inc bh ; to store unlike count
l1:
inc si
inc di
dec cx
jnz compare
jmp dis
eq:
inc bl ; to store like count
jmp l1
dis: ; to display in LED
mov al,bl
out 199,al
mov cx,2Ch
mov dx,4B40h
mov ah,86h
int 15h
mov al,bh
out 199,al
hlt
ret
13) Write an Assembly Language Program to interface TraAic liOt system to
simulate the following rules 1. Enable the signals for the vehicles to move from
west to east and east to west for 2 secs. Then north to south and south to
north for 2 secs. After 2 secs , all amber should blink.
#start=Traffic_Lights.exe#
name "traffic"
#make_bin#
jmp start:
sit_nor_sou dw 0000_0011_0000_1100b
sit_wes_eas dw 0000_1000_0110_0001b
sit_amber dw 0000_0100_1001_0010b
all_red dw 0000_0010_0100_1001b
start:
MOV ax,all_red
out 4,ax
MOV ax,sit_wes_eas
OUT 4,ax
;delay using interrupt or use a for loop
MOV cx,4Ch
MOV dx,4B40h
MOV ah,86h
int 15h
MOV ax,sit_nor_sou
OUT 4,ax
MOV cx,4Ch
MOV dx,4B40h
MOV ah,86h
int 15h
MOV ax,sit_amber
OUT 4,ax
;delay using interrupt or use a for loop
MOV cx,4Ch
MOV dx,4B40h
MOV ah,86h
int 15h
MOV ah,4ch
int 21h
14) Write an assembly language program to simulate digital clock such that the
key press using int , if key pressed is 1. No operation 2. Simulate seconds
display from 59,58,....0 3. Simulate seconds display from 0,1,2,....59 4 - Flash
"00" on the LED interface
#start=led_display.exe#
name "led"
#make_bin#
jmp start
msg db "Enter a number:","$"
start:
MOV ah,9
lea dx,msg
int 21h
MOV ah,01h
int 21h
cmp al,'1'
je exit
cmp al,'2'
je desec
cmp al,'3'
je asec
desec:
MOV bl,59
lo1:
MOV al,bl
OUT 199,al
dec bl
MOV cx,0Ch
MOV dx,4B40h ; delay
MOV ah,86h
int 15h
cmp bl,0
je exit
jmp lo1
asec:
MOV bl,0
lo2:
MOV al,bl
OUT 199,al
inc bl
MOV cx,0Ch
MOV dx,4B40h ; delay
MOV ah,86h
int 15h
cmp bl,59
je exit
jmp lo2
exit:
MOV ah,4ch
int 21h