1#include <asm.inc> 2#include <ksamd64.inc> 3.code64 4#if 0 5 title strcat - concatenate (append) one string to another 6;*** 7;strcat.asm - contains strcat() and strcpy() routines 8; 9; Copyright (c) Microsoft Corporation. All rights reserved. 10; 11;Purpose: 12; STRCAT concatenates (appends) a copy of the source string to the 13; end of the destination string, returning the destination string. 14; 15;******************************************************************************* 16include ksamd64.inc 17 subttl "strcat" 18;*** 19;char *strcat(dst, src) - concatenate (append) one string to another 20; 21;Purpose: 22; Concatenates src onto the end of dest. Assumes enough 23; space in dest. 24; 25; Algorithm: 26; char * strcat (char * dst, char * src) 27; { 28; char * cp = dst; 29; 30; while( *cp ) 31; ++cp; /* Find end of dst */ 32; while( *cp++ = *src++ ) 33; ; /* Copy src to end of dst */ 34; return( dst ); 35; } 36; 37;Entry: 38; char *dst - string to which "src" is to be appended 39; const char *src - string to be appended to the end of "dst" 40; 41;Exit: 42; The address of "dst" in EAX 43; 44;Uses: 45; EAX, ECX 46; 47;Exceptions: 48; 49;******************************************************************************* 50 51;*** 52;char *strcpy(dst, src) - copy one string over another 53; 54;Purpose: 55; Copies the string src into the spot specified by 56; dest; assumes enough room. 57; 58; Algorithm: 59; char * strcpy (char * dst, char * src) 60; { 61; char * cp = dst; 62; 63; while( *cp++ = *src++ ) 64; ; /* Copy src over dst */ 65; return( dst ); 66; } 67; 68;Entry: 69; char * dst - string over which "src" is to be copied 70; const char * src - string to be copied over "dst" 71; 72;Exit: 73; The address of "dst" in EAX 74; 75;Uses: 76; EAX, ECX 77; 78;Exceptions: 79;******************************************************************************* 80#endif 81 82public ___entry_from_strcat_in_strcpy 83LEAF_ENTRY_ARG2 strcat, _TEXT, dst_ptr_byte, src_ptr_byte 84 85 //OPTION PROLOGUE:NONE, EPILOGUE:NONE 86 87 mov r11, rcx 88 test cl, 7 89 jz strcat_loop_begin 90 91strcat_copy_head_loop_begin: 92 mov al, [rcx] 93 test al, al 94 jz ___entry_from_strcat_in_strcpy 95 inc rcx 96 test cl, 7 97 jnz strcat_copy_head_loop_begin 98 99strcat_loop_begin: 100 mov rax, [rcx] 101 mov r10, rax 102 mov r9, HEX(7efefefefefefeff) 103 add r9, r10 104 xor r10, -1 105 xor r10, r9 106 add rcx, 8 107 mov r9, HEX(8101010101010100) 108 test r10, r9 109 je strcat_loop_begin 110 sub rcx, 8 111 112strcat_loop_end: 113 test al, al 114 jz ___entry_from_strcat_in_strcpy 115 inc rcx 116 test ah, ah 117 jz ___entry_from_strcat_in_strcpy 118 inc rcx 119 shr rax, 16 120 test al, al 121 jz ___entry_from_strcat_in_strcpy 122 inc rcx 123 test ah, ah 124 jz ___entry_from_strcat_in_strcpy 125 inc rcx 126 shr rax, 16 127 test al, al 128 jz ___entry_from_strcat_in_strcpy 129 inc rcx 130 test ah, ah 131 jz ___entry_from_strcat_in_strcpy 132 inc rcx 133 shr eax, 16 134 test al, al 135 jz ___entry_from_strcat_in_strcpy 136 inc rcx 137 test ah, ah 138 jz ___entry_from_strcat_in_strcpy 139 inc rcx 140 jmp strcat_loop_begin 141 142LEAF_END strcat, _TEXT 143 144LEAF_ENTRY_ARG2 strcpy, _TEXT, dst_ptr_byte, src_ptr byte 145 146 //OPTION PROLOGUE:NONE, EPILOGUE:NONE 147 148 mov r11, rcx 149strcat_copy: 150___entry_from_strcat_in_strcpy=strcat_copy 151 // align the SOURCE so we never page fault 152 // dest pointer alignment not important 153 sub rcx, rdx // combine pointers 154 test dl, 7 155 jz qword_loop_entrance 156 157copy_head_loop_begin: 158 mov al, [rdx] 159 mov [rdx+rcx], al 160 test al, al 161 jz byte_exit 162 inc rdx 163 test dl, 7 164 jnz copy_head_loop_begin 165 jmp qword_loop_entrance 166 167byte_exit: 168 mov rax, r11 169 ret 170 171qword_loop_begin: 172 mov [rdx+rcx], rax 173 add rdx, 8 174qword_loop_entrance: 175 mov rax, [rdx] 176 mov r9, HEX(7efefefefefefeff) 177 add r9, rax 178 mov r10, rax 179 xor r10, -1 180 xor r10, r9 181 mov r9, HEX(8101010101010100) 182 test r10, r9 183 jz qword_loop_begin 184 185qword_loop_end: 186 test al, al 187 mov [rdx+rcx], al 188 jz strcat_exit 189 inc rdx 190 test ah, ah 191 mov [rdx+rcx], ah 192 jz strcat_exit 193 inc rdx 194 shr rax, 16 195 test al, al 196 mov [rdx+rcx], al 197 jz strcat_exit 198 inc rdx 199 test ah, ah 200 mov [rdx+rcx], ah 201 jz strcat_exit 202 inc rdx 203 shr rax, 16 204 test al, al 205 mov [rdx+rcx], al 206 jz strcat_exit 207 inc rdx 208 test ah, ah 209 mov [rdx+rcx], ah 210 jz strcat_exit 211 inc rdx 212 shr eax, 16 213 test al, al 214 mov [rdx+rcx], al 215 jz strcat_exit 216 inc rdx 217 test ah, ah 218 mov [rdx+rcx], ah 219 jz strcat_exit 220 inc rdx 221 jmp qword_loop_entrance 222 223strcat_exit: 224 mov rax, r11 225 ret 226 227LEAF_END strcpy, _TEXT 228 229 end 230