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

Maharashtra Board of Technical Education, Mumbai.

Certified that this Micro-Project Report

“Calculate Factorial Using ALP”


Is the work of

Roll Enrollment No. Student Name


No.
55 2200150186 Deshmukh Amit Jayachand

63 2200150195 Gobe Abhijit Santosh

The student of Semester four Subject Name-Microprocessor (22415) Diploma


in Computer Technology , 2023-24.

This report is a partial fulfillment of subject MIC(22415) for the award of the
Diploma in Computer Technology , By MSBTE, Mumbai.

Guide Name - Mr. Tarange A.L.

Date & Sign -

HOD PRINCIPAL

1
INDEX
Sr.No. Title Page No
1. Abstract 3

2. Introduction 4

3. 3.1 problem statement


3.2 algorithm
3.3 flowchart
3.4 Initialization &
Instructions 5-12
3.5 Program
3.6 Output

4. Conclusion 13

5. Acknowledgement 14

6 References 15

2
Abstract

This micro project of subject MIC Computer Technology course at Government Polytechnic

Solapur, dives into the world of 8086 assembly language using emu8086 software. We create a

program to calculate factorials. Imagine entering a non-negative integer - our program, coded in

8086 instructions, uses a loop (a programming essential) to perform iterative multiplications,

calculating the factorial. Each loop iteration leverages the efficiency of 8086 instructions. Finally,

the program proudly displays the result! This project showcases emu8086's power in simulating

8086 assembly language. It demonstrates how complex math like factorials translates into

instructions the processor directly executes. More importantly, it serves as a valuable stepping

stone for students to grasp assembly language programming, a foundational layer of

computer architecture

3
Introduction

This micro project tackles calculating factorials by merging two powerful tools: Algorithm Logic

Programs (ALPs) and 8086 assembly language. Our goal is to design a program that finds the

factorial of a number entered by the user, ensuring it's non-negative. The project unfolds in two

stages. First, we'll develop an ALP, a blueprint for the calculation logic. This ALP is hardware and

software agnostic, focusing purely on the steps needed to find the factorial. In the second stage,

we'll take the ALP logic and translate it into the language of 8086 assembly language. This code

will be designed to run on emu8086 software, a program that acts like a virtual 8086

microprocessor. By combining these approaches, we gain a deeper understanding. The ALP

clarifies the core concepts, while the emu8086 implementation showcases how those concepts

translate into instructions the computer can directly execute. This project serves as a valuable

learning experience, solidifying our grasp of algorithm design and assembly

language programming.

4
3.1 Problem Statement

This project defines an ALP (Algorithm Logic Program) to calculate factorials. Find factorial

of non-negative integer number. The ALP logic, independent of hardware, utilizes a loop for

iterative calculations. This ALP serves as the foundation for translating the process into 8086

assembly language for execution on emu8086 software.

5
3.2 Algorithm

1. Start.

2. Declare a variable num,fact.

3. Check if the defined number is negative (num<0).

4. If negative, Terminate the program

5. Initialize fact to 1 (factorial of 0 is 1).

6. Set a loop counter cl initialize it to 1.

7. Loop until counter cl is less than or equal to the number (cl<= num).

• Multiply the current factorial value fact with the loop counter cl.

• Update the fact with the result of the multiplication.

• Increment the loop counter cl by 1.

8. Store the value in of multiplication in fact variable.

9. Stop.

6
3.3 Flowchart

Flowchart for calculating Factorial

Image 1.1

7
3.4 Initialization & Instruction Explanations

1. Data Segment:

a. num db 04h: Declares a byte variable num with initial value 04h.

b. Fact dw 00h: Declares a word variable Fact to store the factorial result, initialized

to 00h.

2. Data Segment Initialization:

a. mov ax, data: Loads the address of the data segment into AX.

b. mov ds, ax: Sets the DS register to point to the data segment.

1. Code segment:

a. Code segment consists of instructions used to develop a program.

b. Execution of thr program starts from start:

1. mov: Moves data between registers or between a register and memory.

a. mov ax, data - Moves the address of the data segment into register AX.

2. dec: Decrements the value in a register by 1.

a. dec bl - Decrements the value in register BL by 1.

3. call: Calls a procedure or subroutine.

a. call Fact - Calls the procedure named "Fact".

8
b. int 21h: Terminates the execution of the program.

4. mul: Multiplies two operands and stores the result in a specific register pair.

a. mul bl - Multiplies the value in AX with the value in BL and stores the result in

DX:AX.

5. ret: Returns to the instruction from where procedure is called.

a. ret - Returns from the current procedure.

9
3.5 Code

assume cs:code,ds:data
data segment ; Define the data segment and declare the variables result and fact
fact db 05h
result dw ?
data ends
code segment ;Define the code segment
start:mov ax,data
mov ds,ax
mov al,fact ;Load the number into the al register and the loop counter cl
mov cl,al
dec cl ;Decrement the loop counter
call disp ;Call the Fact procedure
mov ah,4ch
int 21h ;Termination the program
disp proc near ;Procedure to calculate the factorial of the number
mov bl,al ;Move the number into the BL register
up:dec bl ;Decrement the loop counter
mul bl ;Multiply the current factorial value with the loop counter
loop up
mov result,ax ;Update the factorial value
ret
endp
end start
code ends ;End of the program

10
3.6 Output

Image 3.1

Image 3.2

11
Image 3.3

Image 3.4

Image 3.5

12
Conclusion

This microproject explored calculating factorials using a clever combination: ALPs and

emu8086 assembly. We built a program to find the factorial of a user-entered non-negative

integer.

The project unfolded in two steps. First, an ALP - a hardware-neutral blueprint - outlined the

core logic: initialize, loop, multiply, and accumulate.

Then, we translated this ALP logic into 8086 assembly language for emu8086 software, which

acts like an 8086 microprocessor. This implementation utilized the efficiency of assembly

instructions for direct hardware control.

By combining these approaches, we gained valuable insights. The ALP clarified the algorithm,

while the emu8086 code showed how concepts translate into processor instructions. This

project effectively solidified our grasp of both algorithm design and assembly

language programming.

13
Acknowledgement

This microproject, completed for the Computer Technology course in MIC (Microprocessor

and Interfacing Concepts) at Government Polytechnic Solapur, explored factorial calculation

using ALP. While not explicitly implemented here, an Assembly Language Program (ALP)

initially defined the core logic for calculating factorials, independent of any specific hardware

or software. The resulting assembly language code utilized procedures to promote code clarity

and reusability. The Fact procedure encapsulated the steps to find the factorial. Essential

operators like mov, dec, and mul were instrumental in data manipulation and calculations.

emu8086 software provided the platform to run and test the code. It mimicked the execution

of the program on an 8086 microprocessor, eliminating the need for a physical chip.

By combining these elements, the project successfully calculated factorials. It provided

valuable hands-on experience for MIC students at Government Polytechnic Solapur,

solidifying their understanding of assembly language programming concepts and their

application in solving mathematical problems.

14
Reference

https://www.tutorialspoint.com/index.htm

https://en.m.wikipedia.org/wiki/Assembly_language

https://www.geeksforgeeks.org/

15

You might also like