内存中有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 numbersL1:
cmp count,0
jz output
mov ebx,[esi]
cmp ebx,60
jl smallerthan60
cmp ebx,80
jl smallerthan80
inc num3
jmp nextnumsmallerthan60:
inc num1
jmp nextnumsmallerthan80:
inc num2
jmp nextnumnextnum:
dec count
add esi,4
jmp L1output:
mov eax,num1
call writeint
call crlf
mov eax,num2
call writeint
call crlf
mov eax,num3
call writeintmain endp
end main
运行结果: