4.21 Sorting an Array of Values

Almost every textbook on this planet gives an example of a sort when introducing arrays. Because you've probably seen how to do a sort in high-level languages already, it's probably instructive to take a quick look at a sort in HLA. The example code in this section will use a variant of the bubble sort, which is great for short lists of data and lists that are nearly sorted but horrible for just about everything else.[63]

const NumElements := 16; static DataToSort: uns32[ NumElements ] := [ 1, 2, 16, 14, 3, 9, 4, 10, 5, 7, 15, 12, 8, 6, 11, 13 ]; NoSwap: boolean; . . . // Bubble sort for the DataToSort array: repeat mov( true, NoSwap ); for( mov( 0, ebx ); ebx <= NumElements-2; inc( ebx )) do mov( DataToSort[ ebx*4], ...

Get The Art of Assembly Language, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.