diff options
Diffstat (limited to 'programs/sub-suite/libc.s')
| -rw-r--r-- | programs/sub-suite/libc.s | 31 | 
1 files changed, 31 insertions, 0 deletions
| diff --git a/programs/sub-suite/libc.s b/programs/sub-suite/libc.s index 18c10db..74ad654 100644 --- a/programs/sub-suite/libc.s +++ b/programs/sub-suite/libc.s @@ -508,3 +508,34 @@ free:  	plb.q		; Restore B.  	pla.q		; Restore A.  	rts		; End of free. + + +; memcpy: memory to memory copy. +; Input: A = Destination pointer. B = Source pointer. Y = Number of bytes to copy. +; Output: A = Destination pointer. +; Caller preserved registers: none. +; Callie preserved registers: none. + +memcpy: +	pha.q		; Preserve the return value. +	pha.q		; Push the destination pointer on the stack. +	phb.q		; Push the source pointer on the stack. +	phy.q		; Push the size on the stack. +	and #0		; Reset A. +	tab		; Reset B. +	cpy #0		; Is the size zero? +	beq @end	; Yes, so we're done. +@loop: +	lda (sp+9)	; Get a byte from the source. +	sta (sp+17)	; Copy it to the destination. +	inc.q sp+9	; Increment the source pointer. +	inc.q sp+17	; Increment the destination pointer. +	dey		; Decrement the size. +	beq @end	; The size is zero, so we're done. +	bra @loop	; Keep looping. +@end: +	pla.q		; Clean up the stack frame. +	pla.q		; +	pla.q		; +	pla.q		; Restore the return value. +	rts		; End of memcpy. | 
