How to sort element in assembly language emu8086

Here I will show you how to take user input in an array and sort them in assembly language emu8086

There are many sorting algorithms like insertion sort,selection sort,bubble sort,quick sort,merge sort.In high level language it is easy to use any of these language.But in machine language like assembly it is little bit tough.So here I use a simple and easy sorting algorithm bubble sort.Let's see the code how it works.

I can do your all programming assignments.

INCLUDE 'EMU8086.INC' .MODEL SMALL .STACK 100h .DATA ARR DB 50 DUP(?) ;declare array .CODE MAIN PROC MOV AX,@DATA MOV DS,AX PRINT "Number of data(1-9): " MOV AH,1 INT 21h AND AL,0FH ; convert ascii value XOR CX,CX ;to set zero MOV CL,AL PUSH CX PUSH CX LEA SI,ARR PRINTN ;print new line PRINTN PRINT "Enter Data: " ;print message INPUT: MOV AH,1 INT 21h MOV ARR[SI],AL INC SI LOOP INPUT ;looping POP CX LEA SI,ARR ADD CX,SI XOR BX,BX SORT: ;sorting label SUB CX,1 LEA SI,ARR CMP CX,SI JLE EXIT SWAP: CMP SI,CX JGE SORT MOV BL,ARR[SI] ; bubble sort algorithm MOV BH,ARR[SI+1] CMP BL,BH JLE INCREMENT MOV ARR[SI],BH MOV ARR[SI+1],BL INC SI JMP SWAP INCREMENT: INC SI JMP SWAP EXIT: LEA SI,ARR POP CX PRINTN PRINTN PRINT "After Sorting: " OUTPUT: MOV DL,ARR[SI] ;show output MOV AH,2 INT 21h INC SI LOOP OUTPUT MAIN ENDP END MAIN

Are I can do your web developing project or develop simple game with python, click for order.

Comments

  1. Here is am error to sorting, and if we put 8 value then it goes to in halt position.

    ReplyDelete

Post a Comment

Popular posts from this blog

How to Declare array in Assembly languages emu8086

How To Print New Line in Assembly Language emu8086

Simple Input and output in assembly Language EMU8086