TITLE Program Template (template.asm) ; Author: Roger ; Assignment Number: demo Due Date: ; Description: This program gets two integers, and calculate the ; summation from the lower to the upper. ; All variables are global ... no parameter passing ; no data validation INCLUDE Irvine32.inc ; (insert constant definitions here) .data rule1 BYTE "Enter a lower and upper limit, and I'll show: ",0 rule2 BYTE "the summation of ints from lower to upper.", 0 a DWORD ? ;lower b DWORD ? ;upper sum DWORD ? ;sum of lower + lower +1 .... upper out1 BYTE "The summation from ",0 out2 BYTE " to ", 0 out3 BYTE " is: ", 0 prompt1 BYTE "Enter a lower limit: ", 0 prompt2 BYTE "Enter a upper limit: ", 0 ; (insert variable definitions here) .code main PROC call intro call getData call calculate call showResults exit ; exit to operating system main ENDP ; Procedure to introduce the program. ; receives: none ; returns: none ; preconditions: none ; registers changed: edx intro PROC mov edx, OFFSET rule1 call WriteString call Crlf mov edx, OFFSET rule2 call WriteString call Crlf call Crlf ret intro ENDP ;Procedure to get values for a and b from the user. ;receives: none ;returns: store user inputs (low & upper) into globals (a & b) ;preconditions: none ;registers changed: edx, eax getData PROC mov edx, OFFSET prompt1 call WriteString call ReadInt mov a, eax mov edx, OFFSET prompt2 call WriteString call ReadInt mov b, eax ret getData ENDP ; Procedure to calculate the summation of integers from a to b. ; receives: a, b, sum, globals ; returns: global sum = a + a+1 + a+2 .... + b ; preconditions: a <= b ; registers changed : eax, ebx, ecx calculate PROC mov eax, 0 ;accum mov ebx, a ;iterations: ecx = b-a+1 mov ecx, b sub ecx, a inc ecx top: add eax, ebx inc ebx loop top mov sum, eax ret calculate ENDP ; Procedure to display the results(a, b, and sum) ; receives: none, a, b, sum are globals ; returns: none ; preconditions: sum has been calculated ; registers changed : eax, edx showResults PROC mov edx, OFFSET out1 call WriteString mov eax, a call WriteDec mov edx, OFFSET out2 call WriteString mov eax, b call WriteDec mov edx, OFFSET out3 call WriteString mov eax, sum call WriteDec call Crlf ret showResults ENDP END main