From dddfd8b706a5083517d5dbaa9d6c52c53952ea59 Mon Sep 17 00:00:00 2001 From: Ry Date: Fri, 25 Mar 2022 18:03:12 -0700 Subject: [PATCH] fox32rom: Add memory compare routines --- memory.asm | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/memory.asm b/memory.asm index a94efa7..573e39e 100644 --- a/memory.asm +++ b/memory.asm @@ -1,4 +1,4 @@ -; memory copy routines +; memory copy/compare routines ; copy specified number of bytes from source pointer to destination pointer ; if the source and destination overlap, the behavior is undefined @@ -48,4 +48,60 @@ copy_memory_words_loop: pop r31 pop r1 pop r0 - ret \ No newline at end of file + ret + +; compare specified number of bytes from source pointer with destination pointer +; inputs: +; r0: pointer to source +; r1: pointer to destinaton +; r2: number of bytes to compare +; outputs: +; Z flag +compare_memory_bytes: + push r0 + push r1 + push r31 + + mov r31, r2 +compare_memory_bytes_loop: + cmp.8 [r1], [r0] + ifnz jmp compare_memory_bytes_not_equal + inc r0 + inc r1 + loop compare_memory_bytes_loop + ; set Z flag if we reach thie point + mov r0, 0 + cmp r0, 0 +compare_memory_bytes_not_equal: + pop r31 + pop r1 + pop r0 + ret + +; compare specified number of words from source pointer with destination pointer +; inputs: +; r0: pointer to source +; r1: pointer to destinaton +; r2: number of words to compare +; outputs: +; Z flag +compare_memory_words: + push r0 + push r1 + push r31 + + mov r31, r2 +compare_memory_words_loop: + cmp [r1], [r0] + ifnz jmp compare_memory_words_not_equal + add r0, 4 + add r1, 4 + loop compare_memory_words_loop + ; set Z flag if we reach thie point + mov r0, 0 + cmp r0, 0 +compare_memory_words_not_equal: + pop r31 + pop r1 + pop r0 + ret