0% found this document useful (0 votes)
2 views

Mml Lab Code_bit9

The document outlines several 8086 assembly language programs, including one for adding an array of 16-bit numbers and displaying the result as ASCII, generating a Fibonacci series based on user input, and implementing a digital calculator. It also describes a traffic light control system based on key inputs, a stepper motor interface, and string manipulation tasks to extract even and odd positioned characters. Each program includes specific operations and conditions to be executed, demonstrating various functionalities of assembly programming.

Uploaded by

mohith.r0101
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Mml Lab Code_bit9

The document outlines several 8086 assembly language programs, including one for adding an array of 16-bit numbers and displaying the result as ASCII, generating a Fibonacci series based on user input, and implementing a digital calculator. It also describes a traffic light control system based on key inputs, a stepper motor interface, and string manipulation tasks to extract even and odd positioned characters. Each program includes specific operations and conditions to be executed, demonstrating various functionalities of assembly programming.

Uploaded by

mohith.r0101
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

add al,cl 2) Write a 8086 AIP to add an array of 16 bit numbers and store the result as

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

test al, 10000000b lea dx,msg msg db "Enter a string:","$"

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","$"

out 7, al hlt msg3 db 10,13,"Comparison: Both are equal","$"

inc si msg4 db 10,13,"Comparison: Both are unequal","$"

cmp si, 4 msg5 db 10,13,"Reversed string is:","$"

jb next_step msg6 db 10,13,"Odd index string:","$"

mov si, 0 msg7 db 10,13,"Even index string:","$"

inc cx ; 4 si = 1 cx arr db 15 dup('$')

cmp cx, 08 ; cx=8 corresponds to one complete rotation arr1 db 15 dup('$')

je dis arr2 db 15 dup('$')

jne next_step rev db 15 dup('$')

dis: ends

inc dx code segment

MOV ax,dx start:

out 199,ax mov ax, data

cmp dx,0Ah ;10 rotations per direction yall mov ds, ax

jne l1 mov es,ax

MOV bx,offset dataccw_fs lea dx,msg

inc flg mov ah,9

int 21h jz dis jmp l4


lea si,arr mov al,[si] l5:
l1: mov [di],al cmp [di],'$'
mov ah,1 add si,2 jz compare
int 21h inc di inc di
cmp al,13 jmp l3 inc dx
jz odd dis: jmp l5
mov [si],al mov ah,9 compare:
inc si lea dx,msg6 cmp bx,dx
jmp l1 int 21h jz eq
odd: lea dx,arr1 jmp uneq
lea si,arr int 21h eq:
lea di,arr1 lea dx,msg7 lea dx,msg1
l2: int 21h mov ah,9
cmp [si],'$' lea dx,arr2 int 21h
jz even int 21h cld
mov al,[si] count: lea si,arr1
mov [di],al mov bx,0 lea di,arr2
add si,2 mov dx,0 mov cx,bx
inc di lea si,arr1 repe cmpsb
jmp l2 lea di,arr2 jnz note
even: l4: lea dx,msg3
lea si,arr+1 cmp [si],'$' mov ah,9
lea di,arr2 jz l5 int 21h
l3: inc si jmp exit
cmp [si],'$' inc bx
note: 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',
lea dx,msg4 lea dx,rev
sort the string in ascending order (i/p - EXAM, o/p - AEMX), if the character is
mov ah,9 mov ah,9 'd', sort the string in descending order (i/p - EXAM, XMEA) and if the character
int 21h int 21h is 'e', extract a character and then print the string (CH = 'A', o/p - EXM).

jmp exit exit:


uneq: ends org 100h

add bx,dx end start jmp start

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

cmp char, 'e'


je extract_char outerd: l2:
jmp end_program ; Exit for invalid input lea si,str_arr MOV al,[si]
sort_asc: mov dl,len MOV [di],al
mov cl,len dec dl dec si
outer: innerd: inc di
lea si,str_arr mov al, [si] dec cx
mov dl,len mov ah, [si + 1] jnz l2
dec dl cmp al, ah jmp end_program
inner: jbe no_swapd ; Skip if in order extract_char:
mov al, [si] xchg al, ah ; Swap characters lea si,str_arr
mov ah, [si + 1] mov [si], al lea di,str2
cmp al, ah mov [si + 1], ah MOV cx,4
jbe no_swap ; Skip if in order no_swapd: ex1:
xchg al, ah ; Swap characters inc si MOV al,[si]
mov [si], al dec dl cmp al,extract
mov [si + 1], ah jnz innerd je skip
no_swap: dec cl MOV [di],al
inc si jnz outerd inc si
dec dl rev: inc di
jnz inner lea si,str_arr loop ex1
dec cl lea di,str2 jmp end_program
jnz outer MOV cx,4 skip:
jmp end_program dec cx inc si
sort_desc: add si,cx jmp ex1
mov cl, len MOV cx,4 ; reverse for desending yall

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

