流程设计如下:
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
总结: 写个汇编真麻烦。、