整数求和程序的流程设计和实现

来源:互联网 发布:网络写手签约哪个网站 编辑:程序博客网 时间:2024/06/09 23:02

流程设计如下:



TITLE Integer Summation Program ;This program prompts the user for three integers;stores them in an array,calculates the sum of the;array,and displays the sumINCLUDE Irvine32.inc.codemain PROC;MAIN program control procedure;Calls: Clrscr,PromptForIntergers;ArraySum,DisplaySum;---------------------------------------------------PromptForIntegers PROC;;Prompts the user for three integers,inserts them in ;an array.;Receives:ESI points to an array of DW integers,;ECX = array size;Returns:nothing;Calls:ReadInt,WriteString;---------------------------------------------------retPromptForIntegers ENDP;---------------------------------------------------ArraySum PROC;;Calculates the sum of an array of 32-bit integers.;Receives:ESI points to the array,ECX =array size;Returns:EAX = the sum of the array elements;---------------------------------------------------retArraySum ENDP;---------------------------------------------------DisplaySum PROC;;Displays the sum on the scr;Receives:EAX=the sum;Returns:nothing;Calls:WriteString,WriteInt;---------------------------------------------------retDisplaySum ENDPEND main


实现后如下:


TITLE Integer Summation Program ;This program prompts the user for three integers;stores them in an array,calculates the sum of the;array,and displays the sumINCLUDE Irvine32.incINTEGER_COUNT=3.datastr1 BYTE "Enter a signed integer:",0str2 BYTE "The sum of the integer is:",0array DWORD INTEGER_COUNT DUP(?).codemain PROCcall Clrscrmov esi,OFFSET arraymov ecx,INTEGER_COUNTcall PromptForIntegerscall ArraySumcall DisplaySUmexitmain ENDP;---------------------------------------------------PromptForIntegers PROC USES ecx edx esi;;Prompts the user for three integers,inserts them in ;an array.;Receives:ESI points to an array of DW integers,;ECX = array size;Returns:nothing;Calls:ReadInt,WriteString;---------------------------------------------------mov edx,OFFSET str1L1:call WriteStringcall ReadIntcall Crlfmov [esi],eaxadd esi,TYPE DWORDloop L1retPromptForIntegers ENDP;---------------------------------------------------ArraySum PROC USES esi ecx;;Calculates the sum of an array of 32-bit integers.;Receives:ESI points to the array,ECX =array size;Returns:EAX = the sum of the array elements;---------------------------------------------------mov eax,0L1:add eax,[esi]add esi,TYPE DWORDloop L1retArraySum ENDP;---------------------------------------------------DisplaySum PROC USES edx;;Displays the sum on the scr;Receives:EAX=the sum;Returns:nothing;Calls:WriteString,WriteInt;---------------------------------------------------mov edx,OFFSET str2call WriteStringcall WriteIntcall CrlfretDisplaySum ENDPEND main总结: 写个汇编真麻烦。、







0 0
原创粉丝点击