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

Interfacing Solved Problems

The document provides assembly language programs for 8086 microprocessors to calculate the sum, largest, and smallest values from an array of numbers, prompt a user to enter two hexadecimal numbers and print their sum, and print a pattern of stars based on a number of rows entered by the user. It includes code segments and descriptions for each programming problem and uses concepts like loops, arrays, input/output, and number conversion between decimal and hexadecimal.

Uploaded by

Yemane Yona
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
110 views

Interfacing Solved Problems

The document provides assembly language programs for 8086 microprocessors to calculate the sum, largest, and smallest values from an array of numbers, prompt a user to enter two hexadecimal numbers and print their sum, and print a pattern of stars based on a number of rows entered by the user. It includes code segments and descriptions for each programming problem and uses concepts like loops, arrays, input/output, and number conversion between decimal and hexadecimal.

Uploaded by

Yemane Yona
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

MICROCOMPUTER AND

INTERFACING SOLVED
PROBLEMS
Final part

For all 4th year electrical and computer engineering streams except power stream.
1) Write an assembly programming for 8086 microprocessor to find the sum, largest, and
smallest number from a given arrays.
Arrays: 08h,92h,32h,16h,00h,78h,90h,02h,0ffh,78h,02h
Sum: 0363h
Largest: 0ffh
Smallest: 00h
largest1: mov al,arr1[si]
.model small
.stack cmp al,largest
.data
jb no_change
count db 10
arr1 db mov largest,al

08h,92h,32h,16h,00h,78h,90h,02h,0ffh,78h,02h no_change: inc si


largest db ?
loop largest1
sum dw 0
smallest db ? mov cl,count
.code
mov si,00h
main proc
mov ax, @data mov al,arr1[si]

mov ds,ax mov smallest,al


mov cl,count
smallest1: mov al,arr1[si]
mov ch,00h
mov si,00h cmp al,smallest
mov ax,00h
ja no_change1
sum1: mov al,arr1[si]
mov smallest,al
add sum,ax
inc si no_change1: inc si

loop sum1 loop smallest1


mov cl,count
mov ax,4c00h
mov si,00h
int 21h
mov al,arr1[si]
main endp
mov largest,al
end main
2) Write a. program that prompts the user to enter two unsigned hex numbers, 00to FFh, and
prints their sum in hex on the next line. If the user enters an illegal character, he or she
should be prompted to begin again.

mov ah,09h
.model small
mov dx,offset newlin
.stack
int 21h
.data
mov dx,offset msg2
msg1 db "ENTER THE FIRST NUMBER IN HEX(00-FF): ",'$'
int 21h
msg2 db "ENTER THE SECOND NUMBER IN HEX(00-FF): ",'$'
call accept_input
msg3 db "THE SUM OF TWO HEX NUMBER IS: ",'$'
mov num2,al
newlin db 13, 10, "$"
add al,num1
dig1 db ? ; TO ACCEPT THE FIRST DIGIT FROM USER
mov sum,al
dig2 db ? ; TO ACCEPT THE SECOND DIGIT FROM USER
mov ah,09h
num db ? ; TO STORE THE COMBIND VALUE OF DIGITES
mov dx,offset newlin
num1 db ? ; THE FIRST NUMBER IN HEX
int 21h
num2 db ? ; THE SECOND NUMBER IN HEX
mov ah,09h
sum dB ? ; THE SUM OF THE FIRST AND THE SECOND
NUMBERS mov dx,offset msg3

asc db ? ; use to store the changed num to ascii letter (A-F) int 21h
representation
mov ax,word ptr sum
let db ? ; use to store letter representation to hex num
mov cx,00h
.code
mov bl,10h
main proc
split: div bl
mov ax,@data
mov dx,00h
mov ds,ax
mov dl,ah
mov ah,9h
push dx
mov dx,offset msg1
inc cl
int 21h
mov ah,00h
call accept_input
cmp al,00h
mov num1,al
ja split
print: pop dx mov bl,10h ret

mov ah,dl mul bl print_hexa endp

cmp dl,09 mov dig1,al change_letter proc

jg call1 add al,dig2 A: cmp al,11h

mov al,dl mov num,al jg B

add al,30h ret mov al,0AH

jmp print1 accept_input endp jmp end2

call1: call print_hexa print_hexa proc B: cmp al,12h

print1: mov ah,02h aa: cmp ah,0ah jg C

mov dl,al jg bb mov al,0BH

int 21h mov al,'A' jmp end2

loop print jmp end1 C: cmp al,13h

