# sort.s # insert sort by pt matfyz cz # linux environment and i386 needed # compile: as -o sort.o sort.s .file "sort.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 pushl %ecx pushl %edx pushl %eax pushal # save esi, edi, ebx as needed pushl %edx # pass array start to edi jmp .L3 .L0: scasl # advance edi by 4 pushl %edi # save current array ptr movl %edi, %esi std # reverse stringops lodsl # value to be inserted movl %eax, %ebx .L1: lodsl # value in sorted part cmpl %eax, %ebx jge .L2 # stop if lower encountered stosl # move array to create space for edx cmpl %edx, %esi # start of array? jae .L1 .L2: cld # restore df movl %ebx, (%edi) # insert value .L3: popl %edi # restore current array ptr loop .L0 # continue ecx times popal # restore saved registers ret # bye .L4: .size sort,.L4-sort .ident "insert sort of size 36 bytes" # end of sort.s