0
10kviews
With the help of a neat flowchart/algorithm write a program in 8086 assembly to arrange a set often 8-bit numbers initialized in data segment in ascending order.
1 Answer
written 7.8 years ago by |
Flowchart:
Algorithm:
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 |