Você está na página 1de 4

SSBTs College of Engineering & Technology, Bambhori, Jalgaon

Department of Computer Engineering


Name: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ __ _ _ _ _ _Date of Performance: _ _ /_ _/20_ _
Class: S.E. Computer
Date of Completion: _ _ /_ _/20_ _
Div: _ _ _ , Batch: _ _ _ _ _ _
Grade: _ _ _ _ _
Roll No: _ _ _ _ _

Subject: Microprocessor and Microcontroller Lab

Sign. of Teacher with Date:

EXPERIMENT NO: 08

TITLE: Factorial of a Number.


AIM: Write an 8086 Assembly Language Program to find out Factorial of a number (Range 0 to 8)
Objectives:
1. To apply concept of finding out factorial of a given number.
2. To apply concept of NEAR procedure in a program.

Background:
Procedures are a group of instructions stored as a separate program in memory and it is called
from the main program whenever required. The type of procedure depends on where the
procedures are stored in memory. If it is in the same code segment as that of the main program
then it is a near procedure otherwise it is a far procedure.

Near Call: A call to a procedure within the current code segment (the segment currently pointed
to by the CS register), sometimes referred to as an intra-segment call.
Syntax
Name PROC NEAR
<Instructions>
Name ENDP

Pre-Lab Task:
Required interrupt functions:-

Interrupt No.
INT 21H

Function

Description

AH= 09H

To print string of characters.

AH= 4CH

To terminate a program and return at command


prompt.

AH = 02H

To print a single character

Required main Instructions:-

Instruction

Description

MUL

Multiply Unsigned Bytes or Words: This instruction multiplies an


unsigned byte from some source times an unsigned byte in AL
register or an unsigned word from some source times an unsigned
word in AX register.
e.g. MUL BH ; AL times BH , result in AX
MUL CX ; AX times CX , result high word in DX, low word
; in AX

ROR

Rotate All Bits of Operand Right: This instruction rotates all bits in
a specified byte or word to the right, some number of bit positions.
LSB is placed as a new MSB and a new CF.

Program Template:

DATA SEGMENT
; Declare required HEX_CHART and NUMBER (i.e. input)
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
MOV AX, DATA
MOV DS, AX ; Initialization of DS register

; Write down the set of instructions to calculate Factorial of a number,


; as per the given algorithm
CALL DISP_CHAR

; Call NEAR procedure to display the result


; character by character

DISP_CHAR PROC NEAR

; Define NEAR procedure to display a


; single character of a result

; Write down set of instructions to display single character


RET
DISP_CHAR ENDP
MOV AH, 4CH
INT 21H
CODE ENDS
END

; To terminate a program

In-Lab Task:
Students will execute a complete program as per following algorithm and will write down the
Result/Output.
Algorithm:
1. Define an input NUMBER in Data segment, for finding out factorial.
2. Define Counter = NUMBER.
3. If the NUMBER

= 0, then
Factorial is 1, display the result and terminate a program.
Else
Decrement the number by 1, multiply with original number and repeat this
Step till Counter becomes 0.
4. Call Near Procedure to display the result character by character.

5. Define Near Procedure to display a single character of a result.

6. Terminate the program and return back to OS.

Result/Output: - ____________________________________________________
__________________________________________________________________
__________________________________________________________________
Post-Lab Task:
Outcomes:
1. The concept of factorial of a number
2. The Concept of a Procedure.

Reference Books:1. John E. Uffenbeck , The 8086/ 8088 Family: Design, Programming and Interfacing, Pearson.
2. Douglas V. Hall Microprocessor and Interfacing Programming and Hardware Pearson.
3. Peter Abel, IBM PC Assembly Language and Programming Pearson.

Questions for Viva:1. Explain overall logic of a program.

Name of Teacher

Sign

Você também pode gostar