Adds strclr()
This commit is contained in:
@@ -4,6 +4,7 @@ section .text
|
||||
global strlen
|
||||
global strcpy
|
||||
global strcat
|
||||
global strclr
|
||||
|
||||
;----- strlen(*str[]) -----;
|
||||
; Gets the length of given string
|
||||
@@ -85,3 +86,19 @@ strcat:
|
||||
mov byte [rdi], EOS
|
||||
mov rax, r8
|
||||
ret
|
||||
|
||||
;----- strclr(*str[], maxLength) -----;
|
||||
; Clears a string by placing [maxLength] EOS into string.
|
||||
; Thus DANGEROUS function: MAKE SURE maxLength IS SIZE OF str[] - greater values WILL cause issues and eventually crashes
|
||||
; Return value: N/A
|
||||
; Used registers:
|
||||
; rdi* (arg) Pointer to str[]
|
||||
; rsi (arg) Length of str[]
|
||||
; rcx* Counter for STOSB
|
||||
; rax* Character storage (AL) for STOSB
|
||||
strclr:
|
||||
mov rcx, rsi
|
||||
xor al, al
|
||||
cld
|
||||
rep stosb
|
||||
ret
|
||||
|
@@ -10,15 +10,17 @@ extern printf
|
||||
extern strlen
|
||||
extern strcpy
|
||||
extern strcat
|
||||
extern strclr
|
||||
; convert.asm
|
||||
|
||||
section .rodata
|
||||
TEST_print equ 1
|
||||
TEST_puts equ 1
|
||||
TEST_printf equ 1
|
||||
TEST_strlen equ 1
|
||||
TEST_strcpy equ 1
|
||||
TEST_strcat equ 1
|
||||
TEST_print equ 0
|
||||
TEST_puts equ 0
|
||||
TEST_printf equ 0
|
||||
TEST_strlen equ 0
|
||||
TEST_strcpy equ 0
|
||||
TEST_strcat equ 0
|
||||
TEST_strclr equ 1
|
||||
|
||||
str1 db "Hello, world!",EOS
|
||||
str2 db "Hello, World!",EOS
|
||||
@@ -57,6 +59,12 @@ section .rodata
|
||||
strcat1 db TAB,"strcat(strBuff2, str1, 32): ",NL,TAB,TAB,EOS
|
||||
strcat2 db TAB,"strcat(strBuff2, str5, 32): ",NL,TAB,TAB,EOS
|
||||
|
||||
;strclr()
|
||||
msgStrclr db "TEST strclr()",NL,EOS
|
||||
strclr1a db TAB,"strcat(strBuff1, str5, 32)",NL,TAB,"strclr(strBuff1, 32)",NL,TAB,"print(strBuff1): ",NL,TAB,TAB,EOS
|
||||
strclr1b db TAB,"print(strBuff1[3]): ",NL,TAB,TAB,EOS
|
||||
strclr2 db TAB,"strcat(strBuff1, str5, 32)",NL,TAB,"strclr(strbuff1, 2)",NL,TAB,"print(strbuff1[3]): ",NL,TAB,TAB,EOS
|
||||
|
||||
section .data
|
||||
|
||||
section .bss
|
||||
@@ -193,6 +201,47 @@ _start:
|
||||
call puts
|
||||
%endif
|
||||
|
||||
;---
|
||||
;--- strclr
|
||||
;---
|
||||
%if TEST_strclr
|
||||
lea rdi, [rel msgStrclr]
|
||||
call print
|
||||
|
||||
; TEST 1
|
||||
lea rdi, [rel strclr1a]
|
||||
call print
|
||||
lea rdi, [rel strBuff1]
|
||||
lea rsi, [rel str5]
|
||||
mov rdx, 32
|
||||
call strcat
|
||||
lea rdi, [rel strBuff1]
|
||||
mov rsi, 32
|
||||
call strclr
|
||||
lea rdi, [rel strBuff1]
|
||||
call puts
|
||||
|
||||
lea rdi, [rel strclr1b]
|
||||
call print
|
||||
lea rdi, [rel strBuff1]
|
||||
add rdi, 3
|
||||
call puts
|
||||
|
||||
; TEST 2
|
||||
lea rdi, [rel strclr2]
|
||||
call print
|
||||
lea rdi, [rel strBuff1]
|
||||
lea rsi, [rel str5]
|
||||
mov rdx, 32
|
||||
call strcat
|
||||
lea rdi, [rel strBuff1]
|
||||
mov rsi, 2
|
||||
call strclr
|
||||
lea rdi, [rel strBuff1]
|
||||
add rdi, 3
|
||||
call puts
|
||||
%endif
|
||||
|
||||
;---
|
||||
;--- exit()
|
||||
;---
|
||||
|
Reference in New Issue
Block a user