0% found this document useful (0 votes)
2 views

ASM Project

This document outlines a project that demonstrates the calculation of factorial numbers from 0 to 7 using x86 assembly language. It emphasizes the importance of low-level programming concepts such as loops, memory management, and system interrupts, while providing a practical example for educational purposes. The project showcases efficient resource utilization and faster execution, making it a valuable learning tool for understanding assembly language and its applications in computational tasks.

Uploaded by

pranavsp2810
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

ASM Project

This document outlines a project that demonstrates the calculation of factorial numbers from 0 to 7 using x86 assembly language. It emphasizes the importance of low-level programming concepts such as loops, memory management, and system interrupts, while providing a practical example for educational purposes. The project showcases efficient resource utilization and faster execution, making it a valuable learning tool for understanding assembly language and its applications in computational tasks.

Uploaded by

pranavsp2810
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

CALCULATING FACTORIAL NUMBER

 Introduction

In assembly language programming, the concept of calculating a


factorial is an important exercise to understand basic operations such
as multiplication, loops, and memory management. The factorial of a
number is the product of that number and all the integers below it,
down to 1. Assembly language, being a low-level language, allows
direct control over hardware resources, making it ideal for learning
fundamental computational tasks.
This program focuses on calculating the factorial of a number ranging
from 0 to 7, as larger values would exceed the typical storage capacity
for small data types. By using a loop, the program will multiply the
integers sequentially to compute the desired result. This task helps to
reinforce key principles of flow control, stack management, and the
handling of input and output in assembly language. The challenge of
implementing a factorial calculation in assembly provides a deeper
understanding of how programming tasks are handled at a low level.

1
CALCULATING FACTORIAL NUMBER

 About

This project demonstrates the calculation of a factorial for a given


number between 0 and 7 using assembly language. The program
utilizes the x86 assembly language and adheres to the .MODEL
SMALL memory model, making it suitable for simple applications.
The user is prompted to enter a number, and the program then
calculates its factorial using a loop-based approach.
The factorial calculation is performed by repeatedly multiplying the
number with its decremented value until it reaches 1. The result is
stored and displayed to the user. The program leverages interrupt calls
(INT 21H) for input and output operations, specifically for displaying
messages and numbers on the screen. Additionally, the program
includes a custom subroutine (PRINT_NUMBER) that handles the
conversion of the computed factorial result into its respective digits
for output.
The project highlights essential concepts in assembly language
programming, including data manipulation, loops, and interacting
with system interrupts. It provides an understanding of how low-level
programming interacts with system resources to perform tasks such as
number computation and user interaction. This exercise also serves as
a foundational example of factorial calculation in assembly, making it
an excellent learning tool for those new to assembly programming.

2
CALCULATING FACTORIAL NUMBER

 Use of Factorial Numbers


1. Mathematical Computations: Factorial calculations are
essential in fields like probability and statistics, useful in
analysing outcomes and planning tasks. This program can be
applied to solve real-world combinatorial problems in various
industries.

2. Algorithm Optimization: Assembly language allows for


precise control over system resources, which can optimize
algorithms in resource-constrained environments. This helps in
improving the efficiency of computations for critical
applications.

3. Data Science & Machine Learning: Factorials are integral to


algorithms in machine learning, like combinatorial optimization
and decision tree analysis. The project aids in understanding
how such algorithms operate at a low level, enhancing
computational methods.

4. Computer Science Education: This project serves as a


practical example for students to learn about low-level
programming, memory management, and control flow. It
strengthens their understanding of how programs interact with
hardware resources.

5. Performance Analysis: Understanding how factorial


calculations are handled in assembly can inform the
development of high-performance algorithms. This is valuable
in performance-critical applications where efficient code
execution is key.

3
CALCULATING FACTORIAL NUMBER

 Advantages:
 Efficient Resource Utilization: Assembly language allows
direct control over hardware, making it highly efficient in terms
of memory and processor usage. This results in faster execution
and optimized use of system resources.

 Low-Level Understanding: Writing a program in assembly


provides a deep understanding of how the computer works at a
hardware level. It helps learners understand how higher-level
operations are translated into machine-level instructions.

 Faster Execution: Because assembly language is compiled


directly into machine code, it executes faster compared to
programs written in higher-level languages. This is particularly
beneficial for tasks requiring fast computation, such as factorial
calculations.

 Optimized for Embedded Systems: Assembly language is


