C语言描述该程序流程:
#include <stdio.h> int main() { int a[]={11,33,23,54,12,51,2,4,34,45}; int max=a[0]; for(int i=1;i<=9;i++) { if(a[i]>=max) { max=a[i]; } } printf("%d",max); }
汇编语言:
include irvine32.inc .data arr dword 11,33,23,54,12,51,2,4,34,45 num dword 9 ;需对比9次 .code main proc mov esi,offset arr mov eax,[esi] ;设第一个元素为最大值 findmax: cmp num,0 jz output ;如果num为0,则输出(条件为真就跳转) mov edx,[esi+4] ;下一个数 cmp eax,edx jge nextnum ;如果该数不比eax大,就继续往下找 mov eax,edx nextnum: add esi,4 dec num jmp findmax output: call writeint main endp end main
运行结果: