Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

EXPT-4

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

MICRO PROCESSORS & MICROCONTROLERS ECE

LABDEPARTMENT

EXP.No: 04 Date:

FACTORIAL OF A NUMBER

AIM: To write assembly language program to find factorial of a number

APPARATUS: 1.MASM software

2.PC

REGISTERS USED: AX,BX,CS,DS

FLAGS EFFECTED: ZERO FLAG

ALGORITHM:

1. Initialse the data segment


2. Move the value 0001 to AX register
3. Move value 0005 toBX register
4. Multiply AX with BX and move to AX
5. Decrement BX value by one
6. Jump if not zero to repeat
7. Move AX value to result [0000]
8. Move 4C value to AH register

PROGRAM:

ASSUME CS:CODE ,DS:DATA

DATA SEGMENT

NUM DB 05H

RESULT DB(?)

DATA ENDS

CODE SEGMENT

START: MOV AX, DATA

MOV DS,AX

MOV AX,0001

MOV BX,NUM

REPEAT: MUL BX

PRAGATI ENGINEERING COLLEGE, SURAMPALEM Page 1


MICRO PROCESSORS & MICROCONTROLERS ECE
LABDEPARTMENT

DEC BX

JNZ REPEAT

MOV [RESULT], AL

MOV AH, 4CH

INT 21H

CODE ENDS

END START

CODE TABLE:

BASE OFFSET HEXA OPCODE OPERAND COMMENTS


ADDRESS ADDRESS DECIMAL
OCDE
0B57 0000 B8560B MOV AX,0B56 INITIALISATION
OF DATA
SEGMENT
0B57 0003 8ED8 MOV DS,AX
0B57 0005 B80100 MOV AX,0001 MOVE 0001 TO
AX
0B57 0008 BB0500 MOV BX,0005 MOVE 0005 TO
BX
0B57 000B F7E3 MUL BX MULTIPLY AX
WITH BX
0B57 000D 4B DEC BX DECREMENT
BX
0B57 000E 75FB JNZ 000B JUMP IF NOT
ZERO TO
REPEAT
0B57 0010 A20000 MOV [0000],AL STORE AX
VALUE IN
RESULT
0B57 0013 B44C MOV AH,4C MOVE 4C TO AH
REGISTER
0B57 0015 CD21 INT 21

PROCEDURE:

1. Type masmfilename.asm and press enter on the command prompt.

2. If any errors are present rectify that errors and go to step3.

3. Type link filename.obj and press enter.

PRAGATI ENGINEERING COLLEGE, SURAMPALEM Page 2


MICRO PROCESSORS & MICROCONTROLERS ECE
LABDEPARTMENT

4. Type debug filename.exe and press enter.

5. Press command ‘U’ and note down the code table

6. Trace the program by typing command ‘T’until INT 21H

7. Type eds: offset address of input/output variables for obtain the result.

8. Type ‘q’ command for Quit the program

OBSERVATIONS:

INPUT: 05H

OUTPUT: 78H(120)

Result: HENCE FACTORIAL OF A NUMBER IS OBTAINED USING MASM


SOFTWARE

PRAGATI ENGINEERING COLLEGE, SURAMPALEM Page 3

You might also like