;N!_2--G6_13
;*********************************************************
datarea segment			;define data segment
	n	dw	5
	result	dw	?
datarea ends
;**********************************************************
stack_seg	segment
	dw	128 dup(0)
  tos	label   word
stack_seg	ends
;************************************************************
prognam segment			;defint code segment
;----------------------------------------------------------
main	proc	far		;main part of program

	assume cs:prognam,ds:datarea,ss:stack_seg

start:				;starting execution address
	mov	ax,stack_seg	;set up stack and SP
	mov	ss,ax
	mov	sp,offset tos
;
	push	ds		;save old data segment
	sub	ax,ax		;put zero in AX	
	push	ax		;save it on stack
;
	mov	ax,datarea	;datarea segment addr
	mov	ds,ax	  	;  into DS register
  
;MAIN PART OF PROGRAM GOES HERE
	mov	bx,n
	push	bx
	call	fact
	pop	result
	ret			;return to DOS

main	endp			;end of main part of program
;----------------------------------------------------------
fact	proc	near		;define subprocedure
	push	ax
	push	bp		
	mov	bp,sp		
	mov	ax,[bp+6]	
	cmp	ax,0		
	jne	fact1
	inc	ax
	jmp	exit
fact1:	
	dec	ax
	push	ax
	call	fact
	pop	ax
	mul	[bp+6]
exit:	mov	[bp+6],ax
	pop	bp
	pop	ax
	ret
fact    endp			;end subprocedure
;----------------------------------------------------------
prognam ends			;end of code segment
;**********************************************************

	end	start		;end assembly
