This commit is contained in:
julianb0 2019-05-31 21:25:56 +02:00
parent 0def32e91a
commit 2263a3f43d
No known key found for this signature in database
GPG Key ID: DDF8325C95299A62
5 changed files with 85 additions and 0 deletions

View File

@ -24,6 +24,10 @@ main:
mov ax1, 10
call print_n
mov ax0, .buf
mov ax1, .msg
call strcmp
leave
ret

52
dos/str/strcmp.k Normal file
View File

@ -0,0 +1,52 @@
; The OS/K Team licenses this file to you under the MIT license.
; See the LICENSE file in the project root for more information.
;
; int strcmp(const char *str1, const char *str2)
;
; Returns:
; 0 if the contents of both strings are equal
; 1 if the first character that does not match has a greater value in str1 than in str2
; -1 if the first character that does not match has a lower value in str1 than in str2
;
strcmp:
cmp b[ax0], b[ax1]
cjmpnz .1
test b[ax0], b[ax0]
cjmpz .1
inc ax0
inc ax1
jmp strcmp
.1:
mov rax, b[ax0]
sub rax, b[ax1]
sgn rax, rax
ret
;
; int strncmp(const char *str1, const char *str2, int maxn)
;
strncmp:
mov rcx, ax2
.1:
cmp b[ax0], b[ax1]
cjmpnz .1
test b[ax0], b[ax0]
cjmpz .1
inc ax0
inc ax1
loop strcmp
.1:
mov rax, b[ax0]
sub rax, b[ax1]
sgn rax, rax
ret

View File

@ -4,4 +4,5 @@
include "str/strlen.k"
include "str/strrev.k"
include "str/strcpy.k"
include "str/strcmp.k"

View File

@ -200,6 +200,27 @@ cdecz m
cdecnz r
cdecnz m
sgn r r
sgn r i
sgn r m
sgn m r
sgn m i
sgn m m
csgnz r r
csgnz r i
csgnz r m
csgnz m r
csgnz m i
csgnz m m
csgnnz r r
csgnnz r i
csgnnz r m
csgnnz m r
csgnnz m i
csgnnz m m
#
# Comparison instruction
#

View File

@ -10,6 +10,7 @@ IMPL_COND(add);
IMPL_COND(sub);
IMPL_COND(mul);
IMPL_COND(div);
IMPL_COND(sgn);
//
// Unsigned arithmetic instructions
@ -72,3 +73,9 @@ IMPL_START_1(dec)
}
IMPL_OUT;
IMPL_START_2(sgn)
{
v1 = (v2 ? ((long)v2 > 0 ? 1 : (ulong)-1L) : 0);
}
IMPL_OUT;