# sort-32.s # insert sort by pt matfyz cz # linux environment and i386 needed # compile: as -o sort-32.o sort-32.s .file "sort-32.s" .globl sort .type sort,@function .text # calling convention: saves ebp, ebx, esi, edi, df (a must) # assumes that items count is >= 1 (see isort.c) sort: popl %eax # return address popl %edx # array address popl %ecx # items cnt pushal # save %esi, %edi, %ebx as needed pushl %edx # pass array address to %esi jmp .L3 .L0: lodsl # advance %esi pushl %esi # save 4l8r movl %esi, %edi # std # df=1 lodsl # value to be inserted .L1: cmpl (%esi), %eax # still continue moving ? jge .L2 movsl # move array to create space for %eax cmpl %edx, %edi # start of array? jne .L1 .L2: stosl # insert value from %eax cld # df=0 .L3: popl %esi # restore current ptr into array loop .L0 # continue %ecx times popal # restore saved registers pushl %eax # dummy pushl %eax # dummy pushl %eax # return address ret # bye .L4: .size sort,.L4-sort .ident "insert sort of size 32 bytes" # end of sort-32.s