c - How to fix selection Sort Swap access violation -


I am currently trying to get the assembly and I am trying to apply the basic sorting algorithm using the language I am I think I have found the logic below it, but it can also be on the error either in any case, whenever I try to run the swap part of the selection type, then with an access violation error Ends on the basis of some other questions about this subject which I have seen, the way I am implementing the swap is valid (but again, if I am wrong then correct me) In the meantime, thinking that swap is right, what is the reason for my access violation?

Here is the code:

  int _tmain (int argc, _TCHAR * argv []) {four * arr; Arr = new four [5]; Arr [0] = '2'; Arr [1] = '5'; Arr [2] = '1'; Arr [3] = '3'; Arr [4] = '4'; Int len ​​= 5; __asm ​​{Push EX Push Ebayck Push ECX Push Edx Push ESI Push EDI MAPEx, 0; // i mov ebx, 0; // j mov ecx, arr // arrange mov edx, 0; // minutes mov esi, len; // array length mov edi, len; // array LAN - 1 sub EDI, 1; Mov DL, 0; Mov DH, 0; OUTERLOOP: CMP EX, EDI; Jaege END_OUTER; Mov Ebux, Ex; Add ebay, 1; Mov edx, eax; INNERLOOP: CMP EBX, SEI; JaysEND_INNER; Mov al, bte ptr [ecx + ebx * 1]; Mov Blow, Byte PTR [ecx + edx * 1]; CPP Al, BL; JL Low; Jaeger's Greater; Less: mov edx, ebx; Inc. Abbey; JMP Inner Loop; More: Ink eBooks; JMP Inner Loop; END_INNER: cmp edx, eax; Js pass; Jane Schippe; Pass: Ink AX; JMM Orralpe; Swap: mov dh, [ecx + eax]; Mov DL, [ecx + edx]; Mov [ecx + eax], dl; Mov [ecx + edx], DH; Inc. AX; JMM Orralpe; END_OUTER: For Pop ADI Pop AC Pop ADX Pop XX Pop EBX PopEx} (Int i = 0; I & lt; len; i ++) {printf ("% c \ n", ARR [i]); } Return 0; }   

The following error messages I receive in return are:

  First chance at 0x012f1474 in Clean2.exe Exception: 0xC0000005: Access violation location read 0x004e67c8. Unwanted exception to 0x012f1474 in Clean2.exe: 0xC0000005: Access violation space arrive at 0x004e67c8.   

Any advice would be appreciated, thanks.

Edit:

I changed my code and tried to use the exchange which seemed to do the trick I consulted the answer given below and separating the register Decided that I am using for bytes. At this point I am not receiving any errors now, this is the updated code.

  int _tmain (int argc, _TCHAR * argv []) {char temp; Char * arr Arr = new four [5]; Arr [0] = '2'; Arr [1] = '5'; Arr [2] = '1'; Arr [3] = '3'; Arr [4] = '4'; Int len ​​= 5; __asm ​​(push eX push ebayck push eks push edex push esi push eDI mb ebx, arm; // arrange mov ecx, 0; // i mov edx, 0; // J mov esi, 0; // less film ADI, Lane; // Length Otherlop: Cftcx, EDI; Jaege END_OUTER; Mov edx, ecx; Add AdX, 1; Mov esi, ecx; INNERLOOP: CMP ADX, EDI; JaysEND_INNER; Mov ah, byte ptr [ebx + edx]; Mov al, bte ptr [ebx + esi]; CMP Ah, al; JL Low; Jaeger's Greater; Less: mov esi, edx; Inc. edx; JMP Inner Loop; More: inc edx; JMP Inner Loop; END_INNER: CMP ASI, ECX; Js pass; Jane Schippe; PASS: inc ecx; JMM Orralpe; Swap: Exchange al, [ebx + xxx]; Inc. Exx; JMM Orralpe; END_OUTER: For Pop ADI Pop AC Pop ADX Pop XX Pop EBX PopEx} (Int i = 0; I & lt; len; i ++) {printf ("% c \ n", ARR [i]); } Return 0; }   

But now I'm getting 1, 1, 1, 3, 4 in my array instead of 1, 2, 3, 4, 5. I will continue to try to work on it. If someone can see what is wrong, please tell me thank you.

For one thing, it seems that you use eax Register for many things Keep in mind that with the registered Al registered with the byte-size share of eax . Specifically, when you do mov al, ... , you overwrite the bottom 8 bits of the value in the eax .

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -