In this post you will see all the Microprocessor 8086 Lab programs with explanation.
1. Program for addition of two 8 bit unsigned numbers.
DATA SEGMENT
N1 DB 07H
N2 DB 08H
Result DB ?
CARRY DB ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV DX,DATA
MOV DS,DX
MOV AL,N1
MOV BL,N2
ADD AL,BL
MOV Result ,AL
JNC EXIT
MOV CARRY,01
EXIT:
MOV AH, 4CH
INT 21H
CODE ENDS
END START
Explanation :
1. In this program above we have taken two variables N1 and N2 and assigned unsigned (positive) values 7 and 8 respectively.
2. We took Result variable to store the answer and the carry variable to store carry if generated.
3. All this variables are declared in data segment.
4. In code segment we assumed CS as CODE and DS as DATA where ASSUME is a directive which is used to give logical names.
5. Using START keyword we started the program and the lines below are used to initialize data segment MOV DX,DATA
MOV DS,DX
6. After that we move the value of N1 i.e. 7 in AL register using MOV instruction.
7. Similarly we mov the value of N2 in BL register
8. Now we used the instruction ADD AL,BL so that both will get added and answer will be stored in AL register.
9. After that we moved addition in the Result variable using instruction MOV Result,AL
10. Then we used JNC instruction it checks for any carry generated, if carry is not generated then it will jump on EXIT lable otherwise it will go to execute instruction below it
i.e. MOV CARRY,01 .
11. After that MOV AH,4CH
INT 21H
used to terminate the program
12. And then CODE ENDS to ends code segment and END START to ends start.
2 . Program for addition of two 16 bit unsigned numbers
DATA SEGMENT
N1 DW 0007H
N2 DW 0008H
Result DW ?
CARRY DB ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV DX,DATA
MOV DS,DX
MOV AX,N1
MOV BX,N2
ADD AX,BX
MOV Result ,AX
JNC EXIT
MOV CARRY,01
EXIT:
MOV AH, 4CH
INT 21H
CODE ENDS
END START
Explanation :
1. The same thing we have done for this program as the first program.
2. Only the difference is we took 16- bit numbers so that to store them we used the register AX,BX and added them.
3. And stored the result in the Result variable and the carry in the Carry variable if generated.
4. At last for all program termination code and the end of code segment and end of START.
3. Program for subtraction of two 8 bit unsigned numbers.
DATA SEGMENT
N1 DB 07H
N2 DB 08H
Result DB ?
CARRY DB ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV DX,DATA
MOV DS,DX
MOV AL,N1
MOV BL,N2
SUB AL,BL
MOV Result ,AL
JNC EXIT
MOV CARRY,01
EXIT:
MOV AH, 4CH
INT 21H
CODE ENDS
END START
Explanation :
1. In this program we have declared two variables N1 and N2 having 8-bit values 07 and 08 respectively.
2. Also Result and Carry variables to store result and carry respectively.
3. After initializing data segment we moved value of N1 to AL and value of N2 to BL and using SUB AL,BL instruction we subtracted 08 from 07 and answer will be stored in AL , we moved that answer in result variable and stored carry if generated.
4. Then termination of program and then end of code segment and end of start.
4. Program for subtraction of two 16 bit unsigned
numbers
DATA SEGMENT
N1 DW 0007H
N2 DW 0008H
Result DW ?
CARRY DB ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV DX,DATA
MOV DS,DX
MOV AX,N1
MOV BX,N2
SUB AX,BX
MOV Result ,AX
JNC EXIT
MOV CARRY,01
EXIT:
MOV AH, 4CH
INT 21H
CODE ENDS
END START
Explanation:
1. The program is for subtraction of two 16-bit numbers.
2. Only we took 16- bit numbers so that to store them we used the register AX,BX and subtracted them.
3. And stored the result (subtraction) in the Result variable and the carry in the Carry variable if generated.
4. At last for all program termination code and the end of code segment and end of START.
5. Program for addition of two BCD numbers.
DATA SEGMENT
N1 DB 07H
N2 DB 08H
Result DB ?
CARRY DB ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV DX,DATA
MOV DS,DX
MOV AL,N1
MOV BL,N2
ADD AL,BL
DAA
MOV Result ,AL
JNC EXIT
MOV CARRY,01
EXIT:
MOV AH, 4CH
INT 21H
CODE ENDS
END START
Explanation:
1. The above program is same as the addition of two 8-bit numbers
2. Only the difference is we have used DAA instruction after addition instruction.
3. And all the other format is same.
6. Program for SUBTRACTION of two 16 BCD numbers.
DATA SEGMENT
N1 DB 07H
N2 DB 08H
Result DB ?
CARRY DB ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV DX,DATA
MOV DS,DX
MOV AL,N1
MOV BL,N2
SUB AL,BL
DAS
MOV Result ,AL
JNC EXIT
MOV CARRY,01
EXIT:
MOV AH, 4CH
INT 21H
CODE ENDS
END START
Explanation :
1. This program is also same as like the subtraction of two 8- bit numbers .
2. The only difference is here DAS (Decimal arrangement after sutraction ) instruction to adjust decimal after subtraction i.e. to convert the ans into its BCD number.
7. Program for division of two unsigned numbers.
DATA SEGMENT
NUMBER1 DW 0009H
NUMBER2 DB 02H
QUOTIENT DB ?
REMAINDER DB ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV DX,DATA
MOV DS,DX
MOV AX,NUMBER1
MOV BL,NUMBER2
DIV BL
MOV QUOTIENT ,AL
MOV REMAINDER,AH
MOV AH,4CH
INT 21H
CODE ENDS
END START
Explaination :
1. In this program we took two variables NUMBER1 and NUMBER2 having values 0009 which 16-bit and 02 which is 8-bit.
2. The rule for division is the dividend must be greater than the divisor for ex. if divisor is 16-bit then the dividend must be 32-bit or greater.
3. As NUMBER1 has 16-bit values so we stored it in 16-bit register i.e. AX and the NUMBER2 in BL register as it stores 8-bit value
4. During division we use DIV instruction and the register/value of divisor after it and the quotient will automatically stored in the AL register and the remainder in the AH register.
5. And at last we moved the quotient in QUOTIENT variable from AL and remainder in REMAINDER variable from AH.
8. Program for multiplication of two 8-bit numbers
DATA SEGMENT
NUMBER1 DB 04H
NUMBER2 DB 03H
PRODUCT DW ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV DX,DATA
MOV DS,DX
MOV AL,NUMBER1
MOV BL,NUMBER2
MUL BL
MOV PRODUCT,AX
MOV AH,4CH
INT 21H
CODE ENDS
END START
Explaination :
1. Same as the the program of division, here there is no rule that any one number should be greater than other.
2. We moved NUMBER1 in the AL register and NUMBER2 in the BL register .
3. Then we use MUL(Multiplication) instruction and same Register/ value where register must be other than AL,AX because MUL instruction multiplies AL/AX with the mentioned register in the program .For ex: If AL=05,BL=04 I will write instruction MUL BL and it will multiply AL with BL
If you think that the explanation I have given is good, then comment me Good Explanation.
1 Comments
Good work
ReplyDelete