AnswerBun.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!

Related Questions

How to toggle button text when clicked with JavaScript in HTML

6  Asked on December 21, 2020 by marcosvaldez81

     

Why is getDate() a month off?

3  Asked on December 21, 2020 by aztheog

   

Using GLOB to match each character in an SQLite TEXT field

2  Asked on December 21, 2020 by anagramdatagram

   

Timeout on a function call

18  Asked on December 21, 2020 by teifion

       

How can I access a variable inside a nested array?

2  Asked on December 21, 2020 by intelltanito

   

OkHttpClient doesn’t add headers to requests

2  Asked on December 21, 2020 by ghaylen

         

Can someone teach me how to get this output

2  Asked on December 20, 2020 by surtz

 

Match multiple exact routes

3  Asked on December 20, 2020 by magofoco

   

Return a 0 if no rows are found in Microsoft SQL Server

2  Asked on December 20, 2020 by henk-hadders

     

What’s the good way to pass data to a thread in c++?

4  Asked on December 20, 2020 by ting-wang

   

Firestore query single document

2  Asked on December 20, 2020 by zvi-karp

     

Expand nested arrays postgres

1  Asked on December 20, 2020 by dan-wolchonok

         

grpc python measure response time

1  Asked on December 20, 2020 by user3599803

     

gtkmm load from resource plain text file

1  Asked on December 19, 2020 by tophyd-ayur

   

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir