Array sorting through x86 assembly (built-in in C ++)? Possible?

This is the first time I'm dealing with x86 assembly, and I cannot figure out how to sort an array (through insertion sort). I understand the algorithm, but the assembly is confusing to me, since I mainly use Java and C ++, Heres everything that I have so far

int ascending_sort( char arrayOfLetters[], int arraySize )
{
 char temp;

 __asm{

     push eax
     push ebx
      push ecx
     push edx
    push esi
    push edi

//// ???

    pop edi
    pop esi
       pop edx
    pop ecx
     pop ebx
    pop eax
 }
}

Basically nothing :( Any ideas ?? Thanks in advance.

Ok, it just makes me sound like a complete idiot, but I can't even change any array values ​​in _asm

To check this, I set:

mov temp, 'X'
mov al, temp
mov arrayOfLetters[0], temp

And that gave me error C2415: wrong type of operand

so i tried:

mov temp, 'X'
mov al, temp
mov BYTE PTR arrayOfLetters[0], al

This is done, but it did not change the array ...

+5
source share
1 answer

. , , . :

mov edx, 1                                  // outer loop counter

outer_loop:                                 // start of outer loop
  cmp edx, length                           // compare edx to the length of the array
  jge end_outer                             // exit the loop if edx >= length of array

  movzx eax, BYTE PTR arrayOfLetters[edx]   // get the next byte in the array
  mov ecx, edx                              // inner loop counter
  sub ecx, 1

  inner_loop:                               // start of inner loop
    cmp eax, BYTE PTR arrayOfLetters[ecx]   // compare the current byte to the next one
    jg end_inner                            // if it greater, no need to sort

    add ecx, 1                              // If it not greater, swap this byte
    movzx ebx, BYTE PTR arrayOfLetters[ecx] // with the next one in the array
    sub ecx, 1
    mov BYTE PTR arrayOfLetters[ecx], bl
    sub ecx, 1                              // loop backwards in the array
    jnz inner_loop                          // while the counter is not zero

  end_inner:                                // end of the inner loop

  add ecx, 1                                // store the current value
  mov BYTE PTR arrayOfLetters[ecx], al      // in the sorted position in the array
  add edx, 1                                // advance to the next byte in the array
  jmp outer_loop                            // loop

end_outer:                                  // end of outer loop

, DWORD (int) BYTE ().

+2

All Articles