Sort three variables: Difference between revisions

Content added Content deleted
(Add CLU)
Line 85: Line 85:
lions, tigers, and
lions, tigers, and
</pre>
</pre>

=={{header|8086 Assembly}}==
===Sorting Unsigned Integers===
<lang asm>mov ax,6FFFh
mov bx,3456h
mov cx,0

;We'll consider these sorted when ax <= bx <= cx.

SortRegisters proc
cmp ax,bx
jbe continue
;if we got here, ax > bx. We don't know the relationship between bx and cx at this time.
cmp ax,cx
jbe swap_ax_and_bx
;if we got here, ax > bx, and bx > cx. Therefore all we need to do is swap ax and cx, and we're done.
xchg ax,cx
jmp endOfProc

swap ax_and_bx:
;if we got here, ax > bx, and ax <= cx. So all we have to do is swap ax and bx, and we're done
xchg ax,bx
jmp end ;back to top

continue: ;if we got here, ax <= bx.
cmp bx,cx
jbe end
;if we got here, ax <= bx, and bx > cx. Therefore all we need to do is swap bx and cx, and we're done.
xchg bx,cx


endOfProc: ;if we got here, ax <= bx, and bx <= cx. Therefore, ax <= bx <=cx and we are done.
;

SortRegisters endp </lang>


=={{header|Ada}}==
=={{header|Ada}}==