summaryrefslogblamecommitdiff
path: root/zp/source/arm/mem/memcpy.s
blob: b07c1f6c7bfe63c5e0fd005ff9d73ec078586146 (plain) (tree)

















































                                                                                                                                                                                                                                         
@ Copyright 2022-2023 Gabriel Jensen.
@ This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
@ If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.

.syntax unified

.thumb

.globl zp_memcpy

.func
.thumb_func

zp_memcpy:
	              @ zp_i02 tmp4;
	              @ zp_i8 tmp1;

.wrdcpy:          @ wrdcpy:;
	@ Check if there are at least four bytes remaining:
	cmp  r1,0x4
	blt  .bytcpy  @ if (num < 0x4u) goto bytcpy;

	@ Copy one word:
	ldm  r0!,{r3} @ tmp4 = *(zp_i02 *)in; /* We use ldm/stm with an exclamation mark after the source/destination as this version saves the incremented address into the register, meaning we don't have to icrement it ourselves. */
	stm  r2!,{r3} @ *(zp_i02 *)out = tmp4;

	@ Continue to the next word:
	subs r1,0x4   @ num -= 0x4u;
	b    .wrdcpy  @ goto wrdcpy;

.bytcpy:          @ bytcpy:;
	@ Check if we have any bytes remaining:
	cmp  r1,0x0
	beq  .done    @ if (num == 0x0u) goto done;

	@ Copy one byte:
	ldrb r3,[r0]  @ tmp1 = *(zp_i8 *)in;
	strb r3,[r2]  @ *(zp_i8 *)out = tmp1;

	@ Continue to the next byte:
	adds r0,0x1   @ ++in;
	adds r2,0x1   @ ++out;
	subs r1,0x1   @ --num;
	b    .bytcpy  @ goto bytcpy;

.done:            @ done:;
	@ Return:
	bx   lr       @ return;
	
.endfunc