;PROADD_3--G6_5
;**********************************************************
parm_seg        segment		;define data segment
	ary	dw	1,2,3,4,5,6,7,8,9,10
	count	dw	10
	sum	dw	?
parm_seg        ends
;**********************************************************
stack_seg	segment
	dw	100 dup(?)
  tos	label  word
stack_seg	ends
;***********************************************************
code1   segment			;defint code segment
;----------------------------------------------------------
main	proc	far		;main part of program
				
	assume cs:code1,ds:parm_seg,ss:stack_seg

start:				;starting execution address

;set up SS and SP register    
	mov	ax,stack_seg
	mov	ss,ax		
	mov	sp,offset tos

;set up stack for return
	push	ds		;save old data segment
	sub	ax,ax		;put zero in AX	
	push	ax		;save it on stack

;set DS register to current data segment
	mov	ax,parm_seg     ;data segment addr
	mov	ds,ax	  	;  into DS register

;
	mov	bx,offset ary	;push addr of ary	
	push	bx		;  onto stack
	mov	bx,offset count	;push addr of count
	push 	bx		;  onto stack
	mov	bx,offset sum	;push addr of sum
	push	bx		;  onto stack
	call	far ptr proadd
	ret
main 	endp
;------------------------------------------------------------
code1	ends
;************************************************************
code2	segment
       
        assume	cs:code2

;------------------------------------------------------------ 
proadd	proc    far
	push	bp		;save BP
	mov	bp,sp		;use BP to access parameter
	push	ax		;save other registers
	push	cx
	push	si
	push	di
	mov	si,[bp+0ah]	;get addr of ary
	mov	di,[bp+8]	;get addr of count
	mov	cx,[di]		; CX <-- (count) 
	mov	di,[bp+6]	;get addr of sum
	xor	ax,ax		;clear AX
next:	add	ax,[si]		;compute sum
	add	si,2
	loop	next
	mov	[di],ax		;store result
	pop	di		;restore registers
	pop	si
	pop	cx
	pop	ax
	pop	bp
	ret	6		;adjust stack and return

proadd	endp
;------------------------------------------------------------
code2	ends
;************************************************************

	end	start		;end assembly
