Microprocessor Programming Solution
Microprocessor Programming Solution
Microprocessor Programming Solution
Write an ALP in 8085 to transfer 20 bytes of data in a table to another table by interchanging
D1 and D4 bits of each byte. [2075 Baishakh]
LXI H, 9000H
LXI D, 9020H
MVI C, 14H
LOOP: MOV A, M
ANI 00010010B
CPI 00010010B
JZ NOCHANGE
CPI 00000000B
JZ NOCHANGE
MOV A, M
XRI 00010010B
STAX D
JMP SKIP
NOCHANGE: MOV A, M
STAX D
SKIP: INX H
INX D
DCR C
JNZ LOOP
HLT
Write an assembly language program for 8085 to find the square of ten 8-bit numbers which
are less than or equals to 0FH, stored from memory location C090H. Store the result from the
end of the source table. [2073 Magh]
LXI H, C090H
LXI D, C09AH
LOOP: MOV A, M
MOV B,A
MOV C,A
XRA A
DCR C
JNZ MULTIPLY
STAX D
SKIP: INX H
INX D
MOV A, L
CPI 9AH
JNZ LOOP
HLT
Write a program in 8085 to sort the 10 data bytes stored in a table in descending order. The
data bytes are stored in a table from memory address 8920H. [2076 Bhadra]
MVI C, 09H
MVI D, 09H
LOOP1: MOV A, M
INX H
CMP M
JNC OKAY
JZ OKAY
MOV B,M
MOV M, A
DCX H
MOV M, B
INX H
OKAY: DCR D
JNZ LOOP1
DCR C
JNZ LOOP2
HLT
Write a program in 8085 to find the largest and smallest bytes from the list of 20 bytes stored
starting from memory location C050H. Store the largest byte and smallest byte in C070H and
C071H respectively. [2076 Baisakh]
LXI H, C050H
MVI C, 13H
LOOP:INX H
MOV A, D
CMP M ;D-M
JNC SKIP1
MOV D, M
SKIP1: MOV A, E
CMP M ;E-M
JC SKIP2
MOV E, M
SKIP2: DCR C
JNZ LOOP
MOV A, D
STA C070H
MOV A, E
STA C071H
HLT
Write a program in 8085 to count the odd and even parity numbers of 150 data stored in the
memory location starting from C050H. Stores the counts at memory locations D000H and
D001H. [2077 Chaitra]
LXI H, C050H
LOOP: XRA A
ADD M
JPE EVEN
INR D
JMP EXIT
EVEN: INR E
EXIT: INX H
DCR C
JNZ LOOP
MOV A, D
STA D000H
MOV A, E
STA D001H
HLT
There are 40 8-bit numbers in a table with address starting from 9090H. WAP in 8085 to
transfer these numbers to another table with address from A010H if lower nibble of a number
is greater than higher nibble. Otherwise transfer by setting bit D2 and resetting bit D6. [2078
Baishakh]
LXI H, 9090H
LXI D, A010H
LOOP: MOV A, M
ANI 0FH
MOV B, A
MOV A,M
RRC
RRC
RRC
RRC
ANI 0FH
CMP B ;Higher-Lower
JNC SETRESET
MOV A, M
STAX D
JMP EXIT
SETRESET: MOV A, M
ORI 00000100B
ANI 10111111B
STAX D
EXIT: INX H
INX D
DCR C
JNZ LOOP
HLT
There are two tables holding 20 data whose starting address is 9000H and 9020H
respectively. WAP to add the content of first table with the content of second table having
same array index. Store sum and carry into the 3rd and 4th table indexing from 9040H and
9060H respectively. [2074 Bhadra]
LXI D, 9000H
LXI H, 9020H
LXI B, 9040H
START: LDAX D
ADD M
STAX B
JNC SKIP
PUSH H
LXI H, 9060H
MOV A, L
ADD E
MOV L, A
MVI M, 01H
POP H
SKIP:INX H
INX B
INX D
MOV A, E
CPI 14H
JNZ START
HLT
8086
WAP to read a string from the user, convert it to uppercase, count the number of words and
display each word in each line.
.model small
.stack 64
.data
maxchar db 255
actlen db ?
input db 255 dup(?)
.code
newline macro
mov ah, 02h
mov dl, 0ah
int 21h
mov dl, 0dh
int 21h
endm
newline
newline
cmp dl, 32
jne skipnewline
newline
inc bl
jmp skip
newline
newline
main endp
end
Write an ALP in 8086 to read a word and display all the alphabets in alternate case (first
alphabet in lower case, second in upper case, third in lower case and soon ) in a clear
window. [2075 Baisakh]
.model small
.stack 64
.data
maxchar db 255
actlen db ?
input db 255 dup(?)
.code
clr macro
mov ax, 0600h
mov cx, 0000h
mov dx, 1950h
mov bh, 4fh
int 10h
endm
clr
cmp bl, 0
je makelower
sub dl, 32
int 21h
mov bl, 0
jmp skip
main endp
end
Write an assembly program to read a string from the user and display vowels and consonants
separately. [2072 Ashwin]
.model small
.stack 64
.data
maxchar db 255
actlen db ?
input db 255 dup(?)
.code
newline macro
mov ah, 02h
mov dl, 0ah
int 21h
mov dl, 0dh
int 21h
endm
newline
newline
cmp dl, 32
je skip
cmp dl, 'a'
je s_vowel
cmp dl, 'e'
je s_vowel
cmp dl, 'i'
je s_vowel
cmp dl, 'o'
je s_vowel
cmp dl, 'u'
je s_vowel
mov [bx], dl
inc bx
jmp skip
skip: inc si
loop again
newline
newline
Write a program to read a string and display only the alphabetic characters from the string in
a clear screen. [2071 Magh]
.model small
.stack 64
.data
maxchar db 255
actlen db ?
input db 255 dup('$')
.code
main proc far
mov ax, @data
mov ds, ax
;input string
mov ah, 0ah
lea dx, maxchar
int 21h
;clear screen
mov ax, 0003h
int 10h
jl skip
Write a program to find the largest and smallest numbers of an array having 10 numbers.
Display the found numbers in the cleared screen. [2073 Bhadra]
.model small
.stack
.data
arr db 12, 15, 10, 18, 24, 08, 19, 20, 11, 14
max db ?
min db ?
.code
main proc far
mov ax, @data
mov ds, ax
mov max, al
mov min, al
inc si
mov ah,0
mov al, max
call print_num
mov ah,0
mov al, min
call print_num
print_num proc
mov cx,0
mov dx,0
label1: cmp ax,0
je print1
mov bx,10
div bx ;extract the last digit
push dx ;push it in the stack
inc cx ;increment the count
xor dx,dx ;set dx to 0
jmp label1
print1: cmp cx,0 ;check count
je exit
pop dx ;pop the top of stack
add dx,48 ;for ascii
mov ah,02h
int 21h
dec cx
jmp print1
exit: ret
end
.model small
.stack 64
.data
.code
mov ds, ax
int 21h
int 21h
mov ah, 00
mov bh, 00
mul bl
call print_num
int 21h
main endp
.model small
.stack 64
.data
maxchar db 255
actlen db ?
.code
newline macro
int 21h
int 21h
endm
mov ds, ax
;input string
int 21h
mov ch,0
jl skip
jg skip
jg check_lower
skip: inc si
loop again
newline
int 21h
newline
int 21h
int 21h
main endp
end
.model small
.stack 64
.data
maxchar db 255
actlen db ?
.code
newline macro
int 21h
int 21h
endm
mov ds, ax
;input string
int 21h
mov ch,0
newline
cmp dl, 32
jne skip_first_flag
jne print_lower
cmp dl, 91
jl print
jmp print
jg print
inc si
loop again
int 21h
main endp
end
.model small
.stack 64
.data
num dw ?
counter dw ?
sum dw ?
.code
;clear screen
mov ax, 0003h
int 10h
again: mov ax, num ;since 'add sum, num' is illigal so we need a register
for add operation.
add sum, ax
newline
main endp
end
.model small
.stack
.data
.code
mov ds, ax
mov ax, 0
mov bx,02
inc bx
inc bx
loop again
call print_num
int 21h
main endp
End
Write a program to find the largest and smallest numbers of an array having 10 numbers.
Display the found numbers in the cleared screen. [2073 Bhadra]
.model small
.stack
.data
arr db 12, 15, 10, 18, 24, 08, 19, 20, 11, 14
max db ?
min db ?
.code
main proc far
mov ax, @data
mov ds, ax
lea si, arr
mov cx, 9
mov al, arr[si]
mov max, al
mov min, al
inc si
mov ah,0
mov ah,0
.code
main proc far
mov ax, @data
mov ds, ax
.model small
.stack
.data
maxchar db 255
nchars db ?
.code
main proc
mov ds, ax
int 21h
newline_m
;clear screen
int 10h
int 21h
inc si
loop again
newline_m
int 21h
int 21h
main endp
end
TITLE 2072 Magh (Approx Solution, See class note for full solution)
.model small
.stack
.data
maxchar db 255
nchars db ?
actstr db 255 dup(?)
row db 10 ;approx center for row.
.code
center macro
inc row
mov ah, 02h
mov bh, 00
mov dh, row
mov dl, 40
int 10h
center endm
main proc
mov ax, @data
mov ds, ax
mov bl, 01h
mov ah, 0ah
mov dx, offset maxchar
int 21h
center
lea si, actstr
mov ch, 00h
mov cl, nchars
.code
main proc far
mov ax, @data
mov ds, ax
;counter
mov cx, 10
.model small
.stack 64
.data
maxchar db 255
actlen db ?
input db 255 dup(?)
.code
;pointer define
lea si, input
lea di, final_string
newline
skip: inc si
inc di
loop again
newline
;count number of uppercase letter (assumed number is less than 9 else you
have to use 'num_print' subroutine)
main endp
end
.stack 64
.data
vow_c db ?
con_c db ?
num_c db ?
oth_c db ?
maxchar db 255
actlen db ?
input db 255 dup(?)
.code
newline macro
mov ah, 02h
mov dl, 0ah
int 21h
mov dl, 0dh
int 21h
endm
;string read
mov ah, 0ah
lea dx, maxchar
int 21h
;pointer define
lea si, input
;counter define
newline
;vowel check
okay: cmp dl, 'a'
je c_vowel
cmp dl, 'e'
je c_vowel
cmp dl, 'i'
je c_vowel
cmp dl, 'o'
je c_vowel
cmp dl, 'u'
je c_vowel
cmp dl, 'A'
je c_vowel
cmp dl, 'E'
je c_vowel
cmp dl, 'I'
Prepared By: Baikuntha Acharya (Lecturer, DHoD, Sagarmatha Engineering College)
[email protected]
IOE – 8085 8086 Microprocessor Old Question Solution
je c_vowel
cmp dl, 'O'
je c_vowel
cmp dl, 'U'
je c_vowel
inc con_c ;increment consonant count if non of the above condition matched
i.e this character must be consonant
jmp skip
c_vowel: inc vow_c ;increment vowel count if any of the condition matched
above and jumped here
jmp skip
;numerals check
other_characters: cmp dl, '0'
jb skip_numeral_count
cmp dl, '9'
ja skip_numeral_count
inc num_c
jmp skip
skip: inc si
loop again
int 21h
main endp
end