找到N元素的最低子阵列,并在阵列的其余部分中最大

发布于 2025-02-06 15:18:37 字数 2306 浏览 3 评论 0原文

因此,我是一个新手,我一直在尝试用汇编语言编写一个程序,该程序可以计算上述最小值和最大值。数组是作为表示数字的一行输入,而停止代码为Digit Zero的ASCII字符。我也在使用80386 Intel CPU。因此,例如,如果我要输入数组,如以下“ 3 5 2 6 9 4 0”,而n的值是...假设4,则程序应在数组中显示前4个元素的最小值(第一个subarre) ,应该是2和剩下的东西(第二个子阵列),那是9。为此提供的帮助很小的价格……但是,是的……对大学生不要期望太多)。

这是测试的照片: https://i.sstatic.net/wklfy.png

    .data?
            n db ?
            digit db ?
            minimum db ?
            maximum db ?
            empty dw ?

.data

        messagen1 db "Input untill what array element should we check the minimum of first subarray", 0
        messagen2 db "i.e. from what element should maximum value of subarray be checked: ", 0
        input db "Input elemnts(digits) of array: ", 0
        error db "Entered array is not long enough(It has less than N elements)", 0
        message1 db "Minimum of a first subarray is: ", 0
        message2 db "and maximum of second subarray is: ", 0
        new_line db 13, 10, 0

.code

start:

        mov al, '9'
        mov bl, '0'

        invoke StdOut, addr messagen1
        invoke StdOut, addr new_line
        invoke StdOut, addr messagen2
        invoke StdIn, addr n, 1
        invoke StdIn, addr empty, 2

        invoke StdOut, addr input

looping:

        invoke StdIn, addr digit, 1
        invoke StdIn, addr empty, 2

        cmp digit, '0'
        je end

        inc bl
        cmp bl, n
        jl lesser
        jg greater
        
        cmp al, digit
        jge exchanging
        mov al, digit
 
    exchanging:

        mov minimum, al
        mov al, '0'
        jmp looping
        
    lesser:
    
        cmp al, digit
        jge looping
        mov al, digit
        jmp looping
        
    greater:

        cmp al, digit
        jle looping
        mov al, digit
        jmp looping

end:

        cmp bl, n
        jl end1
        jge end2
         
    end1:
    
        invoke StdOut, addr error
        invoke ExitProcess, 1
        
    end2:
    
        invoke StdOut, addr message1
        invoke StdOut, addr minimum 
        mov maximum, al
        invoke StdOut, addr new_line
        invoke StdOut, addr message2
        invoke StdOut, addr maximum
        invoke ExitProcess, 0
        
end start

So, I am a newbie and I have been trying to write a program in Assembly language that calculates minimum and maximum as mentioned above. Array is input as a row of characters that represent digits and stop code is ascii character of digit zero. I am also working on 80386 Intel CPU. So, for example, if I were to input array as following "3 5 2 6 9 4 0", and the value of N is... let's say 4, program should display minimum of first 4 elements in array (first subarray), which should be 2 and maxiumum of what is left from it (second subarray), which is 9. Now, for some reason, I got incorrect values, so if anyone can proanalyze code, I would be very, very grateful (which is small price to pay for such a help... but yeah... don't expect much from college student).

Here is the photo of the testing: https://i.sstatic.net/wkLFY.png

    .data?
            n db ?
            digit db ?
            minimum db ?
            maximum db ?
            empty dw ?

.data

        messagen1 db "Input untill what array element should we check the minimum of first subarray", 0
        messagen2 db "i.e. from what element should maximum value of subarray be checked: ", 0
        input db "Input elemnts(digits) of array: ", 0
        error db "Entered array is not long enough(It has less than N elements)", 0
        message1 db "Minimum of a first subarray is: ", 0
        message2 db "and maximum of second subarray is: ", 0
        new_line db 13, 10, 0

.code

start:

        mov al, '9'
        mov bl, '0'

        invoke StdOut, addr messagen1
        invoke StdOut, addr new_line
        invoke StdOut, addr messagen2
        invoke StdIn, addr n, 1
        invoke StdIn, addr empty, 2

        invoke StdOut, addr input

looping:

        invoke StdIn, addr digit, 1
        invoke StdIn, addr empty, 2

        cmp digit, '0'
        je end

        inc bl
        cmp bl, n
        jl lesser
        jg greater
        
        cmp al, digit
        jge exchanging
        mov al, digit
 
    exchanging:

        mov minimum, al
        mov al, '0'
        jmp looping
        
    lesser:
    
        cmp al, digit
        jge looping
        mov al, digit
        jmp looping
        
    greater:

        cmp al, digit
        jle looping
        mov al, digit
        jmp looping

end:

        cmp bl, n
        jl end1
        jge end2
         
    end1:
    
        invoke StdOut, addr error
        invoke ExitProcess, 1
        
    end2:
    
        invoke StdOut, addr message1
        invoke StdOut, addr minimum 
        mov maximum, al
        invoke StdOut, addr new_line
        invoke StdOut, addr message2
        invoke StdOut, addr maximum
        invoke ExitProcess, 0
        
end start

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文