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

流程设计如下:



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 sum
INCLUDE Irvine32.inc


.code
main 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
;---------------------------------------------------
	ret
PromptForIntegers 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
;---------------------------------------------------

ret
ArraySum ENDP


;---------------------------------------------------
DisplaySum PROC
;
;Displays the sum on the scr
;Receives:	EAX=the sum
;Returns:	nothing
;Calls:		WriteString,WriteInt
;---------------------------------------------------
	ret
DisplaySum ENDP
END 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 sum
INCLUDE Irvine32.inc
INTEGER_COUNT=3

.data
str1 BYTE "Enter a signed integer:",0
str2 BYTE "The sum of the integer is:",0
array DWORD INTEGER_COUNT DUP(?)


.code
main PROC
	call Clrscr
	mov esi,OFFSET array
	mov ecx,INTEGER_COUNT
	call PromptForIntegers
	call ArraySum
	call DisplaySUm
	exit
main 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 str1
L1:	call WriteString
	call ReadInt
	call Crlf
	mov [esi],eax
	add esi,TYPE DWORD
	loop L1	
	ret
PromptForIntegers 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,0
L1:
	add eax,[esi]
	add esi,TYPE DWORD
	loop L1
	ret
ArraySum ENDP


;---------------------------------------------------
DisplaySum PROC USES edx
;
;Displays the sum on the scr
;Receives:	EAX=the sum
;Returns:	nothing
;Calls:		WriteString,WriteInt
;---------------------------------------------------
	mov edx,OFFSET str2
	call WriteString
	call WriteInt
	call Crlf
	ret
DisplaySum ENDP
END main



总结: 写个汇编真麻烦。、











评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值