首先输入总共的数字个数(2-5个),如果有负数就停止输入
统计正数的个数,并对正数进行排序
于是我写了一段排序。但是在统计完输入正数个数后就卡住了,不输出个排序结果,不会自动退出。
代码如下,求解,谢谢~
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
char message1[] = "Select total number of positive integers (between 2-5): ";
char message2[] = "\nEnter positive integer %d:";
char message4[] = "\nProgram terminates and has looped %d times.";
char message6[] = "Your integers from lowest to highest is ";
char message7[] = "The total amount is %d.";
char format[] = "%d"; // format string for the scanf function
char format2[] = "%d,"; // format string for the scanf function
int n;
int counter;
int counter2;
int num = 0;
int number[6];
int total;
_asm {
lea eax, message1
push eax
call printf
add esp, 4
lea eax, n
push eax
lea eax, format
push eax
call scanf_s
add esp, 8
////////总数为n///////////////
mov ecx,n
L1:
mov n,ecx
add num, 1
mov eax, num
push eax
lea eax, message2
push eax
call printf
add esp, 8
mov eax, num
//add eax
mov eax,num
lea eax, number[eax * 4]
push eax
lea eax, format
push eax
call scanf_s; reading total number
add esp, 8
mov eax,num
cmp number[eax*4],0
jle negative
mov ecx,n
loop L1
jmp valid
/////////////////////////////////////////////
negative:
sub num,1
valid:
mov eax, num
push eax
lea eax, message4
push eax
call printf
add esp,8
jmp sort
////////////排序开始
sort:
mov ecx,1
outer:
mov ecx,num
inner:
mov ecx,num
mov counter,ecx
mov eax,counter
mov ebx,number[eax*4]
sub counter,1
mov eax, counter
cmp ebx,number[eax*4]
jle unchange
mov eax, counter
xchg ebx, number[eax*4]
add counter,1
mov eax, counter
mov number[eax*4],ebx
unchange:
sub counter,1
mov ecx,counter
loop inner
sub num,1
mov ecx,num
loop outer
////////////排序结束,输出开始,但是没有开始
lea eax, message6
push eax
call printf
add esp, 4
mov ecx,counter
L4:
mov counter, ecx
mov eax, num
push eax
lea eax, format2
push eax
call printf
add esp, 8
mov ecx,counter
loop L4
}
return 0;
}
运行结果如图
统计正数的个数,并对正数进行排序
于是我写了一段排序。但是在统计完输入正数个数后就卡住了,不输出个排序结果,不会自动退出。
代码如下,求解,谢谢~
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
char message1[] = "Select total number of positive integers (between 2-5): ";
char message2[] = "\nEnter positive integer %d:";
char message4[] = "\nProgram terminates and has looped %d times.";
char message6[] = "Your integers from lowest to highest is ";
char message7[] = "The total amount is %d.";
char format[] = "%d"; // format string for the scanf function
char format2[] = "%d,"; // format string for the scanf function
int n;
int counter;
int counter2;
int num = 0;
int number[6];
int total;
_asm {
lea eax, message1
push eax
call printf
add esp, 4
lea eax, n
push eax
lea eax, format
push eax
call scanf_s
add esp, 8
////////总数为n///////////////
mov ecx,n
L1:
mov n,ecx
add num, 1
mov eax, num
push eax
lea eax, message2
push eax
call printf
add esp, 8
mov eax, num
//add eax
mov eax,num
lea eax, number[eax * 4]
push eax
lea eax, format
push eax
call scanf_s; reading total number
add esp, 8
mov eax,num
cmp number[eax*4],0
jle negative
mov ecx,n
loop L1
jmp valid
/////////////////////////////////////////////
negative:
sub num,1
valid:
mov eax, num
push eax
lea eax, message4
push eax
call printf
add esp,8
jmp sort
////////////排序开始
sort:
mov ecx,1
outer:
mov ecx,num
inner:
mov ecx,num
mov counter,ecx
mov eax,counter
mov ebx,number[eax*4]
sub counter,1
mov eax, counter
cmp ebx,number[eax*4]
jle unchange
mov eax, counter
xchg ebx, number[eax*4]
add counter,1
mov eax, counter
mov number[eax*4],ebx
unchange:
sub counter,1
mov ecx,counter
loop inner
sub num,1
mov ecx,num
loop outer
////////////排序结束,输出开始,但是没有开始
lea eax, message6
push eax
call printf
add esp, 4
mov ecx,counter
L4:
mov counter, ecx
mov eax, num
push eax
lea eax, format2
push eax
call printf
add esp, 8
mov ecx,counter
loop L4
}
return 0;
}
运行结果如图