jmp input cmp al,'o' #start=stepper_motor.exe#

inc_space: jz inc_vow name "stepper"

inc space_count cmp al,'O' #make_bin#

jmp input jz inc_vow #start=thermometer.exe#

vowel_count: cmp al,'u' name "thermo"

MOV ah,09h jz inc_vow #make_bin#

lea dx,msg1 cmp al,'U' jmp start:

int 21h jz inc_vow motorcw_fs db 0000_0001b

input2: jmp input2 db 0000_0011b

MOV ah,1 inc_vow: db 0000_0110b

int 21h inc vow_count db 0000_0000b

cmp al,13 jmp input2 motorccw_fs db 0000_0100b

je exit exit: db 0000_0110b

cmp al,'a' MOV ah,4ch db 0000_0011b

jz inc_vow int 21h db 0000_0000b

cmp al,'A' msg db 10,13, "Error$"

jz inc_vow msgg db 10,13, "OK!$"

cmp al,'e' msg1 db 10,13 ,"Motor rotating clockwise...$"

jz inc_vow msg2 db 10,13 ,"Motor rotating counter clockwise...$"

cmp al,'E' start:

jz inc_vow input:

MOV cx ,150 in al,7 test al,10000000b


wait3: test al,10000000b jz wait2
NOP jz wait1 MOV al,[bx][si]
dec cx MOV al,[bx][si] out 7,al
jnz wait3 out 7,al inc si
in al,125 ; get thermometer value inc si cmp si,4
cmp al,40 cmp si,4 jne rot2
jl low jne rot MOV si,0
cmp al,80 MOV si,0 inc dx
jg high inc dx cmp dx,24
lea dx,msgg cmp dx,24 ; 8 x 3 ( 3 rotations ) jne rot2
MOV ah,09h jne rot jmp input
int 21h jmp input
jmp input high:
low: lea dx,msg
lea dx,msg MOV ah,09h
MOV ah,09h int 21h
int 21h lea dx,msg1
lea dx,msg2 MOV ah,09h
MOV ah,09h int 21h
int 21h MOV bx,offset motorcw_fs
MOV bx,offset motorccw_fs MOV si,0
MOV dx,0 MOV dx,0
MOV si,0 rot2:
rot: wait2:
wait1: in al,7
11) Write an assembly language program using 8086 to interface stepper motor lea dx,msg1
and perform the following operations. Get the number of rotations as user
mov ah,09h next_step:
input, for every rotation count should be displayed on the LED, when the count
reaches desired input, rotate the motor towards anticlockwise direction and int 21h wait: in al, 7
decrement the count for every complete rotation stop the motor when count mov dh,0 test al, 10000000b
reaches 0
mov dl,10d jz wait
#start=stepper_motor.exe#
input: mov al, [bx][si]
name "stepper"
mov ah,1 out 7, al
#make_bin#
int 21h inc si
#start=led_display.exe#
cmp al,13 cmp si, 4
#make_bin#
jne number jb next_step
name "led"
mov dl,0 mov si, 0
jmp start
mov ah,0 inc cx
msg1 db 10,13,'Enter the number of rotations:$'
jmp next cmp cx,8
str1 db 10,13,'HALT$'
number: jz dis
datcw_fs db 0000_0001b
sub al,30h jmp next_step
db 0000_0011b
mov cl,al next1:
db 0000_0110b
mov al,dh mov bx,offset datccw_fs
db 0000_0000b
mul dl l2:
datccw_fs db 0000_0100b
add al,cl mov si,0
db 0000_0110b
mov dh,al mov cx,0
db 0000_0011b
jmp input next_step1:
db 0000_0000b
next: wait1: in al, 7
start:
mov bx, offset datcw_fs test al, 10000000b
mov ax,0
l1: jz wait1
out 199,ax
mov si, 0
mov dx,0
mov cx, 0

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

#start=led_display.exe# int 15h

name "led" cmp bl,0

#make_bin# je exit

jmp start jmp lo1

msg db "Enter a number:","$" asec:

start: MOV bl,0

MOV ah,9 lo2:

lea dx,msg MOV al,bl

int 21h OUT 199,al

MOV ah,01h inc bl

int 21h MOV cx,0Ch

cmp al,'1' MOV dx,4B40h ; delay

je exit MOV ah,86h

cmp al,'2' int 15h

je desec cmp bl,59

cmp al,'3' je exit

je asec jmp lo2

desec: exit:

MOV bl,59 MOV ah,4ch

lo1: int 21h

MOV al,bl
OUT 199,al
dec bl

You might also like