From 4ed9c427f2ba2e4ec0e620f1416aea0e2906f19e Mon Sep 17 00:00:00 2001 From: Jeremiah Orians Date: Sun, 14 Aug 2016 17:41:16 -0400 Subject: [PATCH] Initial prototype for a copy_string function --- Library function prototypes/clear_string.s | 5 +-- Library function prototypes/copy_string.s | 39 ++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 Library function prototypes/copy_string.s diff --git a/Library function prototypes/clear_string.s b/Library function prototypes/clear_string.s index ff185d9..b578fad 100644 --- a/Library function prototypes/clear_string.s +++ b/Library function prototypes/clear_string.s @@ -1,4 +1,5 @@ - # We will be using R0 and R1 to pass values to the function + # We will be using R0 to pass pointer to string + # to cleared by the function # R15 will be used as the stack pointer :start LOADUI R0 @string @@ -29,7 +30,7 @@ LOADXU8 R0 R1 R2 ; Get the byte STOREX8 R3 R1 R2 ; Overwrite with a Zero ADDUI R2 R2 1 ; Prep for next loop - CMPJUMP.NE R0 R3 @clear_byte ; Stop if byte is NULL + JUMP.NZ R0 @clear_byte ; Stop if byte is NULL ;; Done ;; Restore registers POPR R3 R15 diff --git a/Library function prototypes/copy_string.s b/Library function prototypes/copy_string.s new file mode 100644 index 0000000..f5d23ef --- /dev/null +++ b/Library function prototypes/copy_string.s @@ -0,0 +1,39 @@ + # We will be using R0 and R1 to pass values to the function + # R15 will be used as the stack pointer +:start + LOADUI R0 @string + LOADUI R1 0x100 + LOADUI R2 33 + LOADUI R3 44 + LOADUI R4 55 + LOADUI R15 0x600 + CALLI R15 @copy_string + HALT +:string + HALT + HALT + NOP + +;; Our simple string compare function +:copy_string + ;; Preserve registers + PUSHR R0 R15 + PUSHR R1 R15 + PUSHR R2 R15 + PUSHR R3 R15 + ;; Setup registers + MOVE R2 R1 + MOVE R1 R0 + LOADUI R3 0 +:copy_byte + LOADXU8 R0 R1 R3 ; Get the byte + STOREX8 R0 R2 R3 ; Store the byte + ADDUI R3 R3 1 ; Prep for next loop + JUMP.NZ R0 @copy_byte ; Stop if byte is NULL +;; Done + ;; Restore registers + POPR R3 R15 + POPR R2 R15 + POPR R1 R15 + POPR R0 R15 + RET R15