Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.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
Sorting 查找列表中的最小数_Sorting_Assembly_X86_Masm_Irvine32 - Fatal编程技术网

Sorting 查找列表中的最小数

Sorting 查找列表中的最小数,sorting,assembly,x86,masm,irvine32,Sorting,Assembly,X86,Masm,Irvine32,我在这段代码中的目标是找到列表中的最小数字。在这种情况下,我使用了冒泡排序法;不幸的是,代码没有给出最小/最小的数字。请看一看,谢谢: include irvine32.inc .data input byte 100 dup(0) stringinput byte "Enter any string: ",0 totallength by

我在这段代码中的目标是找到列表中的最小数字。在这种情况下,我使用了冒泡排序法;不幸的是,代码没有给出最小/最小的数字。请看一看,谢谢:

include irvine32.inc

.data
input               byte        100 dup(0)                         
stringinput         byte        "Enter any string: ",0         
totallength         byte        "The total length is: ",0   
minimum             byte        "The minimum value is: ",0
.code 


stringLength        proc
                    push        ebp
                    mov         ebp, esp
                    push        ebx
                    push        ecx
                    mov         eax, 0
                    mov         ebx, [ebp+8]
L1:
                    mov         ecx, [ebx] ;you can use ecx, cx, ch, cl 
                    cmp         ecx, 0     ;you can use ecx, cx, ch, cl 
                    JE          L2
                    add         ebx, 1
                    add         eax, 1
                    jmp         L1
L2:
                    pop         ecx
                    pop         ebx
                    mov         ebp, esp
                    pop         ebp
                    ret         4

stringLength        endp



BubbleSort PROC uses ECX
    push edx 
    xor ecx,ecx 
    mov ecx, 50

    OUTER_LOOP: 
        push ecx
        xor ecx,ecx
        mov ecx,14
        mov esi, OFFSET input

        COMPARE:
            xor ebx,ebx
            xor edx,edx
            mov bl, byte ptr ds:[esi]
            mov dl, byte ptr ds:[esi+1]
            cmp bl,dl
            jg SWAP1 

            CONTINUE:      
                add esi,2      
                loop COMPARE

        mov esi, OFFSET input

        pop ecx     
        loop OUTER_LOOP

    jmp FINISHED

    SWAP1:
        xchg bl,dl 
        mov byte ptr ds:[esi+1],dl 
        mov byte ptr ds:[esi],bl
        jmp CONTINUE 

    FINISHED:



    pop edx 

    ret 4
BubbleSort ENDP




main proc

                    call        clrscr              
                    mov         edx, offset stringinput     
                    call        writeString
                    mov         edx, offset input 
                    call        writeString      
                    call        stringLength
                    mov         edx, offset input 
                    mov         ecx, sizeof input 
                    call        readstring        
                    call        crlf
                    mov         edx,offset totallength
                    call        writestring
                    call        writedec    
                    call        crlf
                    mov         edx, offset minimum
                    call        crlf
                    call        writeString
                    push        offset input
                    call        BubbleSort
                    mov         edx, offset input 
                    call        writeString     
                    call        crlf

                    exit 
main                endp


                    end         main

我还没有看过你的代码,因为排序对于你想要做的事情来说是一种过于复杂的方法。不仅如此,我们大多数人都不太注意未注释的代码。只是需要很长时间才能弄清楚你想做什么

简单地遍历整个列表,并以255(FFH)开始。每次您遇到一个小于AL中的数字,然后用该值替换它,当循环完成时,AL将具有最低的值

如果您需要知道它在列表中的位置,您可以使用AH,这将是起始地址和当前地址之间的差异。指令集的知识是必不可少的,因为查找字符串的长度可以通过以下方式简化:

mov     di, input                ; Point to beginning of buffer
mov     cx, -1                   ; for a maximum of 65535 characters
xor     al,  al                  ; Looking for NULL
rep     scasb
neg     cx
dec     cx                       ; CX = length of string.

请记住,ES需要指向@DATA

使用“开始”的固定值不是一个好主意,使用尽可能高的值是不安全的(例如,您更改了数组的值范围,但忘记了调整它)。更好的方法是:使用第一个数字作为最低值,然后开始与#2进行比较