Bubble Sort
Bubble Sort
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