www.pudn.com > sdk_host_2520.rar > memfns.inc


;;************************************************************************ 
;SigmaTel, Inc 
;$Archive: $ 
;$Revision:  $ 
;$Date: 20th Dec 2000 
;Description:  File header 
;Notes:	Memory functions memcpy,memset		 
;************************************************************************* 
;MACROS FOR MEMCPY 
;************************************************************************* 
;MACRO memcpy_non0 
;description	implementing the memcpy(*src.*dest,size) 
;This macro is to be used when the number of words to be copied is a constant  
;or when the count register is known to be non zero.Use the macro memcpy when you  
;are not sure whether the register containing the count is zero. 
;parameters to be passed 
;		srcptr		:source pointer  
;		desptr		:destination pointer 
;		size		:no of words to be copied in register or as immediate value 
;		memspacesrc	:memoryspace of source buffer 
;		memspacedes	:memoryspace of destination buffer 
;------------------------------------------------------------------------- 
;USAGE: 
;Source pointer in r0 (pointing to X memory), Destination pointer in r2 (pointing to Y memory) 
;Number of words to be copied- size 
;Call the macro as  
;	memcpy_non0 r0,r2,#>size,x,y 
;------------------------------------------------------------------------- 
memcpy_non0 	MACRO	desptr,srcptr,size,memspacesrc,memspacedes 
		do size,_memcpy_non0 
		move memspacesrc:(srcptr)+,x0 
		move x0,memspacedes:(desptr)+   
_memcpy_non0	nop 
	ENDM 
 
;************************************************************************* 
;MACRO memcpy 
;description	implementing the memcpy(*src.*dest,size) 
;This macro is to be used when the number of words to be copied is in a register. 
;Use this macro when you are not sure whether the count register can take a value 0. 
;This macro will trash the Accumulator acc specified as argument. 
;parameters to be passed 
;		srcptr		:source pointer  
;		desptr		:destination pointer 
;		size		:no of words to be copied is expected in register 
;		memspacesrc	:memoryspace of source buffer 
;		memspacedes	:memoryspace of destination buffer 
;		acc		:specify the accumulator register that can be trashed 
;------------------------------------------------------------------------- 
;USAGE: 
;Source pointer in r0 (pointing to X memory), Destination pointer in r2 (pointing to Y memory) 
;To copy the number of words contained in x0 
;Call the macro as  
;	memcpy r0,r2,x0,x,y,acc 
;------------------------------------------------------------------------- 
memcpy	 	MACRO	desptr,srcptr,size,memspacesrc,memspacedes,acc 
		clr acc  
		move size,acc 
		tst acc 
		jle _memcpy		 
		do size,_memcpy 
		move memspacesrc:(srcptr)+,x0 
		move x0,memspacedes:(desptr)+   
_memcpy		nop 
	ENDM 
 
;************************************************************************* 
;MACRO memset 
 
;************************************************************************* 
;MACRO	memset_non0 
;description	implementing the memset(*src.*dest,size) 
;This macro is to be used when the number of words to be set is a constant. 
;parameters to be passed 
;		desptr		:destination pointer 
;		size		:no of words to be copied in register or as immediate value 
;		value		:register containing the value to be set 
;		memspacedes	:memoryspace of destination buffer 
;------------------------------------------------------------------------- 
;USAGE: 
;Source pointer in r0 (pointing to X memory) 
;To set the number of words contained in x0 to the value in n0 
;Call the macro as  
;	memset_non0 r0,#>size,n0,x 
;------------------------------------------------------------------------- 
memset_non0 	MACRO	desptr,value,size_str,memspacedes 
		do size_str,_RepLoopA 
			move value,memspacedes:(desptr)+   
			nop 
_RepLoopA 
		ENDM 
;************************************************************************* 
;MACRO	memset 
;description	implementing the memset(*src.*dest,size) 
;This macro is to be used when the number of words to be set is available in a register. 
;This macro will trash the Accumulator acc specified as argument. 
;parameters to be passed 
;		desptr		:destination pointer 
;		size		:register containing the no of words to be copied 
;		value		:register containing the value to be set 
;		memspacedes	:memoryspace of destination buffer 
;		acc		:specify the accumulator register that can be trashed 
;------------------------------------------------------------------------- 
;USAGE: 
;Source pointer in r0 (pointing to X memory) 
;To set size number of words contained to the value in n0 
;Call the macro as  
;	memset r0,size,n0,x,acc 
;------------------------------------------------------------------------- 
memset	 	MACRO	desptr,value,size,memspacedes,acc 
		clr acc  
		move size,acc 
		tst acc  
		jle _memset		 
		do size,_memset 
			move value,memspacedes:(desptr)+   
			nop 
_memset 	nop 
		ENDM 
;************************************************************************* 
 
;************************************************************************* 
;MACRO memove 
;description     implementing memove(*dest,*src,count ); 
;parameters to be passed 
;		 srcptr         ;source pointer 
;		 count	        ;count of words to be moved 
;		 desptr         ;destination pointer 
;		 arg1           ;specify value of n used as offset to srcptr  
;                arg2		;specify value of n used as offset to desptr 
 
 
MEMOVE MACRO srcptr,desptr,count,arg1,arg2 
	; pass src as arg1 and dest as arg2 
	move srcptr,b  
	move desptr,a 
	cmp b,a   ; compare src pointer and dest pointer 
	jlt _continue 
	move count,n\arg1 
	move n\arg1,n\arg2 
	lua (srcptr)+n\arg1,srcptr 
	lua (desptr)+n\arg2,desptr 
	do n\arg1,_memloop 
	move x:(srcptr)-,x0 
	move x0,x:(desptr)- 
_memloop 
	jmp _end 
_continue 
	do n\arg1,_loop 
	move x:(srcptr)+,x0 
	move x0,x:(desptr)+ 
_loop 
_end   	nop	 
        ENDM