summaryrefslogtreecommitdiff
path: root/zap/source/amd64/mem/fill.s
diff options
context:
space:
mode:
Diffstat (limited to 'zap/source/amd64/mem/fill.s')
-rw-r--r--zap/source/amd64/mem/fill.s51
1 files changed, 51 insertions, 0 deletions
diff --git a/zap/source/amd64/mem/fill.s b/zap/source/amd64/mem/fill.s
new file mode 100644
index 0000000..0abd2be
--- /dev/null
+++ b/zap/source/amd64/mem/fill.s
@@ -0,0 +1,51 @@
+# 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>.
+
+.intel_syntax noprefix
+
+.globl zap_fill
+
+zap_fill:
+ # zap_i8 val1;
+ # zap_i04 val8;
+
+ movzx rax,sil # val8 = val;
+ shl rax,0x8 # val8 <<= 0x8u;
+ mov al,sil # val8 |= val;
+ shl rax,0x8 # val8 <<= 0x8u;
+ mov al,sil # val8 |= val;
+ shl rax,0x8 # val8 <<= 0x8u;
+ mov al,sil # val8 |= val;
+ shl rax,0x8 # val8 <<= 0x8u;
+ mov al,sil # val8 |= val;
+ shl rax,0x8 # val8 <<= 0x8u;
+ mov al,sil # val8 |= val;
+ shl rax,0x8 # val8 <<= 0x8u;
+ mov al,sil # val8 |= val;
+ shl rax,0x8 # val8 <<= 0x8u;
+ mov al,sil # val8 |= val;
+ # val1 = val8;
+
+.wrdfill: # wrdfill:;
+ cmp rdx,0x8
+ jl .bytefill # if (num < 0x8u) goto bytefill;
+
+ mov [rdi],rax # *dest = val8;
+
+ add rdi,0x8 # dest += 0x8u;
+ sub rdx,0x8 # num -= 0x8u;
+ jmp .wrdfill # goto wrdfill
+
+.bytefill: # bytefill:;
+ test rdx,rdx # if (rem == 0x0)
+ jz .done # goto done
+
+ mov [rsi],al # *dest = val1;
+
+ inc rdi # ++dest;
+ dec rdx # --rem;
+ jmp .bytefill # goto bytefill;
+
+.done:
+ ret # return