最大数组为6个数字//它不显示最大值



我需要此数组的最大值,并且是位置。现在,我的意见应显示数组的最大值,但没有。我主要需要帮助和获得最大值的循环,现在我没有创建获得最大位置的另一个循环,最终程序应显示最大标记和模块的数量。

 #define _CRT_SECURE_NO_WARNINGS
 #include "stdafx.h"
 #include <stdio.h>
 #include <stdlib.h>
int main(void){
char get1[] = "Enter the mark for module 1:";
char get2[] = "Enter the mark for module 2:";
char get3[] = "Enter the mark for module 3:";
char get4[] = "Enter the mark for module 4:";
char get5[] = "Enter the mark for module 5:";
char get6[] = "Enter the mark for module 6:";
char out1[] = "Best mark is ";
char out2[] = "for module";
char format[] = "%d"; // format string for the scanf function
int x;
int myarray[5];
int max = 0;
int module = 0;// declare variables in C
_asm {
    mov ebx, 0
    mov eax, x
    mov myarray[ebx], eax
        while1:lea eax, get1; 
        push eax
        call printf
        add esp, 4
        lea eax, x; 
        push eax
        lea eax, format
        push eax
        call scanf
        add esp, 8
        mov eax, x
        cmp eax, 0
        jl while1
        mov eax, x
        cmp eax, 100
        jg while1

        mov ebx, 1
        mov eax, x
        mov myarray[ebx], eax

        while2 : lea eax, get2; 
        push eax
        call printf
        add esp, 4
        lea eax, x; 
        push eax
        lea eax, format
        push eax
        call scanf
        add esp, 8
        mov eax, x
        cmp eax, 0
        jl while2
        mov eax, x
        cmp eax, 100
        jg while2

        mov ebx, 2
        mov eax, x
        mov myarray[ebx], eax
        while3 : lea eax, get3; 
        push eax
        call printf
        add esp, 4
        lea eax, x; 
        push eax
        lea eax, format
        push eax
        call scanf
        add esp, 8
        mov eax, x
        cmp eax, 0
        jl while3
        mov eax, x
        cmp eax, 100
        jg while3

        mov ebx, 3
        mov eax, x
        mov myarray[ebx], eax
        while4 : lea eax, get4; 
        push eax
        call printf
        add esp, 4
        lea eax, x; 
        push eax
        lea eax, format
        push eax
        call scanf
        add esp, 8
        mov eax, x
        cmp eax, 0
        jl while4
        mov eax, x
        cmp eax, 100
        jg while4

        mov ebx, 4
        mov eax, x
        mov myarray[ebx], eax
        while5 : lea eax, get5; // ask for the mark
        push eax
        call printf
        add esp, 4
        lea eax, x; 
        push eax
        lea eax, format
        push eax
        call scanf
        add esp, 8
        mov eax, x
        cmp eax, 0
        jl while5
        mov eax, x
        cmp eax, 100
        jg while5

        mov ebx, 5
        mov eax, x
        mov myarray[ebx], eax
        while6 : lea eax, get6; 
        push eax
        call printf
        add esp, 4
        lea eax, x; //read it in
        push eax
        lea eax, format
        push eax
        call scanf
        add esp, 8
        mov eax, x
        cmp eax, 0
        jl while6
        mov eax, x
        cmp eax, 100
        jg while6
            MOV ebx, 0
            MOV eax, myarray[ebx]
            MOV ecx, 5
            LAB1:CMP myarray[ebx], eax
            JAE PASS
            MOV eax, myarray[ebx]
            PASS : inc ebx
            dec ecx
            cmp ecx, 0
            jg LAB1
            MOV max, eax

            push max
            lea eax, out1
            push eax
            call printf
            add esp, 8
int myarray[5];

这定义了一个包含6 dwords 的数组。
因为您似乎不了解像mov myarray[ebx], eax这样的指令确实做了什么,所以您对数组重叠的所有作业。[ebx]零件实际上是数组中的偏移。它不是像高级语言中找到的索引。然后您需要的是缩放:

mov myarray[ebx*4], eax

LAB1:CMP myarray[ebx], eax
     JAE PASS
     MOV eax, myarray[ebx]

此代码确实与您想要的相反。如果数组元素小于EAX寄存器,则将其放在EAX寄存器中。这样,EAX寄存器变得越来越小。稍后,您将显示为最大在其中实际上(如果代码的其余部分正确),则将是最小值


为什么输入6个数字?

  • 第一个数组元素由变量 x
  • 填充
  • 第二个数组元素使用第一输入
  • 填充
  • 使用第二个输入
  • 填充了第三个数组元素
  • 使用第三个输入
  • 填充第四个阵列元素
  • 使用第四个输入
  • 填充第五个数组元素
  • 使用第5个输入
  • 填充了第六个数组元素

第六输入无处可去!

最新更新