mov ax,4c00h bb: cmp ah,0bh jg D

int 21h jg cc mov al,0CH

main endp mov al,'B' jmp end2

accept_input proc jmp end1 D: cmp al,14h

mov ah,01 cc: cmp ah,0ch jg E

int 21h jg dd mov al,0DH

sub al,30h mov al,'C' jmp end2

cmp al,11h jmp end1 E: cmp al,15h

jb les_va1 dd: cmp ah,0dh jg F

call change_letter jg ee mov al,0EH

les_va1: mov dig1,al mov al,'D' jmp end2

mov ah,1 jmp end1 F: mov al,0FH

int 21h ee: cmp ah,0eh end2:mov let,al

sub al,30h jg ff ret

cmp al,11h mov al,'E' change_letter endp

jb les_va2 jmp end1 end main

call change_letter ff: mov al,'F'

les_va2: mov dig2,al end1:mov asc,al

mov al,dig1
3) Write an ALP program to print the below pattern by asking the user number of rows:

for_1: mov al,i

inc al mov ax,4c00h

mov j,al int 21h

for_2: cmp cl,j main endp

.model small jb end_for2 end main

.stack mov ah,02h

.data mov dl,spc

msg db "ENTER THE NUMBER OF ROW(1-9):",'$' int 21h

astr db '*' inc j

spc db ' ' jmp for_2

newli db 13,10,'$' end_for2: mov ax,00

i db 0 mov al,i

j db 0 mov bl,2

k db 0 mul bl

num_as db 0 ;to store number of * in single row mov num_as,al

.code mov k,00

main proc for_3: cmp al,k

mov ax,@data jb end_for3

mov ds,ax mov ah,02h

mov ah,09h mov dl,astr

mov dx,offset msg int 21h

int 21h inc k

mov ah,1 mov al,num_as

int 21h jmp for_3

sub al,30h end_for3: MOV AH,09

mov cl,al MOV DX,OFFSET newli

mov al,00h INT 21H

mov ah,09h inc i

mov dx,offset newl cmp i,cl

int 21h jb for_1


4) Assembly program for to find a factorial for a given numbers(1-6):
Enter number: 07
Fact Value=2D0
model small fact: mul cx print_hexa proc
.stack loop fact aa: cmp ah,0ah
.data mov bl,10h jg bb
msg1 db "Enter split: div bl mov al,'A'
Number(1-6):",'$'
mov dx,00h jmp end1
msg2 db "Fact
mov dl,ah bb: cmp ah,0bh
value:",'$'
push dx jg cc
newli db 13,10,'$'
inc cl mov al,'B'
asc db ?
mov ah,00h jmp end1
.code
cmp al,00h cc: cmp ah,0ch
main proc
ja split jg dd
mov ax,@data
print: pop dx mov al,'C'
mov ds,ax
mov ah,dl jmp end1
mov ah,9h
cmp dl,09 dd: cmp ah,0dh
mov dx,offset msg1
jg call1 jg ee
int 21h
mov al,dl mov al,'D'
mov ah,01
add al,30h jmp end1
int 21h
jmp print1 ee: cmp ah,0eh
mov cx,00h
call1: call print_hexa jg ff
sub al,30h
print1: mov ah,02h mov al,'E'
mov cl,al
mov dl,al jmp end1
mov ah,9h
int 21h ff: mov al,'F'
mov dx,offset newli
loop print end1:mov asc,al
int 21h
mov ax,4c00h ret
mov ah,9h
int 21h print_hexa endp
mov dx,offset msg2
main endp end main
int 21h
5) Write a program that lets the user types some text, consisting of words separated by
blanks, ending with a carriage return, and displays the text in the same word order as
entered, but with the letters ·in each word reversed.

Enter any string: computer interfacing and programming


Output: retupmoc gnicafretni dna gnimmargorp
.model small mov dx,0ah reverse: xchg bx, sp ;
swap bx and sp
.stack 100h mov ah,2
pop dx ; pop
.data int 21h a value from stack into dx
msg1 db 'Enter String:$' mov bx,50h xchg bx, sp ;
msg2 db 'Reverse String:$' xchg bx,sp ;swap sp swap bx and sp
pointer cmp dl, 20h
count DW 0
push 0020h jne skip
main proc
xchg bx,sp mov ah, 2
mov ax,@data ;initialize data
segment inc count loop2: pop dx ;
mov ds,ax loop1: pop and show output

lea dx,msg1 pop dx ;swap bx int 21h


