From cc28b42897bf7b2322d45062685c198e7fe714e6 Mon Sep 17 00:00:00 2001 From: Ain <41307858+nero@users.noreply.github.com> Date: Sat, 28 Sep 2019 12:37:16 +0000 Subject: [PATCH] Factor out string token search --- kernel/config.asm | 33 +-------------------------------- kernel/main.asm | 1 + kernel/string.asm | 31 +++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 32 deletions(-) create mode 100644 kernel/string.asm diff --git a/kernel/config.asm b/kernel/config.asm index 5be6029..de6776e 100644 --- a/kernel/config.asm +++ b/kernel/config.asm @@ -8,37 +8,6 @@ config_tokens: .none: db 0 -; IN SI offset of needle -; DI offset to haystack table -; OUT DI found offset in table -; ZF zero flag set if match -config_search_token: - push bp - push cx -.loop: - cmp BYTE [di], 0 - je .fail - push si - push di - mov bp, di - xor ch, ch - mov cl, [di] - inc di - add bp, cx - inc bp - repe cmpsb - pop di - pop si - je .end - mov di, bp - jmp .loop -.fail: - stc -.end: - pop cx - pop cx - ret - config_parse_int: ret @@ -46,6 +15,6 @@ config_parse_int: config_first_run: mov si, bx mov di, config_tokens - call config_search_token + call string_search_token int3 ret diff --git a/kernel/main.asm b/kernel/main.asm index 873c448..0f5a06c 100644 --- a/kernel/main.asm +++ b/kernel/main.asm @@ -58,6 +58,7 @@ init: hlt jmp .halt +%include "string.asm" %include "config.asm" kernel_end: diff --git a/kernel/string.asm b/kernel/string.asm new file mode 100644 index 0000000..dc9a744 --- /dev/null +++ b/kernel/string.asm @@ -0,0 +1,31 @@ +; IN DS:SI offset of needle +; ES:DI offset to haystack table +; OUT ES:DI found offset in table +; ZF zero flag set if match + +string_search_token: + push bp + push cx +.loop: + cmp BYTE [es:di], 0 + je .fail + push si + push di + mov bp, di + xor ch, ch + mov cl, [es:di] + inc di + add bp, cx + inc bp + repe cmpsb + pop di + pop si + je .end + mov di, bp + jmp .loop +.fail: + stc +.end: + pop cx + pop cx + ret