本文主要是介绍【汇编语言实战】求两组给定数组最大值,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
C语言描述该程序流程:
#include <stdio.h>
int main()
{int arr1[]={11,33,23,542,12233,5443,267,456,234,453};int arr2[]={21,123,432,45,234,534,6517,678,879,1};int max=arr1[0];for(int i=1;i<10;i++){if(arr1[i]>max){max=arr1[i];}}printf("%d\n",max);max=arr2[0];for(int i=1;i<10;i++){if(arr2[i]>max){max=arr2[i];}}printf("%d",max);}
汇编语言:
include irvine32.inc
.data
arr1 dword 11,33,23,542,12233,5443,267,456,234,453
arr2 dword 21,123,432,45,234,534,6517,678,879,1
num dword 9 ;需对比9次
.code
main proc
mov esi,offset arr1
mov eax,[esi] ;设第一个元素为最大值findmax1:
cmp num,0 ;如果num为0,输出并开始找第二个数组的最大值
jz func
mov edx,[esi+4]
cmp eax,edx
jge nextnum1 ;如果该数不比eax大,就继续往下找
mov eax,edxnextnum1:
add esi,4
dec num
jmp findmax1func:
call writeint
mov esi,offset arr2
mov eax,[esi]
mov num,9findmax2:
cmp num,0
jz output
mov edx,[esi+4]
cmp eax,edx
jge nextnum2
mov eax,edxnextnum2:
add esi,4
dec num
jmp findmax2output:
call writeint
main endp
end main
运行结果:
这篇关于【汇编语言实战】求两组给定数组最大值的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!