Mml Lab Code_bit9
Mml Lab Code_bit9
MML CODE unpacked number as ASCII for example if the output is 47 it should be stored as
mov bh,al
34 & 37 in consecutive locations. And display the number as on the LED with
1) Write an 8086 assembly language program to get an 8 bit data as user input jmp input day causing INT
and display the Fibonacci series in decimal until the user input has reached. For fibo:
every display a delay of 5 secs is to be generated.
mov al,1 #start=led_display.exe#
#start=led_display.exe#
mov bl,1 name="led"
name "led"
mov dl,bh org 100h
#make_bin#
jmp generate .data
jmp start
generate: array db 10, 10, 10, 10,7
msg db "Enter a number:","$"
out 199,al count dw 5
start:
add al, bl result db ?
mov bh,0
xchg al, bl ascii_result db ?, ?
mov bl,10d
mov cx, 5bh .code
lea dx,msg
mov ah, 86h start:
mov ah,9
int 15h
int 21h
cmp al,dl xor ax, ax
input:
jg exit mov cx, count
mov ah,1
jne generate lea si, array
int 21h
exit: sum_loop:
cmp al,13
mov ah,4ch MOV bl,[si]
jne number
int 21h add al, bl
je fibo
inc si
number:
loop sum_loop
sub al,30h
mov result, al
mov cl,al
mov bl, 10
mov al,bh
div bl
mul bl
add al, 30 3) Construct digital calculator by getting an input from the user where, for 0 cmp al,3
copy the block data, 1 -> sorting, 2 -> find the data that match and display
mov ascii_result, al jz nothing ; Else, exit program
them, 3 -> do nothing
add ah, 30 blc_move:
mov ascii_result + 1, ah MOV cl,arr_len ; Load array length into CL
#start=simple.exe#
lea si,ascii_result lea si,ar1 ; Load address of ar1 into SI
name ="simple"
mov cx, 2 lea di,move_arr ; Load address of ar2 into DI
#make_bin#
display_loop: lo1:
#start=led_display.exe#
MOV al,[si] MOV al,[si] ; Move byte from ar1
name ="led"
out 199, al MOV [di],al ; Copy it to ar2
#make_bin#
MOV bx,cx inc si ; Increment source index
.stack 100h
push bx inc di ; Increment destination index
jmp start
MOV cx , 150 loop lo1 ; Repeat for all elements
wait2: jmp exit ; Exit after block move
ar1 db 5,2,4,4,1 ; Original array 1
NOP blk_sort:
ar2 db 3,2,6,4,9 ; Original array 2
loop wait2 MOV cl,arr_len
move_arr db ?,?,?,?,?
pop bx outer:
eq_count db ? ; Count of equal elements
MOV cx,bx lea si, ar1
arr_len db 5 ; Array length
inc si MOV dl, arr_len
msg db 10,13, "Program exited successfully$"
loop display_loop dec dl
start:
inner:
in al,110 ; Input from I/O port 110
MOV al, [si]
cmp al,0
MOV ah, [si + 1]
jz blc_move ; If input is 0, block move
cmp al, ah
cmp al,1
jbe nochange
jz blk_sort ; If input is 1, block sort
xchg al, ah
cmp al,2
MOV [si], al
jz blk_cmp ; If input is 2, block match
MOV [si + 1], ah OUT 199,al 4) Write a 8086 assembly language code for Traffiic light system for the
following conditions: i)If a key is pressed, eg: if 'A' is the key pressed then
nochange: ; Store equal count in eq_count
vehicles should move from north to south and south to north with a delay of
inc si jmp exit 2secs. ii)If B is the key pressed then vehicles should move from east to west
dec dl nothing: and west to east with a delay of 2secs. iii) If C is the key pressed then, yellow
should blink
jnz inner MOV ah,09h
dec cl lea dx,msg
#start=Traffic_Lights.exe#
jnz outer int 21h
name "traffic"
jmp exit exit:
#make_bin#
blk_cmp: hlt ; Halt the program
jmp start:
lea si,ar1 ; Load address of ar1 into SI
sit_A dw 0000_0011_0000_1100b
lea di,ar2 ; Load address of ar2 into DI
sit_B dw 0000_1000_0110_0001b
MOV cl,arr_len ; Load array length into CL
sit_C dw 0000_0100_1001_0010b
MOV dl,0 ; Initialize equal count to 0
all_red dw 0000_0010_0100_1001b
lpc1:
msg db 10,13,"Enter the character :$"
MOV al,[si] ; Load byte from ar1
start:
CMP al,[di] ; Compare with byte from ar2
MOV ax,all_red
JNE not_equal ; If not equal, skip increment
out 4,ax
INC dx ; Increment equal count
input:
not_equal:
lea dx,msg
inc si ; Increment source index
MOV ah,09h
inc di ; Increment destination index
int 21h
dec cl ; Decrement counter
MOV ah,1
cmp cl,0 ; Check if all elements processed
int 21h
jnz lpc1 ; Repeat if not done
cmp al,'A'
MOV eq_count,dl
je north_south_south_north
MOV al,dl
cmp al,'B'
je east_west_west_east int 15h 5) Write an Assembly Language program using 8086 to interface stepper motor
and perform the following operations : rotate the motor in the clockwise
cmp al,'C' jmp start:
direction for 10 times and rotate the motor in anti-clockwise direction for 10
je all_yellove times. Display the count in data field.
jmp input
north_south_south_north: #start=stepper_motor.exe#
MOV ax,sit_A name "stepper"
OUT 4,ax #make_bin#
MOV cx,4Ch #start=led_display.exe#
MOV dx,4B40h #make_bin#
MOV ah,86h name "led"
int 15h jmp start
jmp start datcw_fs db 0000_0001b
east_west_west_east: db 0000_0011b
MOV ax,sit_B db 0000_0110b
OUT 4,ax db 0000_0000b
MOV cx,4Ch
MOV dx,4B40h dataccw_fs db 0000_0100b
MOV ah,86h db 0000_0110b
int 15h db 0000_0011b
jmp start db 0000_0000b
all_yellove: msg db "HALT","$"
MOV ax,sit_C flg dw 0
OUT 4,ax start:
MOV cx,4Ch mov dx,0
MOV dx,4B40h mov ax,dx
MOV ah,86h out 199,ax ; clearing the led
mov bx, offset datcw_fs ;stepper motor operation xor dx,dx 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",
l1: cmp flg,02h
to be extracted I as "ELDA" and "HLOER' and find the length of the new strings
mov si, 0 je end if the length of both strings are equal compare the strings and display the
mov cx, 0 jmp l1 result else reverse the original string and print(use INT for string display).
next_step: end:
wait: in al, 7 MOV ah,09h data segment
jz wait int 21h msg1 db 10,13,"Both the new strings have equal length","$"
mov al, [bx][si] ret msg2 db 10,13,"Both the new strings have unequal length","$"
dis: ends
mov cx,bx msg2 db 10, 13, "Enter the operation ('a' for ascending, 'd' for descending, 'e'
for extraction): $"
dec bx
msg3 db 10, 13, "Enter the character to extract: $"
lea si,arr
msg4 db 10, 13, "Result: $"
lea di,rev
str_arr db 'E','X','A','M'
add si,bx
str2 db ?,?,?,?
l:
len db 4 ; String length
mov al,[si]
char db ? ; Character input for operation
mov [di],al
extract db 'A' ; Character to extract
dec si
start:
inc di
lea dx, msg2
dec cx
mov ah, 09h
cmp cx,0
int 21h
jnz l
mov ah, 01h ; Read operation character
lea dx,msg2
int 21h
mov ah,9
mov char, al
int 21h
cmp char, 'a'
lea dx,msg5
je sort_asc
mov ah,9
cmp char, 'd'
int 21h
je sort_desc
end_program: 8) Write an 8086 ALP to interface I/O to read the key press, if the key pressed is array:
'0' implement digital clock for only secs display on the LED in decimal. If key
ret MOV ch,len
pressed is '2' get an array as input and swap the higher order bits with lower
mov ah,4Ch order bits eg. 23,56,89 etc...o/p 32,65,98.... Other than 0 & 2 as input-program lea si,arr1
int 21h should not respond. lp1:
#start=led_display.exe# MOV bl,10d
name "led" MOV bh,0
#make_bin# MOV ah,09h
#start=simple.exe# lea dx,msg1
name "simple" int 21h
#make_bin# inp:
jmp start MOV ah,1
msg db 10,13, "Enter 0-> digital clock 2-> Array swap in I/O port 110$" int 21h
msg1 db 10,13,"Enter number:$" cmp al,13
arr1 db 10 dup(0) jne store
arr2 db 10 dup(0) jmp next_ele
len db 5 store:
start: sub al,30h ; convert ascii to number digit
MOV ah,9 MOV cl,al
lea dx,msg MOV al,bh
int 21h mul bl
in al,110 add al,cl
cmp al,2 MOV bh,al
je array jmp inp
cmp al,0 next_ele:
je clock MOV [si],bh
jmp exit inc si
dec ch lp4: 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
jz swap MOV al,bl
'V', count the number of vowels.
jmp lp1 OUT 199,al
org 100h
swap: inc bl
jmp start:
lea si,arr1 MOV cx,0Ch
msg1 db 10,13,"Enter sentence :$"
lea di,arr2 MOV dx,4B40h ; delay
msg2 db 10,13,"Enter S--> space count V-> Vowel count : $"
MOV cx,5 MOV ah,86h
vow_count db EQU 0
lp3: int 15h
space_count db EQU 0
MOV al,[si] cmp bl,20
start:
MOV bl,10 je exit
MOV ah,09h
MOV ah,0 jmp lp4
lea dx,msg2
div bl exit:
int 21h
MOV bl,ah ;swap digits MOV ah,4ch
MOV ah,1
MOV dl,al int 21h
int 21h
MOV al,10
cmp al,'S'
mul bl
je space_countl
add al,dl
cmp al,'V'
MOV [di],al
je vowel_count
inc si
jmp exit
inc di
space_countl:
loop lp3
MOV ah,09h
jmp exit
lea dx,msg1
clock:
int 21h
MOV al,0
input:
OUT 199,al
MOV ah,1
MOV bl,1
int 21h
cmp al,13 cmp al,'i' 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
je exit jz inc_vow
repeat reading the input until it falls in the required range. When the
cmp al,' ' cmp al,'I' temperature reaches >=80 rotate the stepper in clockwise for 3 times and
je inc_space jz inc_vow display the msg as 'motor started' . Again, if the temperature goes down
jz inc_vow input:
mov al, [bx][si] mov ah,09h 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
out 7, al int 21h
locations. Print the count of matching and mismatching on the LED with a
inc si mov ah,4ch delay.
cmp si, 4 int 21h #start=led_display.exe#
jb next_step1 #make_bin#
mov si, 0 name "led"
inc cx arr1 db 1,2,3,4,5
cmp cx,8 arr2 db 1,2,3,8,5
jz dis1 cnt dw 5
jmp next_step1 mov ax,00h
dis: out 199,ax
inc dl lea si,arr1
mov al,dl lea di,arr2
out 199,ax mov cx,cnt
cmp dh,dl ; same move on to anticlockwise mov bx,0
jz next1 compare:
jmp l1 mov al,[si]
dis1: cmp al,[di]
dec dl jz eq
mov al,dl inc bh ; to store unlike count
out 199,al l1:
cmp dl,0 inc si
jz halt inc di
jmp l2 dec cx
halt: jnz compare
lea dx,str1 jmp dis
eq: 13) Write an Assembly Language Program to interface TraAic liOt system to int 15h
simulate the following rules 1. Enable the signals for the vehicles to move from
inc bl ; to store like count MOV ax,sit_amber
west to east and east to west for 2 secs. Then north to south and south to
jmp l1 north for 2 secs. After 2 secs , all amber should blink. OUT 4,ax
dis: ; to display in LED #start=Traffic_Lights.exe# ;delay using interrupt or use a for loop
mov al,bl name "traffic" MOV cx,4Ch
out 199,al #make_bin# MOV dx,4B40h
mov cx,2Ch jmp start: MOV ah,86h
mov dx,4B40h sit_nor_sou dw 0000_0011_0000_1100b int 15h
mov ah,86h sit_wes_eas dw 0000_1000_0110_0001b MOV ah,4ch
int 15h sit_amber dw 0000_0100_1001_0010b int 21h
mov al,bh all_red dw 0000_0010_0100_1001b
out 199,al start:
hlt MOV ax,all_red
ret 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
14) Write an assembly language program to simulate digital clock such that the MOV cx,0Ch
key press using int , if key pressed is 1. No operation 2. Simulate seconds
MOV dx,4B40h ; delay
display from 59,58,....0 3. Simulate seconds display from 0,1,2,....59 4 - Flash
"00" on the LED interface MOV ah,86h
#make_bin# je exit
desec: exit:
MOV al,bl
OUT 199,al
dec bl