REBORN New Member Nov 23, 2015 #1 Hi ! I need a help to do a bubble sort in assembly 8051, and the number of the elements of vector is located in R0 , and so far I do this code. Code: $MOD51 ORG 0 ORD: MOV A,@R0 MOV R7,A DEC R7 INC R0 MOV B, R0 ROT2: MOV R0,B MOV A, R7 MOV R6,A ROT3: ACALL COMP DJNZ R6,ROT3 DJNZ R7,ROT2 RET COMP: MOV A,@R0 INC R0 CLR C SUBB A,@R0 JC FIM XCH A,@R0 DEC R0 XCH A,R0 INC R0 XCH A,@R0 RET FIM: SJMP FIM END Last edited by a moderator: Nov 23, 2015
Hi ! I need a help to do a bubble sort in assembly 8051, and the number of the elements of vector is located in R0 , and so far I do this code. Code: $MOD51 ORG 0 ORD: MOV A,@R0 MOV R7,A DEC R7 INC R0 MOV B, R0 ROT2: MOV R0,B MOV A, R7 MOV R6,A ROT3: ACALL COMP DJNZ R6,ROT3 DJNZ R7,ROT2 RET COMP: MOV A,@R0 INC R0 CLR C SUBB A,@R0 JC FIM XCH A,@R0 DEC R0 XCH A,R0 INC R0 XCH A,@R0 RET FIM: SJMP FIM END
Ian Rogers User Extraordinaire Forum Supporter Most Helpful Member Nov 23, 2015 #2 Sorry had to clean it up so I could read it!!! Code tags make it easier for others to read code.. What's not happeneing
Sorry had to clean it up so I could read it!!! Code tags make it easier for others to read code.. What's not happeneing
Ian Rogers User Extraordinaire Forum Supporter Most Helpful Member Nov 23, 2015 #3 That wasn't bubble sort.. Bubble sort is the slowest sort routine... starting at the beginning it will swap bytes systematically and run through the array n(2) times... I have implemented a bubble sort with 8 items located at position 0x30.. Code: $MOD51 ORG 0 OUTLP: MOV R0,#30H MOV R1,#31H MOV R2,#7 INLP: MOV A,@R0 MOV B,@R1 ACALL COMP INC R1 INC R0 DJNZ R2,INLP DJNZ R3,OUTLP FIM: SJMP FIM COMP: CLR C SUBB A,B JC DONE MOV A,@R0 MOV B,@R1 MOV @R0,B MOV @R1,A DONE: RET END
That wasn't bubble sort.. Bubble sort is the slowest sort routine... starting at the beginning it will swap bytes systematically and run through the array n(2) times... I have implemented a bubble sort with 8 items located at position 0x30.. Code: $MOD51 ORG 0 OUTLP: MOV R0,#30H MOV R1,#31H MOV R2,#7 INLP: MOV A,@R0 MOV B,@R1 ACALL COMP INC R1 INC R0 DJNZ R2,INLP DJNZ R3,OUTLP FIM: SJMP FIM COMP: CLR C SUBB A,B JC DONE MOV A,@R0 MOV B,@R1 MOV @R0,B MOV @R1,A DONE: RET END