0

我正在尝试为我的程序集类的字符串数组执行冒泡排序操作。字符串存储在字符串指针数组中,经过多次挫折,现在可以正常工作。现在,我面临一个新问题,排序本身......

以前在我的 C++ 课上做过,但是哇,Assembly 本身就是一头野兽。我很混乱。

无论如何,这是我的代码:

.586
.MODEL FLAT

INCLUDE io.h            ; header file for input/output

.STACK 4096

.DATA
myStrings       byte    "fabc dui.",0
                byte    "abcdfe.",0
                byte    "efghi.",0
                byte    0



myStrArr        dword   20 DUP (?) ;array that will point to myStrings
strInc          dword   0       

labelPrint      byte    "The output is: ",0
stringOut       dword   ?


.CODE
_MainProc PROC

            mov     edi, offset myStrings
            mov     esi, offset myStrArr

;这个子程序将把字符串转换成双字数组

L1:

            cmp     byte ptr [edi], 0
            jz      OL
            mov     dword ptr [esi], edi
            add     esi, 4
            inc     strInc
            xor     ecx, ecx
            not     ecx
            xor     al, al
            repne   scasb
            jmp     L1

            xor     ebx, ebx

;这将在传输完成后运行

OL:

            xor     edx, edx
            mov     ebx, offset myStrArr        ;ebx -> myStrArr
            mov     esi, [ebx]                  ;esi -> [ebx] -> myStrArr[i]
            mov     edi, [ebx+4]                ;edi -> [ebx+4] -> myStrArr[i+1]    
            mov     ecx, strInc
            dec     ecx                         

                                                ;PROF'S TIP:  mov ebx, offset myStrArr
                                                ;             mov esi, [ebx]
                                                ;             mov edi, [ebx+4]

IL:
            cmp     edi, esi                    ;compares the first character of the two strings
            jbe                                 ;jumps to NC if there's no change
            mov     dl, 1                       ;set direction flags
            mov     edi, [ebx]                  ;swaps it around
            mov     esi, [ebx+4]                    


NC:

            mov     [ebx], edi                  ;point to next value
            add     esi, 4                      ;point to next value
            loop    IL
            or      dl, dl
            jnz     OL

                                                ;IN CASE OF ME GETTING SOMETHING RIGHT, ERASE COMMENTS
                                                ; mov       ebx, dword ptr [edi]
                                                ; output    labelPrint, dword ptr [ebx]


                                                ; mov       esi, dword ptr [edi]
                                                ; output  labelPrint, dword ptr [esi]
                                                ; add       esi, 4
                                                ; mov       esi, dword ptr [edi]
                                                ; output  labelPrint, dword ptr [esi]   

            mov     eax, 0                      ; exit with return code 0
            ret
_MainProc ENDP

END                                                ; end of source code

似乎我正在使用字符串指针数组进行冒泡排序,但我想我已经超出了我在这里听到的范围。非常感谢有关如何处理的一些指导!

提前感谢大家!

4

0 回答 0