【发布时间】:2016-12-07 01:48:59
【问题描述】:
我需要这个数组的最大值和它的位置。在我看来,现在它应该显示数组的最大值,但它没有。 我主要需要帮助和获取最大值的循环,而在另一个我现在尚未创建的获取最大值位置的循环中,最终程序应该显示最大值标记和模块的编号。
#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
【问题讨论】:
-
注释您的代码,尤其是如果您希望其他人提供帮助。另外,学习使用调试器,这样您就可以修复自己的错误。
-
这不是minimal reproducible example(太长了,没有清楚地描述它的作用以及它应该如何工作与它实际作用以及你在调试器中看到的内容)。见How to Ask。