Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6674427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:44:37+00:00 2026-05-26T03:44:37+00:00

I have a dword array of 15 random integers that is stored in esi.

  • 0

I have a dword array of 15 random integers that is stored in esi. I have a bubble sort algorithm below which is supposed to arrange the values from lowest to highest. However when my program runs through this algorithm it doe not seem to touch any of the values and when I print the array it is exactly as it was before. Thoughts?

BubbleSort PROC USES eax ebx ecx edx esi

    mov ecx, 0 
    mov ecx, 15

    OUTER_LOOP: 
        push ecx
        mov ecx,0
        mov ecx,14
        mov esi, OFFSET arr

        COMPARE:
            mov ebx,0
            mov edx,0
            mov bl, [esi]
            mov dl, [esi+1]
            cmp bl,dl
            jg SWAP 

            CONTINUE:      
                add esi,4      
                loop COMPARE

        mov esi, OFFSET arr

        pop ecx     
        loop OUTER_LOOP

    jmp FINISHED

    SWAP:
        mov bl, [esi]
        mov dl, [esi+1]
        xchg bl,dl 
        mov [esi],dl 
        mov [esi+1],bl
        jmp CONTINUE 

    FINISHED:
    ret

BubbleSort ENDP

Thanks for your help in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T03:44:38+00:00Added an answer on May 26, 2026 at 3:44 am

    EDIT:

    I found different problems in your code. I’ve fixed them below and ESI is actually changed (not sorted because I think the sorting algorithm is wrong but didn’t have time yet to change it)

    1- mov reg,0

    It’s better to xor the register instead of moving 0 to it. XOR instruction is shorter.

    2- In the CONTINUE loop I use add esi,2 (maybe you’re on 64bit windows?)

    3- In the SWAP loop, the first 2 mov instructions are useless. I removed them.

    4- In the SWAP loop, you need to swap the lines where you put the values back in esi and esi+1 (actually you don’t even need the xchg instruction.)

    Now ESI is changed. You need to work on the sorting algorithm.

    BubbleSort PROC uses ECX
        xor ecx,ecx 
        mov ecx, 15
    
        OUTER_LOOP: 
            push ecx
            xor ecx,ecx
            mov ecx,14
            mov esi, OFFSET arr
    
            COMPARE:
                xor ebx,ebx
                xor edx,edx
                mov bl, byte ptr ds:[esi]
                mov dl, byte ptr ds:[esi+1]
                cmp bl,dl
                jg SWAP 
    
                CONTINUE:      
                    add esi,2      
                    loop COMPARE
    
            mov esi, OFFSET arr
    
            pop ecx     
            loop OUTER_LOOP
    
        jmp FINISHED
    
        SWAP:
            xchg bl,dl 
            mov byte ptr ds:[esi+1],dl 
            mov byte ptr ds:[esi],bl
            jmp CONTINUE 
    
        FINISHED:
        ret
    BubbleSort ENDP
    

    EDIT:
    In the outer loop you have 2 mov esi, OFFSET arr

    and the second one happens just before exiting. So you’re basically putting the array offset back in ESI like it was at the start.

    The USES ESI note below holds. You need to remove it.

    Also what is ECX used for in this procedure? It’s never used but you’re assigning values, pushig and poping them?


    USES eax ebx ecx edx esi

    This masm helper pushes ESI on the stack.

    When you exit the procedure it pops it out as it was before.

    So you probably don’t want to include ESI up there.

    Note, you also want to put your DWORD in another register like EAX. There are some case when entering a procedure ESI and the likes are pushed anyway.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example,We have a DWORD = $12345678 Which of the instructions would be faster
i have bit of code that causes an underflow: var t1, t2, delta: DWORD:
I have a DLL that I need to P/Invoke the following method: DWORD Foo(
I have the code below which now shows a standard windows help popup where
I have an array that I am attempting to print. I would like to
I have a four byte DWORD that I need to split into four different
I have a very simple queue implementation that wraps a fixed array. It contains
I am using the following ASM routine to bubble sort an array. I want
I am trying to acces values from an array of integers and have been
I have a struct I have written which is supposed to represent an entire

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.