visual c++ - Insertion sort not swapping -


i have implement insertion sort algorithm in x86 , code doesn't change output of array @ all. think problem lies trying swap in inner loop whenever change how array elements assigned nothing happens. no change in program outputs. why happening, , how can fix it?

my code is:

void asmsort(int *list, int arraylen, int halfpoint) {  /*  * list = address of list of integer array  * arraylen = number of element in list  list.length in java  * halfpoint  use flag  * halpfpoint = 1 when sort routine reach half point return, otherwise finished sort , return  */  /*  *  *  insertion_sort(list,arraylen,halfpoint);  return;  selection_sort(list,arraylen,halfpoint);  return;  *  *  */   // variable can declare here before _asm /* int tmp = 0; int  = 0; int  j = 0; */       _asm  {     mov ecx, arraylen     mov esi, list     mov ebx, halfpoint     mov eax, 99     push eax     push ebp      mov ebp, 4 //this     shl ecx, 2  outerloop:     cmp ebp, ecx     jg exitouter     add esi,ebp     mov edi,[esi]// temp = a[i]     mov eax, ebp //j =     sub eax, 4  // j = j-1 innerloop :     cmp eax, 0    //j>0     jle exitinner     add esi, eax // offset array a[j]     mov edx, [esi] // move a[j] edx     cmp edi, edx // temp < a[j]     jle exitinner     push eax        mov eax,[esi]     add esi,4     mov esi,edi        pop eax     sub eax,4 // j--     jmp innerloop    exitinner:     shr ecx, 1     cmp ebp, ecx     je exitouter     sub esi,ebp     add ebp, 4//i++     jmp outerloop  exitouter :     sub esi, ebp     pop ebp     pop eax       ; ....... more:   cmp ecx,0     jle done     ;.........     mov edx,arraylen     sar edx,1     cmp ecx,edx     jg  cont1     cmp halfpoint,1     je done cont1:  ;.....     ;......     ;.......     ;.....     mov [esi],eax     add esi,4     dec ecx     jmp more done: }  return;  } 

you never write memory. problem here:

mov eax,[esi] add esi,4 mov esi,edi 

you want write memory @ esi, not register esi.

mov eax,[esi] add esi,4 mov [esi],edi 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -