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)

 .model flat,C

 AsmSelectionSort PROTO, arrayPTR:PTR DWORD, count:DWORD


 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

 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
 dec ecx
 add edi, 4
 jmp L6

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

 jmp short omega

 ret   ; return
AsmSelectionSort ENDP


Add your own answers!

Related Questions

How to get a thread dump of a running Node.js process?

3  Asked on December 23, 2020 by philipp-claen


Jquery Select all IDs in different Sections

1  Asked on December 23, 2020 by abcid-d


Can’t merge two dictionaries into one dictionary

3  Asked on December 23, 2020 by yoel-regen


Sharing Power BI Dashboards – External Users

1  Asked on December 23, 2020 by datageek


SQL query to loop through records

1  Asked on December 22, 2020 by doe


Is there a better way to implement nested setTimeouts()

1  Asked on December 22, 2020 by dashman


CMYK image being converted to RGB

0  Asked on December 22, 2020 by entity


Bootstrap Toast at bottom right of page

1  Asked on December 22, 2020 by sean-thorburn


I doesn’t receive any formated data from static class

0  Asked on December 21, 2020 by asfdasfdsfdfsd


SQL Notes: Hackerrank The Report Query how to save the subquery variable

3  Asked on December 21, 2020 by varad-paralikar


NEO4J gives node count as negative

0  Asked on December 21, 2020 by ck22


Ask a Question

Get help from others!

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