Microprocessor and Interfacing
LAB ASSIGNMENT -2
NAME: Asmit Gupta
REG. NO.:18BCE0904
SLOT: L55+L56
FACULTY: VIKAS VIJAYVARGIYA
Q1 A. Write an ALP to find the factorial of numbers 6 and 7.
(Consider number 8bit/16bit)
Aim:
Objective of this expercise is to find the factorial of 6 and 7 using emu8086 Assembly level
language .
Procedure:
1. Initialize DS with the DATA SEGMENT
2. Store the value of n(The number which will be used to find the factorial)
3. Initialize AX with the n
4. Initialize CX with the n-1 vale(for the loop counter)
5. Move the value of AX register to the BX register
6. Then substract 1 form the BX
7. Muntiply BX with the AX and store the result in AX
8. Decrement BX by 1
9. Repeat step 7 to step 8 till CX =0
10. Mov value to AX to the ANS variable
Flow Chart:
Program:
PROGRAM OF 6 FACTORIAL
CODE:-
Assume CS: Code DS: Data
Data Segment
ANS DW 00h
DATA ENDS
CODE SEGMENT
START: MOV AX, @DATA
MOV DS, AX
MOV AX,6
MOV CX, 5
MOV BX,AX
SUB BX,1
L:
MUL BX
SUB BX,1
LOOP L
MOV ANS, AX
CODE ENDS
END START
Output:
PROGRAM OF 7 FACTORIAL
CODE:-
Assume CS: Code DS: Data
Data Segment
ANS DW 00h
DATA ENDS
CODE SEGMENT
START: MOV AX, @DATA
MOV DS, AX
MOV AX,7
MOV CX, 6
MOV BX,AX
SUB BX,1
L:
MUL BX
SUB BX,1
LOOP L
MOV ANS, AX
CODE ENDS
END START
Output:
Inference:
From this program , we can to find the factorial of 6 and 7 using emu8086 software
assembly language and also verified from emulator
Q1 B. Write an ALP to find the nCr and nPr, for that consider n=6
and r= 3
Aim:
Objective of this expercise is to find the permutation and combination of given n and r
values using emu8086 assembly level language
Procedure:
To calculate the permutation and combination, the following steps are to be followed and
these steps have been processed using emu 8086.
1) Compute the factorials n, (n-r) and r
2) For finding the permutation divide factorial of n by the factorial of (n-r)
3) For finding the combination divide the factorial of n by product of the factorial of (n-
r) and the factorial of r.
The registers used to complete the above process are described here below,
AX: The accumulator where all the arithmetic operations are computed.
BX: The address of the data items stored in the memory are operated on using this register.
CX: This register keeps track of the count of the number of times an operation is performed
DX: The register used for temporary storage in case the result overflows from the accumulator
Flow Chart:
CODE:-
org 100h
mov ax,0001h
;;;LOOP for n! ;;;
mov cx,06h ;;;; n value
lab1:mul cx
loop lab1
;;;LOOP for Permutation n!/(n-r)! ;;;
mov cx,06h
sub cx,03h
lab2:div cx
loop lab2
;; Check ax register for the permutation value
;;;; Loop for combination n!/(n-r)!.r! ;;;
mov cx,03h
lab3:div cx
loop lab3
;; Check ax register for combination value ;;;
OUTPUT
For permuration ans is 120(Decimal) = 78H(hexadecimal)
For combination ans is 20(Decimal) = 14H(hexadecimal)
PERMUTATION
COMBINATION
Inference:
From the above experiment the permutation and combination have been appropriately
computed using assembly language.
Q2 ALP Program to generate Fibonacci series
Aim:
Objective of this expercise is to generate the Fibonacci series using emu8086 Assembly level
language .
Procedure:
1. Move the value stored at offset 00H into CX, and decrement it by 2
2. Move 00H into AL
3. Move 500 into SI
4. Move AL into [SI]
5. Increment both AL and SI by 1, and store AL’s value in [SI]
6. Move [SI-1] the value into AL
7. Move [SI]th value into AH
8. Move 00H into BH
9. Add BH and AH
10. Add BH again with AL
11. Increment SI by 1
12. Store BH into [SI]
13. Loop back to Step 6 till counter becomes 0
14. Stop
Flow Chart:
Program:
.model small
.code
main PROC
xor cx, cx
mov bx, 1
loopy:
lea dx, [bx+48]
mov ah, 02h
int 21h
xchg bx, cx
add bx, cx
cmp bx, 10
jb loopy
ENDP
end main
Output:
Inference:
From this program , we generate the Fibonacci series using emu8086 software assembly
languageand also verified from emulator