Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Shows how to sort an array

ajtr211ajtr211 Member Posts: 31
Hi,Greetings
This is a very simple program
that sorts an array of integers.
This program can easily be improved up on

.model small
.stack 100h
.486
ArrayCount = 8
.data
Array dw 879,568,324,931,675,564,432,197
ArrayBuffer dw 8 dup(0)
.code
extrn Writestring:proc,Writeint:proc,
CrLf:proc
;You must have these three procedures in
;your library !
main proc
mov ax,@data
mov ds,ax
mov es,ax

mov bx,offset Array
mov cx,ArrayCount
call sort
mov cx,8
mov si,offset Array
L1:
mov ax,[si]
mov bx,0
mov bx,10
call Writeint
call CrLf
add si,2
loop L1

mov ax,4c00h
int 21h
main endp

sort proc
dec,cx
rpt:
push cx
mov si,bx
top:
mov ax,[si+2]
cmp [si],ax
jl short OK
xchg ax,[si]
xchg ax,[si+2]
OK:
add si,2
loop top

pop cx
dec cx
mov ArrayBuffer,ax
jg short rpt

ret
sort endp
end main

OUTPUT:
197
324
432
564
568
675
879
931
(AJTR211)

Comments

  • Justin BibJustin Bib USAMember Posts: 0

    _ < http://forcoder.org /> free video tutorials and ebooks about // R, Ruby, JavaScript, Python, Perl, Swift, Objective-C, C++, Java, PL/SQL, PHP, Go, C#, Visual Basic, C, Assembly, Visual Basic .NET, Delphi, MATLAB, Scratch Scala, Prolog, ML, Alice, Erlang, Fortran, D, Clojure, SAS, Lisp, LabVIEW, COBOL, Scheme, Kotlin, Julia, Ada, VBScript, Bash, Hack, Logo, Awk, FoxPro, Transact-SQL, Crystal, Lua, F#, ABAP, Rust, Apex, Dart // __________

Sign In or Register to comment.