0
12kviews
With the neat flowchart/algorithm write a program in 8086 assembly to arrange a set of ten 8-bits numbers initialized in data segment in ascending order

Subject: Microprocessors and Applications

Topic: Instruction set of 8086 & programming

Difficulty: High

1 Answer
0
221views

Flowchart:

enter image description here

Algorithm:

  • Initialize the data segment.
  • Initialize the number of elements counter.
  • Initialize the pointer and number of comparisons counter.
  • Compare the elements. If first element < second element go to step VI else go to step V.
  • Swap the elements.
  • Increment the pointer. Decrement the comparison counter.
  • Is count = 0? If yes, go to step VIII else go to step IV.
  • Decrement the number of elements counter.
  • Is count = 0? If yes, go to step X else go to step III.
  • Stop.
Label Instruction Comment
  .model small   ;
  .stack 100 Initialize stack segment
  .data Initialize the data segment
  num dw 0102H, 0154H, 0070H, 0005H Initialize data
  count dw 04 Initialize counter
  .code Initialize code segment
  mov ax, @data Initialize data section
  mov ds, ax  
  mov dx, count Initialize the number of elements counter
  dec dx Number of comparisons is one less than the number of elements
loop2: lea si, num Initialize the pointer
  mov cx, dx CX number of comparisons required
loop1: mov ax, [si] Load a data
  cmp ax, [si + 2] Compare it with next number
  jc next If previous number < = this number go to next
  xchg [si + 2], ax Swap if not sorted
  mov [si], ax Insert in new position
next: inc si Increment si
  inc si  
  loop loop1 Decrement comparison counter and repeat if not zero
  dec dx Decrement number of elements counter
  jnz loop2 Repeat if not zero
  mov ah, 4ch Termination of the program
  int 21h  
  end start  
Please log in to add an answer.