TITLE Demonstrating Procedures (ArraySum.asm) .686 .MODEL flat, stdcall .STACK 4096 INCLUDE Irvine32.inc .data MAXSIZE EQU 10 array DWORD MAXSIZE DUP(?) count DWORD ? ; Add more data if needed .code main PROC push OFFSET count push OFFSET array call ReadIntArray push count push OFFSET array call ArraySum ; Add more instructions to display the final sum exit main ENDP ; Read 32-bit integers, count them, and store them in an array ; This procedure should prompt to the user to enter a list of signed integers ; One signed integer should be input per line ; Reading continues until 0 is read as input, or until MAXSIZE inputs are read ; Receives: array address (on the stack) ; count address (on the stack) ; Returns: Use the array address to store indirectly the input integers ; Use the count address to store indirectly the count ReadIntArray PROC ; to be completed ReadIntArray ENDP ; Calculate and return the sum of an array of 32-bit integers ; Receives: array address (on the stack) ; count of array elements (on the stack) ; Returns: EAX = sum of the array elements ArraySum PROC push ebp ; save old value of EBP mov ebp, esp ; new value of EBP push esi ; save old value of ESI push ecx ; save old value of ECX mov esi, [ebp+8] ; ESI = array address mov ecx, [ebp+12] ; ECX = number of array elements mov eax, 0 ; set the sum to 0 jecxz L2 L1: add eax, [esi] ; add each element to sum add esi, 4 ; point to next array element loop L1 L2: pop ecx ; restore value of ECX pop esi ; restore value of ESI pop ebp ret 8 ; sum is in EAX ArraySum ENDP END main