Sorting algorithms/Bubble sort: Difference between revisions

Add X86 Assembly
m (→‎{{header|REXX}}: added DO-END labels, added comments, added whitespace. -- ~~~~)
(Add X86 Assembly)
Line 3,338:
NumberOfItems = NumberOfItems - 1
Loop</lang>
 
=={{header|X86 Assembly}}==
Translation of XPL0. Assemble with tasm, tlink /t
<lang asm> .model tiny
.code
.486
org 100h
start: mov si, offset array
mov ax, 40 ;length of array (not including $)
call bsort
mov dx, si ;point to array
mov ah, 09h ;display it as a string
int 21h
ret
array db "Pack my box with five dozen liquor jugs.$"
 
;Bubble sort: si = array addrsss, ax = number of bytes
bsort: pusha
xchg cx, ax ;get size of array N
dec cx ;for J:= N-1 downto 0
bs10: xor bx, bx ;for I:= 0 to J-1
bs20: mov ax, [bx+si]
cmp al, ah ;if A(I) > A(I+1) then
jbe bs30
xchg al, ah ; swap bytes
mov [bx+si], ax
bs30: inc bx ;next I
cmp bx, cx
jb bs20
loop bs10
popa
ret
end start</lang>
 
Output:
<pre>
.Pabcdeefghiiijklmnoooqrstuuvwxyz
</pre>
 
=={{header|XPL0}}==
772

edits