Tuesday, April 19, 2016

Bubble Sort in 8086

I've just made a bubble sort program in assembly language. It sorts 32 8 bit numbers. I have used emu8086 for simulation.
here is the code.

        mov ax,3000h
        mov ds,ax
     
        mov di,2070h
        mov cl,32
back:   mov si,2050h
        mov dh,cl
        mov bx,cx
        dec bx
        mov al,[si][bx]
        jmp done
     
up:     dec si
        cmp al,[si][bx]
        jc done
        xchg al,[si][bx]
done:   dec dh
        jnz up
        mov [di],al
        inc di
        loop  back
        hlt
         

You have to fill up the memory segment in 3000:2050 with random 32 8-bit numbers.
Watch this video

No comments:

Post a Comment