Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 32位程序集-插入排序无法正常工作_Arrays_Sorting_Assembly_Insertion Sort - Fatal编程技术网

Arrays 32位程序集-插入排序无法正常工作

Arrays 32位程序集-插入排序无法正常工作,arrays,sorting,assembly,insertion-sort,Arrays,Sorting,Assembly,Insertion Sort,我在这里的任务是添加一个代码,用插入排序对数组进行排序。 “printf”函数打印字符串 printArray打印数组 由于某种原因,数组没有被排序,我找不到原因。 我们将不胜感激 main: push MSG ; print welcome message call printf add esp,4 ; clean the stack call printArray ;print the unsorted array

我在这里的任务是添加一个代码,用插入排序对数组进行排序。 “printf”函数打印字符串 printArray打印数组

由于某种原因,数组没有被排序,我找不到原因。 我们将不胜感激

main:
        push MSG    ; print welcome message
        call printf
        add esp,4   ; clean the stack 

        call printArray ;print the unsorted array

        ;;;;;;;;;;add code here;;;;;;;;;;

        mov eax,1
loop1:
        mov ebx, array
        add ebx, eax

loop2:
        mov esi, ebx
        dec esi
        mov esi, [esi]      ;esi holds the value before what ebx points to
        cmp [ebx], esi
        ja endLoop2

        mov edx, esi
        mov esi, ebx
        dec esi
        mov ecx, [ebx]
        mov [esi], ecx
        mov [ebx], edx
        dec ebx
        cmp ebx, array
        ja loop2

endLoop2:
        inc eax
        cmp eax, 11
        jbe loop1

        ;;;;;;;end of your code;;;;;;;;;;;;;;

        call printArray

        mov eax, 1  ;exit system call
        int 0x80

如果您的数组中满是1字节的值,请在加载和存储到内存时使用movb而不是mov。

将所有INC和DEC更改为add/sub 4,现在似乎根本不在循环后打印数组。也许它改变了阵列的地址?!对我来说没有意义。你觉得这里还有什么不对劲吗?是我干的,把事情搞砸了。另外,你的评论是错误的,因为数组是DB,而不是int。对不起,我想我误解了这个问题。我根据你的新信息编辑了我的答案。