Search This Blog

Saturday, August 27, 2011

WAP in 8051 to sort a block of data in ascending or descending order


; PROGRAM STARTS HERE


MOV R6, #07H ; EXTERNAL COUNTER
START : MOV R7, #07H ; INTERNAL COUNTER
MOV R0, #30H ; INTERNAL MEMORY ADDRESS
MOV A, #00H ; CLEAR ACCUMULATOR
; CY = 0 A>VAL
; CY = 1 A<VAL
BACK :   MOV A, @R0 ;
INC R0 ;
CJNE A, @R0, CARRY ;
SJMP DECREMENTC ;
CARRY : JC DECREMENTC ;
MOV B, @R0 ;
MOV @R0, A ;
DEC R0 ;
MOV A, B ;
MOV @R0, A ;
DECREMENTC : INC R0 ;
DJNZ R7, BACK ;
DJNZ R6, START ;
END

16 comments:

  1. its showing error in 12th line .. "illegal operand"

    ReplyDelete
    Replies
    1. the space between ,and b shud nt come in that 12th line

      Delete
    2. Please Write the line your facing trouble, instead of the line number.

      Delete
  2. CJNE A, @R0, CARRY
    in this line a instruction error exists...

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. this is incorrect the instruction
    cjne a, @r0, carry
    doesnot exist
    try another one

    ReplyDelete
    Replies
    1. Please have a look at the following link...
      http://www.8052.com/51cjne

      A traditional 8051 has been used to execute this program..
      If you are using a new one or some new compiler or simulator the equivalent command has to be replaced....

      Delete
    2. cjne should have A,B,carry in its syntax

      Delete
  5. this is incorrect the instruction
    cjne a, @r0, carry
    doesnot exist
    try another one

    ReplyDelete
    Replies
    1. Please have a look at the following link...
      http://www.8052.com/51cjne

      A traditional 8051 has been used to execute this program..
      If you are using a new one or some new compiler or simulator the equivalent command has to be replaced....

      Delete
    2. That equivalent command i will redo and update soon.

      Delete
    3. % PROGRAM FOR DESCENDING ORDER
      MOV R0,#0FH
      UP1:MOV R7,#0FH
      MOV R1,#30H
      UP:MOV A,@R1
      INC R1
      MOV B,@R1
      CJNE A,B,NEXT
      SJMP DOWN
      NEXT:JNC DOWN
      MOV @R1,A
      DEC R1
      MOV A,B
      MOV @R1,A
      INC R1
      DOWN: DJNZ R7,UP
      DJNZ R0,UP1
      END

      Delete
    4. % program for ascending order

      MOV R0,#04H ;external counter
      UP1:MOV R7,#04H ;internal counter
      MOV R1,#30H
      UP:MOV A,@R1
      INC R1
      MOV B,@R1
      CJNE A,B,NEXT
      SJMP DOWN
      NEXT:JC DOWN
      MOV @R1,A
      DEC R1
      MOV A,B
      MOV @R1,A
      INC R1
      DOWN: DJNZ R7,UP
      DJNZ R0,UP1
      END

      Delete
    5. good work charusheela patil ....

      Delete
  6. How to write the code for arranging a block of binary numbers in ascending order ?

    ReplyDelete
    Replies
    1. Need information like how the binary numbers are stored?? Being a byte based memory system is stored as fixed sized array in memory as 1 or zero or some other way??

      Delete