我需要这个数组的最大值和它的位置。我认为现在它应该显示数组的最大值,但事实并非如此。 我主要需要帮助和获得max的循环以及另一个循环,我现在还没有创建得到max的位置,最终的程序应该显示最大标记和模块的数量。
#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
答案 0 :(得分:0)
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
寄存器变得越来越小。稍后您将显示为 maximum ,实际上(如果其余代码是正确的)它将是最小。
为什么输入6个数字?
第6个输入无处可去!