0% found this document useful (0 votes)
534 views1 page

Bubble Sort in Assembly Language

This program uses bubble sort to arrange an array of bytes in ascending order using assembly language for the 8051 microcontroller. It initializes a counter R0 to the number of bytes minus one. It then loops through the array twice - the inner loop compares adjacent elements and swaps them if out of order, while the outer loop repeats the process for multiple passes until the array is fully sorted.

Uploaded by

utpalwxyz
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
534 views1 page

Bubble Sort in Assembly Language

This program uses bubble sort to arrange an array of bytes in ascending order using assembly language for the 8051 microcontroller. It initializes a counter R0 to the number of bytes minus one. It then loops through the array twice - the inner loop compares adjacent elements and swaps them if out of order, while the outer loop repeats the process for multiple passes until the array is fully sorted.

Uploaded by

utpalwxyz
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
  • 8051 Microcontroller Bubble Sort Example

8051 C

Q2. Write assembly language programme to arrange an array of n byte in ascending order using bubble sort. Ans: ORG 0000H SJMP 30H ORG 30H MOV R0,#(n-1) //Total no. Of bytes(n) to be arranged L1: MOV dptr, #9000h //array stored from address 9000h MOV A,R0 MOV R1,A //store no. Of byte in another register R1 L2: MOVX A, @dptr //GET NUMBER FROM ARRAY MOV B, A //& STORE IN B INC dptr MOVX A, @dptr //next number in the array CLR C //reset borrow flag MOV R2, A //STORE IN R2 SUBB A, B //2nd - 1st no. no compare instruction in 8051 JNC NOEXCHG // JC - FOR DECENDING ORDER MOV A,B //EXHANGE THE 2 NOES IN THE ARRAY MOVX @dptr,a DEC DPL //DEC dptr-INSTRUCTION NOT PTRESENT MOV a,R2 MOVX @dptr,a INC DPTR NOEXCHG: DJNZ R1,L2 //decrement compare counter DJNZ R0,L1 //decrement pass counter here: SJMP here END ALP using 8086 instructions to add, subtract, multiply and divide two 16 bit numbers

cu0001u0002u0003u0004u0005u0003
?u0001u0002u0003u0004u0005u0006u0007u0002b		u0007
u000bf
u0002fbu000eu000fu0010bu000fu0007u0002u0011u0004u0012u000fu0004b

u0007u0002u0006u0012u0002bu0004u0004bu000eu000fu0007u0002bu000eu0002bu0004u0004b
u0002u0012u0013u0002u000eu0002u000b
u0006u0007u0002u0005u000eu0002b	u0014u0007u000eu0015u0005u000eu000fu0002u0012u0004u0015u0007u0004u0002
u0010	u0005u000eu000fu0002u000bu0010u000bu000bfu0007u0002	u0012u0004u0006u0001u0002
u0016u000e	u0017u0002
u0002u0002u0002u0002

You might also like