add1

Tuesday, October 11, 2016

MCSL 017 C and Assembly Language Programming 16-17



MCSL 017 
MCA 1st semester 
Section 2: Assembly Language Programming Lab

(b) Write a program in assembly language to find the factorial of any number (assume number is smaller than 10).

data segment
    msg db "THIS PROGRAM FOR FACTROIAL OF ANY NO$"
    MSG2 DB "FACTROIAL OF 6 IS = $"
    NO DD 6
    TMP DD 1
ends data
code segment
    assume cs:code,ds:data
    start:
    mov ax,data
    mov ds,ax
   
    lea dx,msg
    mov ah,09
    int 21h
    MOV dx,10
    mov ah,02
    int 21h
    MOV dx,13
    mov ah,02
    int 21h
   
    MOV AX,0
    MOV BX,0
    MOV CX,0
    MOV DX,0
    MOV AX,TMP
    MOV BX,AX
    L1:
    INC BX
    MUL BX            
    MOV TMP,AX
    cmp BX,NO
    JNE L1:
   
   
    MOV AX,0
    MOV BX,0
    MOV CX,0
    MOV DX,0
   
    MOV AX,TMP
    MOV BX,10
    L2:
    DIV BX
    PUSH DX
    MOV DX,0
    INC CX
    CMP AX,0
    JNE L2:
          
    lea dx,msg2
    mov ah,09
    int 21h
   
    L3:
    POP DX
    ADD DX,48
    MOV AH,02
    INT 21H
    LOOP L3
      
    
    MOV AH,4CH
    INT 21H
code ends
end start

No comments:

Post a Comment