Skip to content

Instantly share code, notes, and snippets.

@itsuwari
Last active November 16, 2017 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itsuwari/df2f9a8216fc4701e6197707aa76c9f7 to your computer and use it in GitHub Desktop.
Save itsuwari/df2f9a8216fc4701e6197707aa76c9f7 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment