汇编多整数求和

来源:互联网 发布:淘宝联盟升级高佣金 编辑:程序博客网 时间:2024/05/16 06:53

对用户输入的多个整数求和,并输出结果

TITLE Integer Summation ProgramINCLUDE Irvine32.incARRAY_SIZE = 20.data str1 BYTE "Enter a signed integer:",0 str2 BYTE "The sum of the integers is:",0 str3 BYTE "How many integers will be added? ",0 str4 BYTE "The array cannot be larger than 20",0ah,0 array DWORD ARRAY_SIZE DUP(?).code main PROCcall Clrscrmov esi,OFFSET arraymov ecx,ARRAY_SIZEcall panduan          //判断读入的整数个数是否大于20call PromptForIntegerscall ArraySumcall DisplaySumexitmain endppanduan PROC USES edx     mov  edx,OFFSET str3     call WriteString     call ReadInt     call Crlf     mov ebx,20     cmp ebx,eax     mov edi,eax     JNC L1     mov  edx,OFFSET str4     call WriteString     exitL1:  retpanduan ENDPPromptForIntegers PROC USES ecx edx esimov   edx,OFFSET str1     mov ecx,ediL1:  call WriteString     call ReadInt     call Crlf     mov  [esi],eax     add  esi,TYPE DWORD     loop L1     ret   PromptForIntegers ENDPArraySum PROC USES esi ecx     mov eax,0L1:  add eax,[esi]     add esi,TYPE DWORD     loop L1      ret ArraySum ENDPDisplaySum PROC  USES edx     mov edx,OFFSET str2     call WriteString     call WriteInt     call CrlfretDisplaySum ENDPEND main

无
无

除显示多整数的和外,还分别显示这些整数中正整数的和负整数的和

TITLE Integer Summation ProgramINCLUDE Irvine32.incARRAY_SIZE = 20.data str1 BYTE "Enter a signed integer:",0 str2 BYTE "The sum of the positive integers is:",0 str3 BYTE "How many integers will be added? ",0 str4 BYTE "The array cannot be larger than 20",0ah,0 str5 BYTE "The sum of the negative integers is:",0 array DWORD ARRAY_SIZE DUP(?).code main PROCcall Clrscrmov esi,OFFSET arraymov ecx,ARRAY_SIZEcall panduancall PromptForIntegerscall ArraySumcall DisplaySumexitmain endppanduan PROC USES edx     mov  edx,OFFSET str3     call WriteString     call ReadInt     call Crlf     mov ebx,20     cmp ebx,eax     mov edi,eax     JNC L1     mov  edx,OFFSET str4     call WriteString     exitL1:  retpanduan ENDPPromptForIntegers PROC USES ecx edx esimov   edx,OFFSET str1     mov ecx,ediL1:  call WriteString     call ReadInt     call Crlf     mov  [esi],eax     add  esi,TYPE DWORD     loop L1     ret   PromptForIntegers ENDPArraySum PROC USES esi ecx     mov eax,0     mov ebx,0     mov edx,0L1:  cmp [esi],edx     jl  L2     add eax,[esi]     jmp L3     L2: add ebx,[esi]     L3: add esi,TYPE DWORD     loop L1      ret ArraySum ENDPDisplaySum PROC  USES edx     mov edx,OFFSET str2     call WriteString     call WriteInt     call Crlf     mov edx,OFFSET str5     mov eax,ebx     call writestring     call writeint     call CrlfretDisplaySum ENDPEND main

  • 通用寄存器eax, ebx, ecx, edx, esi, edi, ebp, esp

关于通用寄存器的相关解释

0 0