and sp dec count
mov ah,9
xchg bx,sp jnz loop2
int 21h
push dx ; mov dx, 0020h
xor cx,cx
push to new stack
mov ah,1 skip: push dx
xchg bx,sp
int 21h inc count
inc count
input: cmp al,0dh loop reverse
loop loop1
je end_input mov ah, 4ch
lea dx, msg2
push ax int 21h
mov ah,9
inc cx main endp
int 21h
int 21h end main
mov cx,count
jmp input
mov count,0
end_input: mov dx,0dh ;carriage and new line
push 0020h ; push
mov ah,2 0020H onto the STACK

int 21h inc count


6) Postfix and prefix using assembly program:
Example: X=a++ and Y=++b
.model small inc al
.stack ret
.data pre_inc endp
a db 1 pos_dec proc
b db 2 mov bl,al
x db ? dec bl
y db ? ret
.code pos_dec endp
main proc pre_dec proc
mov ax,@data mov bl,al
mov ds,ax dec bl
mov al,a dec al
call pos_inc ret
mov x,bl pre_dec endp
mov a,al end main
mov al,b

call pre_inc

mov y,bl

mov b,al

mov ax,4c00h

int 21h

main endp

pos_inc proc

mov bl,al

inc bl

ret
7) Interface an 8255 with 8086 at 00H as an I/O address of Port A. Interface 7 segment
displays with the 8255. Write an ALP to display 0-9 over the 7 segment displays (cathode
type) continuously as per their positions starting with 0 at the least significant position.

.MODEL SMALL

.STACK

.DATA LOOP1: MOV AL,SEG1[SI]


X DB 10 OUT DX,AL
SEG1 DB CALL DELAY
3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH
INC SI
.CODE
LOOP LOOP1
MAIN PROC FAR
JMP AGAIN
MOV AX, @DATA
MAIN ENDP
MOV DS,AX
DELAY PROC NEAR
MOV DX,06H
MOV BX,0FF00H
MOV AL,8BH
LOOP2: DEC BX
OUT DX,AL
NOP
MOV DX,00H
JNZ LOOP2
AGAIN:
RET
MOV SI,00H
ENDP DELAY
MOV CX,10
END MAIN
8) An 8086 microprocessor has 10 MHz clock rate. Write an assembly language program that
will generate a 246ms square wave of 50% duty cycle on port A of 8255. And Draw full
hardware connection and show the generated signal wave.

.MODEL SMALL MOV AL,01H not al


.STACK AGAIN: OUT DX,AL ret
.DATA call delay1 delay1 endp
counter1 dw 0ffh JMP AGAIN END MAIN
counter2 dw 0f2h MAIN ENDP

.CODE delay1 proc


instruction Clock
MAIN PROC FAR mov cx,counter1 cycle
Mov 4
MOV AX, @DATA loop1: nop nop 3
MOV DS,AX nop dec 3
not 3
MOV DX,06H mov bx,counter2 loop 17
jnz 16
MOV AL,8BH loop2: dec bx
ret 8
OUT DX,AL jnz loop2 Call 16

MOV DX,00H loop loop1


9) Write the instruction to generate a 100 KHz square-wave at OUT0 and a 200 KHz
continuous pulse at OUT1 of 8254. Consider a clock of 8 MHz at clk0 and clk1. Again
address pins A0 and A1 of 8254 are directly connected to A0 and A1 of 8086 and A15 of
8086 is connected to 𝐶𝑆 of 8254 through an inverter.

Solution:

To generate 100 KHz square wave at OUT0, No. of count: X×100 KHz = 8 MHz;
≫X=80=50H

Control Word:

To generate 200 KHz continuous pulse at OUT1, No. of count, X ×200 𝐾𝐻𝑧 = 8𝑀𝐻𝑧; ≫ X =
40 = 28𝐻

Control Word:

Address: As address pins A0 and A1 of 8254 are directly connected to A0 and A1 of 8086 and
̅̅̅̅ of 8254 through an inverter. So,
A15 of 8086 is connected to 𝐶𝑆 Subroutine:

CNT0 EQU 8000 H


Address of Counter 0 = 8000H
CNT1 EQU 8001H
Address of Counter 1= 8001H
CNTR EQU 8003H

Address of counter 2=8002H MOV AL, 16H

OUT CNTR, AL
Address of Control Register = 8003H
MOV AL, 50H

OUT CNT0, AL

MOV AL, 54H

OUT CNTR, AL

MOV AL, 28H

OUT CNT1, A

You might also like