summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2018-06-23 15:14:16 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2018-06-23 15:14:16 -0400
commit52391afe486821e97ec50b3a3db076aa0e94c3c6 (patch)
treeecb7fac66044d4f8577f6b0f749fbbedc47f33db
parent7a97d930936527865cd215f1df5f931e26530d96 (diff)
downloadminos-52391afe486821e97ec50b3a3db076aa0e94c3c6.tar.gz
Fix up strtok
-rw-r--r--string.asm16
1 files changed, 10 insertions, 6 deletions
diff --git a/string.asm b/string.asm
index aafe30c..bf8f958 100644
--- a/string.asm
+++ b/string.asm
@@ -164,21 +164,23 @@ strncmp:
ret
strtok:
+ %define .token_count [bp - 2]
push bp
mov bp, sp
+ sub sp, 2 ; use: .token_count
+
push bx ; save GPRs
- push cx
push dx
push di
push si
- xor ax, ax ; use: for delimter (LSB)
- xor bx, bx ; use: base address for effective address calculations
+ xor ax, ax ; use: hold delimiter (LSB of AX)
+ xor bx, bx ; use: effective address calculations
xor cx, cx ; use: input string length counter
xor dx, dx ; use: temp for string comparison
- xor si, si ; use: token array
- xor di, di ; use: input string
+ xor si, si ; use: token array address
+ xor di, di ; use: input string address
mov di, [bp + 4] ; arg1 - input string (null terminated)
mov si, [bp + 6] ; arg2 - address of token array
@@ -213,6 +215,7 @@ strtok:
; points to our new token address
.strtok_record_no_adjust:
+ inc word .token_count
mov [si], bx ; store address in results array
add si, 2 ; increment results array by one WORD
inc di ; increment input string
@@ -236,13 +239,14 @@ strtok:
.strtok_return:
mov ax, [bp + 6] ; return token array
+ mov cx, .token_count ; return token count
pop si ; restore GPRs
pop di
pop dx
- pop cx
pop bx
+ add sp, 2
mov sp, bp
pop bp
ret