TransWikia.com

how could i make this assembly code (selection sort algorithm) 2 or 3 milliseconds faster?

Stack Overflow Asked by Edgar Torres on September 13, 2020

i tried alot of things, but that is as close as i got. my assigment asks me to create an assembly selection sort algorith faster than a c++ selection sort algorithm. the difference between my code and the c++ code is 200 or 300 miliseconds, sometimes even 100 milisecond

the assembly procedure takes two arguments, one for the array and one for the number of elements

i am thinking of using stack, and i am thinking that i might not need twp registers to point to the same array but i am not sure how to incorporate it

 

TITLE AsmSelectionSort Procedure (AsmSelectionSort.asm)

 .586
 .model flat,C

 AsmSelectionSort PROTO, arrayPTR:PTR DWORD, count:DWORD

 .data

 .code
 ;----------------------------------------------------------
 AsmSelectionSort PROC arrayPTR:PTR DWORD, count:DWORD
 

 
 
 ;
 ; Performs a selection sort on an array of  32-bit integers.
 ; ----------------------------------------------------------
 
 
 mov ecx, count
 dec ecx
 mov esi, arrayPTR

 mov edx, arrayPTR
 
 
 

 
 L9:push ecx
 
 or ecx, ecx
 jz L5
 
 mov edi, 4

 
 L6:
 or ecx, ecx
 jz L3
 add edx, 4
 mov ebx, [edx]
 
 cmp [esi], ebx
 jb L2
 mov eax, [esi]
 
 mov [esi + edi], eax
 mov [esi], ebx
 
 L2:
 dec ecx
 add edi, 4
 
 jmp L6

 L3:
 
 pop ecx
 dec ecx
 add esi, 4
 
 mov edx, esi
 
 jmp L9

 L5:
 
 jmp short omega

omega:
 ret   ; return
AsmSelectionSort ENDP
END

 
 

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP