Sunday, April 8, 2012

Program to sort numbers in ascending order using 8086 (unsigned numbers)

assume cs:code,ds:data
data segment
org 2000h
series db 81h,82h,93h,95h,10h,56h,33h,99h,13h,44h
count dw 10d
data ends
code segment
start:mov ax,data
mov ds,ax
mov dx,count
dec dx
go:mov cx,dx
lea si,series
nxt_byte:mov al,[si]
cmp al,[si+1]
jb next
xchg al,[si+1]
xchg al,[si]
next:inc si
loop nxt_byte
dec dx
jnz go
mov ah,4ch
int 21h
code ends
end start

8 comments:

  1. can we exchange only 1st number nd last number without effecting middle numbers

    ReplyDelete
  2. Surely you can do that. Any way we have the count and the sorted array at the end of the program execution. By using them you can swap the last and first number of the array.

    ReplyDelete
    Replies
    1. assume cs:code,ds:data
      data segment
      org 2000h
      series db 81h,82h,93h,95h,10h,56h,33h,99h,13h,44h
      count dw 10d
      data ends
      code segment
      start:mov ax,data
      mov ds,ax
      mov dx,count
      dec dx
      go:mov cx,dx
      lea si,series
      nxt_byte:mov al,[si]
      cmp al,[si+1]
      jb next
      xchg al,[si+1]
      xchg al,[si]
      next:inc si
      loop nxt_byte
      dec dx
      jnz go
      mov ah,4ch
      int 21h
      code ends
      end start

      Delete
  3. If this program can be improved to print the sorted result also, it would be very great

    ReplyDelete
  4. this is not working properly

    ReplyDelete
  5. Crazy Programmers

    ReplyDelete

DC motor control with Pulse Width Modulation Part 1

DC Motor intro DC motor is a device which converts electrical energy into kinetic energy. It converts the DC power into movement. The typica...