1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-30 01:29:37 +00:00
cc65/libsrc/common/memset.s
uz 53dd513176 This commit was generated by cvs2svn to compensate for changes in r2,
which included commits to RCS files with non-trunk default branches.


git-svn-id: svn://svn.cc65.org/cc65/trunk@3 b7a2c559-68d2-44c3-8de9-860c34a00d81
2000-05-28 13:40:48 +00:00

53 lines
942 B
ArmAsm

;
; void* memset (void* ptr, int c, size_t n);
;
; Ullrich von Bassewitz, 29.05.1998
;
.export _memset
.import popax
.importzp ptr1, ptr2, tmp1, tmp2, tmp3
_memset:
sta tmp1 ; Save n
stx tmp2
jsr popax ; Get c
sta tmp3 ; Save c
jsr popax ; Get ptr
sta ptr1
stx ptr1+1 ; Save work copy
sta ptr2
stx ptr2+1 ; Save a copy for the function result
lda tmp3
ldy #0
ldx tmp2 ; Get high byte of n
beq L2 ; Jump if zero
; Set 256 byte blocks
L1: sta (ptr1),y ; Set one byte
iny
sta (ptr1),y ; Unroll this a bit to make it faster
iny
bne L1
inc ptr1+1
dex ; Next 256 byte block
bne L1 ; Repeat if any
; Set the remaining bytes if any
L2: ldx tmp1 ; Get the low byte of n
beq L9 ; Low byte is zero
L3: sta (ptr1),y ; Set one byte
iny
dex ; Done?
bne L3
L9: lda ptr2 ; Load function result
ldx ptr2+1
rts