0% found this document useful (0 votes)
1K views1 page

Bubble Sort

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)
1K views1 page

Bubble Sort

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
You are on page 1/ 1

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

You might also like