widely used in embedded systems where performance and
memory constraints are crucial. This project can be adapted for
use in such systems, making it highly practical for real-time
computing applications.

 Helps in Debugging and Troubleshooting: Since assembly


language gives full visibility of the underlying system
operations, it helps in debugging low-level errors and
optimizing performance. Understanding assembly aids in
pinpointing inefficiencies in a program.

4
CALCULATING FACTORIAL NUMBER

 Code:
1. .MODEL SMALL
2. .STACK 100H
3. .data
4. MSG_PROMPT DB 'Enter a number (0-7): $'
5. MSG_RESULT DB 'Factorial is: $'
6. INPUT_NUM DB 0
7. FACTORIAL_RESULT DW 1
8. NEWLINE DB 0DH, 0AH, '$'
9.
10. .CODE
11. MAIN PROC
12. MOV AX, @data
13. MOV DS, AX
14. LEA DX, MSG_PROMPT
15. MOV AH, 09H
16. INT 21H
17. MOV AH, 01H
18. INT 21H
19. SUB AL, '0'
20. MOV INPUT_NUM, AL
21. MOV AL, INPUT_NUM
22. MOV AH, 0
23. MOV CX, AX
24. MOV AX, 1
25.
26. FACTORIAL_LOOP:
27. CMP CX, 1
28. JLE DISPLAY_RESULT
29. MUL CX
30. DEC CX
31. JMP FACTORIAL_LOOP
32.
33. DISPLAY_RESULT:
34. MOV FACTORIAL_RESULT, AX
35. LEA DX, MSG_RESULT
36. MOV AH, 09H
37. INT 21H
38. MOV AX, FACTORIAL_RESULT
39. CALL PRINT_NUMBER
40. LEA DX, NEWLINE

5
CALCULATING FACTORIAL NUMBER

41. MOV AH, 09H


42. INT 21H
43. MOV AH, 4CH
44. INT 21H
45.
46. MAIN ENDP
47.
48. PRINT_NUMBER PROC
49. PUSH AX
50. PUSH BX
51. PUSH CX
52. PUSH DX
53. XOR BX, BX
54. MOV BX, 10
55. MOV CX, 0
56.
57. PRINT_LOOP:
58. XOR DX, DX
59. DIV BX
60. PUSH DX
61. INC CX
62. CMP AX, 0
63. JNE PRINT_LOOP
64.
65. PRINT_DIGITS:
66. POP DX
67. ADD DL, '0'
68. MOV AH, 02H
69. INT 21H
70. LOOP PRINT_DIGITS
71.
72. POP DX
73. POP CX
74. POP BX
75. POP AX
76. RET
77. PRINT_NUMBER ENDP
78. END
MAIN

 Output:

6
CALCULATING FACTORIAL NUMBER

7
CALCULATING FACTORIAL NUMBER

 Conclusion:

In conclusion, this assembly language project demonstrates the


efficient calculation of a factorial for numbers ranging from 0 to 7.
By leveraging low-level programming, the project highlights the
fundamental operations of memory management, control flow, and
arithmetic processing using registers and interrupts. The use of the.
MODEL SMALL memory model and INT 21H ensures
compatibility and efficient resource usage.
Through the iterative approach in the factorial calculation loop, this
program showcases the power of assembly language in performing
precise and optimized operations. The inclusion of a custom
subroutine for digit-wise output further illustrates modular
programming techniques, enhancing the clarity and functionality of
the code.
This project not only serves as a practical implementation of
factorial calculation but also provides valuable insights into how
low-level programming interacts directly with hardware. It is a
valuable learning tool for students and developers seeking to
strengthen their understanding of assembly language and its
applications in mathematical computations. Overall, the project
underscores the importance of assembly in developing efficient,
resource-conscious programs while reinforcing key programming
concepts.
.

8
CALCULATING FACTORIAL NUMBER

 Reference:

1. https://www.geeksforgeeks.org/advantages-and-disadvantages-
of-assembler/?utm_source=chatgpt.com

2. https://www.ibm.com/docs/en/z-netview/6.3.0?
topic=SSZJDU_6.3.0/com.ibm.iznetview.doc_6.3.0/
dqe_api_wwial.htm

3. https://medium.com/%40abnerrjo/factorial-function-in-
assembly-363f507773e2

4. https://www.youtube.com/watch?v=hY9P2mfNNQU

5. https://www.geeksforgeeks.org/8086-program-find-factorial-
number/?utm_source=chatgpt.com

You might also like