博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

求三个数之和[汇编]

Posted on 2011-04-03 18:10  Code_HXH  阅读(334)  评论(0编辑  收藏  举报
TITLE integer summation Program
;
;
;
;
INCLUDE Irvine32.inc
INTERGER_COUNT =
3

.data
str1 byte
"enter a signe integer:",0
str2 byte
"the sum of the integers is:",0
array dword INTERGER_COUNT dup(?)


;************************************************************
;
temp: esi:数组的首地址,长度为4个字节
;
ecx:数组元素个数
;
************************************************************
.code
main PROC
call clrscr
mov esi,offset array
mov ecx,INTERGER_COUNT
call promptforintegers
call arraysum
call displaysum
exit
main ENDP

;-----------------------------------------------
;
输入数字
;
-----------------------------------------------
promptforintegers PROC USES ecx edx esi
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 edx
mov edx,0
L1:
add edx,[esi]
add esi,type dword
loop L1
mov eax,edx
ret
arraysum ENDP
;---------------------------------------------------------

;----------------------------------------------------------
;
显示和
displaysum PROC USES edx
;----------------------------------------------------------
mov edx,offset str2
call writestring
call writeint
call crlf
ret
displaysum ENDP
;----------------------------------------------------------
end main