Spagett912 0 Light Poster

TITLE Integer Summation Program (Sum4.asm)

; This program we had begun to modify to allow
; for "PromptForIntegers" to use parameter passing
; rather than using globals

INCLUDE \Irvine\Irvine32.inc

INTEGER_COUNT = 3

.data
str1  BYTE  "Enter a signed integer: ",0
str2  BYTE  "The sum of the integers is: ",0
array DWORD  INTEGER_COUNT DUP(?)

.code 
main PROC
	call	Clrscr

	;We want to emulate how a high level language
   ; handles parameter passing. Conceptually, let's
   ; consider the following prototype:
   ;PromptForInteger(&ArrayParam, Size-of-Array)
   ;The next 3 lines are the equivalent
    
   push  OFFSET array ; this "&ArrayParam" being passed
   push  INTEGER_COUNT
	call	PromptForIntegers


	mov	esi,OFFSET array
   mov	ecx,INTEGER_COUNT
   
	call	ArraySum
	call	DisplaySum

   ;call  Largest
         ;The largest value is ###
   ;call WriteInt
   ;call  GrandProduct
         ;The product of all values in the array 
         ;is ###
   ;call WriteInt
      
	exit
main ENDP

;-----------------------------------------------------
PromptForIntegers PROC 
;
; Prompts the user for an arbitrary number of integers 
; and inserts the integers into an array.
; Receives: ESI points to the array, ECX = array size
; Returns:  nothing
;-----------------------------------------------------
	mov	edx,OFFSET str1	; "Enter a signed integer"
	
L1:	call	WriteString		; display string
	call	ReadInt			; read integer into EAX
	call	Crlf				; go to next output line
	mov	[esi],eax			; store in array
	add	esi,TYPE DWORD		; next integer
	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 = number 
;   of array elements
; Returns:  EAX = sum of the array elements
;-----------------------------------------------------
	mov	eax,0		; set the sum to zero
L1:	add	eax,[esi]		; add each integer to sum
	add	esi,TYPE DWORD	; point to next integer
	loop	L1			; repeat for array size
	ret				; sum is in EAX
ArraySum ENDP

;-----------------------------------------------------
DisplaySum PROC USES edx
;
; Displays the sum on the screen
; Receives: EAX = the sum
; Returns:  nothing
;-----------------------------------------------------
	mov	edx,OFFSET str2	; "The sum of the..."
	call	WriteString
	call	WriteInt			; display EAX
	call	Crlf
	ret
DisplaySum ENDP
 

END main

This is what i need to do...

Convert Each of the Original Functions “PromptForIntegers” and “ArraySum” into parameterized versions. Pass parameters by using the stack. All registers have to be properly reserved and restored. The “USES” clause shouldn't be used for functions that use parameters. This is because the “USES” clause makes implicit use of the stack.

Let them have the following Prototype (conceptually speaking):

Void PromptForInteger(&ArrayParam, Size-of-Array) ß-(Note: “&” means “the address of”)

int ArraySum(&ArrayParam, Size-of-Array) ß-(Note: “&” means “the address of”)

When a function returns a value it is understood to be returned via register “AX.”

Convert the two functions (Largest and Grand Product) into parameterized versions.

Int Largest(&ArrayParam, int Size-of-Array) ß-(Note: “&” means “the address of”)

Int GrandProduct(&ArrayParam, int Size-of-Array) ß-(Note: “&” means “the address of”)


Whoever helps thanks a lot!