内存中有10个分布在0至100内的正整数, 求小于60的数的个数num1,大于或等于60且小于80的数的个数num2,大于或等于80且小于100的数的个数num3
C语言描述该程序流程:
#include <stdio.h>
int main()
{
int a[]={1, 20, 95, 32, 60, 70, 87, 56, 93, 99};
int num1=0,num2=0,num3=0;
for(int i=0;i<10;i++)
{
if(a[i]<60)
{
num1++;
}
else if(a[i]<80)
{
num2++;
}
else
{
num3++;
}
}
printf("%d\n%d\n%d",num1,num2,num3);
}
汇编语言:
include irvine32.inc
.data
numbers dword 1, 20, 95, 32, 60, 70, 87, 56, 93, 99
num1 dword 0
num2 dword 0
num3 dword 0
count dword 10 ;需比较十次
.code
main proc
mov esi,offset numbers
L1:
cmp count,0
jz output
mov ebx,[esi]
cmp ebx,60
jl smallerthan60
cmp ebx,80
jl smallerthan80
inc num3
jmp nextnum
smallerthan60:
inc num1
jmp nextnum
smallerthan80:
inc num2
jmp nextnum
nextnum:
dec count
add esi,4
jmp L1
output:
mov eax,num1
call writeint
call crlf
mov eax,num2
call writeint
call crlf
mov eax,num3
call writeint
main endp
end main
运行结果: