8086 Programs
To find 1s complement of a number.
Programb1.doc
Program to find 2s complement of a number.
Programb2.doc
Program to mask lower nibble.
Programb3.doc
Program to mask upper nibble.
Programb4.doc
Program to pack the two unpacked BCD numbers.
P
Microprocessors & Applications (UPTU)
Explanation :
Consider that a block of data of N bytes is present at source location. Now this block of N
bytes is to be moved from source location to a destination location.
Let the number of bytes N = 10.
We will
Microprocessors & Applications (UPTU)
Explanation :
At first we will accept the string from the user and store it in STR 1. Call procedure
CONVERT, which will do the case conversion. Display the result.
Algorithm :
Step I
Step II
Step III
Step IV
Step V
S
Microprocessors & Applications (UPTU)
Appendix B
Explanation :
The substring is checked in the main string by comparing the first character of substring with
the characters of the main string. If there is a match of first character, then it is required to
Microprocessors & Applications (UPTU)
Appendix B
Explanation :
Accept the string from user using function 09H under INT 21H. Accept this string after
enter is pressed into buffer. Load the string length in CX. Load the length of string also in
DI. Charact
Microprocessors & Applications (UPTU)
Appendix B
Explanation :
Firstly, we will accept the string by user. Load the length of string in CX. The space
between characters is also counted. This string length is in Hex. Convert the Hex to
decimal or BCD, Disp
Microprocessors & Applications (UPTU)
Appendix B
Explanation :
Firstly, we will accept the two strings to be concatenated. Then, we will call procedure
CONCAT which will concatenate the two strings. Display the concatenated strings.
Algorithm :
Step I
: S
Microprocessors & Applications (UPTU)
Explanation :
Appendix B
Using Macro display the Menu for entering string, calculate length, reverse, palindrome
and exit. Accept the choice from user using INT 21H function 01H.
If choice = 1, call procedure for acce
Microprocessors & Applications (UPTU)
Appendix B
Explanation :
We will accept two strings from the user. After accepting the strings, the first step in
string comparison is to check whether their string lengths are equal. If the string lengths
are not equ
Microprocessors & Applications (UPTU)
Appendix B
Explanation :
For BCD-ASCII conversion.
(i)
Mask the lower digit of given BCD number.
(ii) Add 30H to it to convert it to equivalent ASCII number
(iii) Now mask the upper digit of given BCD number.
(iv) Rot
Microprocessors & Applications (UPTU)
Explanation :
For ASCII-BCD conversion.
(i) Subtract the ASCII number by 30 H to get the valid BCD number.
e.g. to convert 35 H i.e. ASCII 5
3
5
-3
0
0
5
Appendix B
05 is the BCD equivalent of 35 H.
Algorithm :
Step
Microprocessors & Applications (UPTU)
Appendix B
Explanation :
For Binary-ASCII conversion.
Multiply the binary number by increasing powers of 2 i.e.20, 21, 22. Starting from
LSB
e.g. to convert 0000 1010 to ASCII
= 0* 20 + 1*21 + 0 * 22 + 1*23 + 0*24 +
Microprocessors & Applications (UPTU)
Appendix B
Explanation :
For ASCII-Gray conversion.
(i) Divide the ASCII number by 2 until the quotient is 0 .
e.g. to convert 0EHi.e. decimal 14
2
2
2
2
2
1
4
7
3
1
0
0
1
1
1
(1110 B) is the binary equivalent of 0E H
Microprocessors & Applications (UPTU)
Appendix B
Explanation :
Consider that a byte of data is present in the AL register and a second byte of data is
present in the BL register. We have to subtract byte in AL with the byte in BL. Using sub
instruction,
Microprocessors & Applications (UPTU)
Explanation :
Assume
Example
AAM
Carry
Appendix B
Consider that a byte of data is present in the AL register and a second byte of data is
present in the BL register. We have to add byte in AL with the byte in BL. Usi
Microprocessors & Applications (UPTU)
Appendix B
Explanation :
Consider that a word of data is present in the AX register in unpacked BCD and byte of
data is present in the BL register, we have to divide word in AX with the byte in BL.
The AAD is before t
Microprocessors & Applications (UPTU)
Appendix B
Explanation :
Consider that a word of data is present in the AX register and word of data is present in
the BX register, we have to divide word in AX with the word in BX.
Using IDIV instruction, divide the
Microprocessors & Applications (UPTU)
Appendix B
Explanation :
Consider that a word of data is present in the AX register and 2nd word of data is present in
the BX register.
We have to multiply the word in AX with the word in BX. Using IMUL instruction,
m
Microprocessors & Applications (UPTU)
Explanation :
Appendix B
The Fibonacci series is
0 1 1 2 3 5 8 13 21.
The first two terms are 0 1, the third term is computed as 0 + 1 = 1, fourth term 1 + 1 =
2, fifth term = 1 + 2 = 3.
i.e. nth term = (n 2)th term +
Microprocessors & Applications (UPTU)
Appendix B
Explanation :
The recursive procedure nCr can be evaluated by different ways. One method to find the
factorial of n, (n r) and r evaluating it by
n
Cr =
In order to reduce the time of execution, we will alt
Microprocessors & Applications (UPTU)
Appendix B
Explanation :
GCD of two numbers is performed by dividing the greater number by the smaller number
till the remainder is zero. If it is zero, the divisor is the GCD if not the remainder and the
divisor of t
Microprocessors & Applications (UPTU)
Appendix B
Explanation :
The LCM of two numbers is found by dividing the first number by the second number. If
there is no remainder, then the first number is the LCM. If there is a remainder, the first
number is adde
Microprocessors & Applications (UPTU)
Explanation :
Appendix B
To compute the factorial of a number means to multiply the number n with
(n 1) (n 2) . 2 1.
e.g. to compute 5 !
5! = 5 4 3 2 1
= 120.
In our program, we will initialize AX = 1 and load the num
Microprocessors & Applications (UPTU)
Explanation :
Appendix B
To compute the factorial of a number, means to multiplay the number say n with (n 1)
(n 2) (n 3) 1.
e.g. To compute 5 ! of a number.
5! =5 4 3 2 1
= 120.
In our program, we will initialize the
Microprocessors & Applications (UPTU)
Appendix B
Explanation :
To find the square of a number we multiply the number with itself. The result is stored in
register AX in the Hex form. Now we have to convert the Hex number to decimal.
Display the result.
Al
Microprocessors & Applications (UPTU)
Explanation :
Appendix B
We have two matrices mat 1 and mat 2. Our task is to subtract these two matrices. As it is
a 3 3 matrix, the number of elements present in it is 9.
We will initialize counter CX with 9 as 9 su
Microprocessors & Applications (UPTU)
Explanation :
Appendix B
We have two matrices mat 1 and mat 2 present. Now our task is to add these two matrices
and display the result. As it is a 3 3 matrix, number of elements present is 9.
We will initialise count
Microprocessors & Applications (UPTU)
Explanation :
Appendix B
We have a number given. Initially, we will count the number of 1s in that number. For
this we will rotate the contents of number bit by bit to right, alongwith carry. If carry = 1
then increme
Microprocessors & Applications (UPTU)
Explanation :
Appendix B
We have an array of 10 numbers. So we initialize the counter with 10. Also we initialize a
pointer to point these numbers.
Compare first number with initial maximum number i.e. zero. If number
Microprocessors & Applications (UPTU)
Appendix B
Explanation :
Initialize the data section. We have a source block and a destination block. The source
block contains N bytes. Let N = 10 for eg. We have to reverse this 10 bytes of data and
transfer them to