Saturday, 28 September 2013

program to check given 8-bit data is "2 out of 5 code" or not

Before we write the program to check whether the given 8-bit data is "2 out of 5 code" or not, let us first understand what is meant by 2 out of 5 code. An 8-bit is 2 out of 5 code if and oly if its 3 MSB bits are zero and the remaining 5 bits contains two 1's. You will be able to understand clearly from the following example shown below.


 let us take the 8 bit data as 18

18 = 0001 1000
         1      8

so in the above example the 3 MSB bits(i.e first 3 bits) are zero & there are two 1's in remaing 5 bits. so that makes the given 8-bit 2 out of 5 code.


Program :
// If given 8 bit is 2 out of 5 code store FFH in memory location 30H//
//If no, store 00H in memory location 30H//


        ORG 00H
        SJMP START
        RESULT EQU 30H
START : MOV A,#_H
        MOV B,A
        ANL A,#0E0H
        JNZ EXIT
        MOV A,B
        MOV R0,#05H
        MOV R1,#00H
   UP : RRC A
        JNC DOWN
        INC R1
 DOWN : DJNZ R0,UP
        MOV A,R1
        CJNE A,#02H,EXIT
        MOV RESULT,#0FFH
        SJMP STOP
 EXIT : MOV RESULT,#00H
 STOP : SJMP STOP
        END






program to perform multiplication of two 8 bit no.s using successive addition method

        ORG 000H
        SJMP START
        RESL EQU 30H
        RESH EQU 31H
START : MOV A,#00H
        MOV B,#_H      /*enter 1st no. */
        MOV R0,#_H     /*enter 2nd no. */
   UP : ADD A,B
        JNC DOWN
        INC RESH
 DOWN : DJNZ R0,UP
        MOV RESL,A
 STOP : SJMP STOP
        END


output :

sl.no  N1    N2    RESH   RESL
      (1st no.)  (2nd no.)  (31H)        (30H)

 1.    8     32     1     90
 2.    6     12     0     6C
 3.    9     14     0     B4    

Thursday, 19 September 2013

program to find bigger no. in a list of given no.s

        ORG 000H
        SJMP START
        RESULT EQU 30H 
START : MOV R0,#30H
        MOV R1,#05H  /* R1 declared as a pass counter*/
        MOV B,@R0
   UP : INC R0
        MOV A,@R0
        CLR C
        SUBB A,B
        JC SKIP
        MOV B,@R0
 SKIP : DJNZ R1,UP
        MOV RESULT,A
 STOP : SJMP STOP

Tuesday, 17 September 2013

Program to sort numbers in ascending order

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

To move data from one memory location to another

        ORG 000H
        SJMP START
START : MOV R2,#05H /* R2 declared as a pass counter*/
        MOV R0,#30H
        MOV R1,#50H
   UP : MOV A,@R0
        MOV @R1,A
        INC R0
        INC R1
        DJNZ R2,UP
 STOP : SJMP STOP

To exchange contents of two memory location

        
        ORG 000H
        SJMP START
START : MOV R2,#05H /* R2 declared as a pass counter*/
        MOV R0,#30H
        MOV R1,#50H
   UP : MOV A,@R0
        MOV B,@R1
        MOV @R1,A
        MOV @R0,B
        INC R1
        INC R0
        DJNZ R2,UP

STOP  : SJMP STOP