Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

1|Page

Course: Microcomputers & Interfacing


Target Group: 4th year Communication Engineering (Section 02) & Control Engineering

Further Examples

Prepared by: Tigabu Yaya January: 2020


2|Page

1. Write an 8086 assembly language program to reverse a string.


ORG 100H
.DATA
SRC DB 'MICROPROCESSOR'
COUNT EQU ($-SRC)
DEST DB COUNT DUP (0)
.CODE
START: MOV AX, @DATA
MOV DS, AX
MOV CX, COUNT
LEA SI, SRC
LEA DI, DEST
DEC CX
DEC CX
ADD SI, CX
BACK: MOV AL, [SI]
MOV [DI], AL
DEC SI
INC DI
DEC CX
JNZ BACK
HLT
END START

Prepared by: Tigabu Yaya January: 2020


3|Page

2. Write a program to find the number of elements in the array which are having ‘1’ in their
5th bit position.
Solution: we can use TEST or AND instruction
.MODEL SMALL
.DATA
ARRAY DB 12H, 21H, 34H, 43H, 56H, 89H, 99H, 63H
COUNT DB $-ARRAY ; the number of elements in the ARRAY
.CODE
START: MOV AX, @DATA
MOV DS, AX
MOV CX, COUNT; NUMBER OF ELEMENTS (BYTES) IN THE LIST
LEA SI, ARRAY; SI stores offset address of the first element of in the ARRAY
MOV BL, 00; to store the number of elements having 1 in their 5th position
BACK: MOV AL, [SI]
TEST AL, 00010000B; AND AL, 10H or TEST AL, 10H; testing 5th position.
JNZ NEXT
INC BL
NEXT: INC SI
LOOP BACK
HLT
END START
Before the program is executed, look the value of BL register.

Prepared by: Tigabu Yaya January: 2020


4|Page

After the program is get executed, look the value of BL register.

3. Write 8086 ALP to find out the numbers of negative and positive numbers from a given
series of signed 8-bit numbers. Again divide the list into positive and negative lists

Prepared by: Tigabu Yaya January: 2020


5|Page

Prepared by: Tigabu Yaya January: 2020


6|Page

NB: in the above program, line 18 and line 19 can be replaced with the following
respective lines below.
18. RCL AL, 01
19. JNC Positive

Before Execution After Execution

Prepared by: Tigabu Yaya January: 2020


7|Page

4. Write 8086 ALP to find out the numbers of even and odd numbers from a given series of
unsigned 8-bit numbers. Again divide the list into odd and even lists
Solution: A number is said to be odd if the right most bit is 0 else it’s even

In the above program, the lines 18 & 19 replaced with their respective lines:
18. RCR AL, 01h
19. JNC EVEN

5. Write a program to calculate factorial of a given number using Macro.

Prepared by: Tigabu Yaya January: 2020


8|Page

Take a number: 05H

6. Write a Program to find the largest and smallest number from an array of n 8-bit numbers
The Given Array: 18H, 22H, 15H, 36H, 46H, 63H

Prepared by: Tigabu Yaya January: 2020


9|Page

7. 8086 ASSEMBLY PROGRAM TO SORT NUMBERS IN ASCENDING ORDER

Before Execution After Execution

NB: Repeat the above program in descending order

Prepared by: Tigabu Yaya January: 2020

You might also like