Showing posts with label 8051 programming. Show all posts
Showing posts with label 8051 programming. Show all posts

Sunday, 13 November 2016

Write a program to FIND THE FACTORIAL OF GIVEN NUMBER




ORG 0000            /* starting of the                              programe
                     MOV R1,#04      /* load r1 with 04
                     MOV R7,#01      /* load r7 with 01
                    LCALL FACT      /*longcalltothefact subroutine    
                    MOV R7,A        /* load R7 WITH 00

FACT: MOV A,R7        /* LOAD A WITH 01
                    CJNE R1,#00,UP   /*compare jump in not                           equal 
                    SJMP UP1        /* inttrupt(condition                           togo up1)
UP:   MOV B,R1       /* b= 00
                    MUL AB          /* result in A
                   DJNZ R1,UP      /* decrement jump if r1                          zero
UP1:  RET             / return
                         END

Thursday, 10 November 2016

Write a Program to sort numbers in ascending order from gievn list



ORG 000H
        SJMP START
START : MOV R1,#05H  /* R1 declared as a pass counter*/
AGAIN : MOV A,R1       /* A=R1
        MOV R2,A     /* R2=A
        MOV R0,#30H          /* R0=30
        MOV A,@R0   /* A=30  
   UP : INC R0  /* R0= 31
        MOV B,@R0     /* B=31
        CLR C      /* C=00
        SUBB A,B    /* A=01
        JC SKIP   /* JUMP IF C=1
        MOV B,@R0   /* B= 31
        DEC R0    /*  R0=30
        MOV A,@R0    /* A=30
        MOV @R0,B   /* R0=31
        INC R0   /* R0=32
        MOV @R0,A 
 SKIP : DJNZ R2,UP
        DJNZ R1,AGAIN
 STOP : SJMP STOP