summaryrefslogtreecommitdiff
path: root/programs/sub-suite/libc.s
diff options
context:
space:
mode:
Diffstat (limited to 'programs/sub-suite/libc.s')
-rw-r--r--programs/sub-suite/libc.s99
1 files changed, 99 insertions, 0 deletions
diff --git a/programs/sub-suite/libc.s b/programs/sub-suite/libc.s
index b34d2d3..3de1094 100644
--- a/programs/sub-suite/libc.s
+++ b/programs/sub-suite/libc.s
@@ -411,6 +411,60 @@ free:
; Caller preserved registers: D, S, F.
; Callee preserved registers: B.
+;memcpy:
+;; inc step ;
+; phb.q ; Preserve B.
+; phx.q ; Preserve X.
+; xor b, b ; Reset B.
+; mov a, f ; Get the size.
+; and #7 ; Get the size, mod 8.
+; mov x, f ; Preserve the size.
+; lsr f, #3 ; Divide the size by 8.
+; beq @rem ; The quotient is zero, so copy the remaining number of bytes.
+;@loop:
+; mov.q (d+8*b), (s+8*b) ; Copy 8 bytes from the source, into the destination.
+; inb ; Increment the counter.
+; cmp b, f ; Is the counter the same as the size?
+; bne @loop ; No, so keep looping.
+;@rem:
+; lsl f, #3 ; Multiply the quotient by 8.
+; cmp #0 ; Is the remainder zero?
+; beq @end ; Yes, so we're done.
+; lea b, 8 ; No, so set our offset to 8.
+; sub b, a ; Subtract 8 by the remainder.
+; and #0 ; Reset A.
+; dec ; Set the bitmask to -1.
+; lsl b, #3 ; Multiply the offset by 8.
+; lsr b ; Shift the bitmask right by the offset.
+; mov.q b, (s+f) ; Get 8 bytes from the source.
+; xor.q b, (d+f) ; Mask out the destination bytes.
+; and b ; Get The masked source.
+; xor.q (d+f), a ; Copy the remaining bytes from the source, into the destination.
+;@end:
+; mov f, x ; Restore the size.
+; mov a, d ; Set the return value to the destination pointer.
+; plx.q ; Restore X.
+; plb.q ; Restore B.
+; rts ; End of memcpy.
+
+
+;memcpy:
+; phb.q ; Preserve B.
+; phx.q ; Preserve X.
+; phy.q ; Preserve Y.
+; mov b, f ; Get the size.
+; mov x, d ; Get the destination.
+; mov y, s ; Get the source.
+; txa ; Set the return value to the destination pointer.
+;@copy:
+; mmv.r ; Copy the size bytes from the source, into the destination.
+;@end:
+; ply.q ; Restore Y.
+; plx.q ; Restore X.
+; plb.q ; Restore B.
+; rts ; End of memcpy.
+
+
memcpy:
phb.q ; Preserve B.
xor b, b ; Reset B.
@@ -433,6 +487,51 @@ memcpy:
; Caller preserved registers: D, S, F.
; Callee preserved registers: B.
+;memset:
+;; inc step ;
+; phb.q ; Preserve B.
+; phx.q ; Preserve X.
+; lea b, 8 ; Set the loop counter to 8.
+; psh s ; Get the constant.
+;@const_loop:
+; lsl s, #8 ; Make room for the next byte.
+; mov s, (sp+1) ; Get the next byte.
+; deb ; Decrement the loop counter.
+; bne @const_loop ; The counter is non zero, so keep looping.
+; ins ; Clean up the frame.
+;@init:
+; mov a, f ; Get the size.
+; and #7 ; Get the size, mod 8.
+; mov x, f ; Preserve the size.
+; lsr f, #3 ; Divide the size by 8.
+; beq @rem ; The quotient is zero, so copy the remaining number of bytes.
+;@loop:
+; mov.q (d+8*b), s ; Set all 8 destination bytes, to the constant value.
+; inb ; Increment the counter.
+; cmp b, f ; Is the counter the same as the size?
+; bne @loop ; No, so keep looping.
+;@rem:
+; lsl f, #3 ; Multiply the quotient by 8.
+; cmp #0 ; Is the remainder zero?
+; beq @end ; Yes, so we're done.
+; lea b, 8 ; No, so set our offset to 8.
+; sub b, a ; Subtract 8 by the remainder.
+; and #0 ; Reset A.
+; dec ; Set the bitmask to -1.
+; lsl b, #3 ; Multiply the offset by 8.
+; lsr b ; Shift the bitmask right by the offset.
+; mov.q b, s ; Get 8 bytes from the constant value.
+; xor.q b, (d+f) ; Mask out the destination bytes.
+; and b ; Get The masked source.
+; xor.q (d+f), a ; Copy the remaining bytes from the source, into the destination.
+;@end:
+; mov f, x ; Restore the size.
+; mov a, d ; Set the return value to the destination pointer.
+; plx.q ; Restore X.
+; plb.q ; Restore B.
+; rts ; End of memset.
+
+
memset:
phb.q ; Preserve B.
xor b, b ; Reset B.