;PROADD_4--g6_8
;**********************************************************
parm_seg        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	128 dup(?)
  tos	label 	word
stack_seg	ends
;*************************************************************
code1	 segment		
;---------------------------------------------------------
main    proc	far
	assume	cs:code1,ds:parm_seg,ss:stack_seg
				
start:				;starting execution address

	mov	ax,stack_seg
	mov	ss,ax		
	mov	sp,offset tos	
;
	push	ds		
	sub	ax,ax
	push	ax
;
	mov	ax,parm_seg
	mov	ds,ax		
;
	mov	bx,offset ary
	push	bx		;push addr of ary onto stack
	mov	bx,offset count	
	push	bx		;push addr of count onto stack
	mov	bx,offset sum	
	push	bx		;push addr of sum onto stack
	call	far ptr proadd
	ret
main	endp
;---------------------------------------------------------
code1	ends		
;**********************************************************
code2	segment

	assume  cs:code2

	  stack_strc	struc
	    save_bp	dw	?
	    save_cs_ip	dw	2 dup(?)
	    par3_addr	dw	?
	    par2_addr	dw	?
	    par1_addr	dw	?
	  stack_strc	ends
;----------------------------------------------------------
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].par1_addr;get addr of par1 from stack
	mov	di,[bp].par2_addr;get value of par2
	mov	cx,[di]		;   and put in CX 
	mov	di,[bp].par3_addr;get addr of par3 from stack
	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
