www.pudn.com > ASM86_64.rar > string.s
.text //------------------------------------------ // unsigned int str_len(const char *s) // // return value: // unsigned int: the length of strings //----------------------------------------- .global str_len str_len: xor %eax, %eax movl 4(%esp), %edx loop: movb (%edx), %bl inc %eax inc %edx test %bl,%bl jnz loop dec %eax ret //------------------------------------- // char get_char(const char *s) // // return value: // char: get char of string[ith] //-------------------------------------- .global get_char get_char: movl 4(%esp), %edx movl 8(%esp), %ecx loop1: movb (%edx), %al test %al, %al jz out inc %edx dec %ecx test %ecx, %ecx jnz loop1 out: ret //---------------------------------- // int str_ch(const char *d, char c) // // return: 0: no found // value: found & postion; //--------------------------- .global str_ch str_ch: xor %eax, %eax movl 4(%esp), %edx movl 8(%esp), %ecx loop2: inc %eax movb (%edx), %bl test %bl, %bl jz out1 inc %edx cmpb %bl, %cl jnz loop2 jmp out2 out1: xor %eax, %eax out2: ret //-------------------------------------------------------------- // unsigned int str_str(const char *dest, const char* source) // // reture value: // 0: no found // unsigned int: found & get postion //-------------------------------------------------------------- .global str_str str_str: movl 4(%esp), %edi movl 8(%esp), %esi // set tmp var sub $8, %esp movl %edi, 4(%esp) movl %esi, (%esp) mov $1, %eax loop3: mov %esi, %ebx mov %edi, %edx inc %esi inc %edi movb (%ebx), %cl //----------- // found & no found test %cl,%cl jz result cmpb $0, (%edx) jz no //----------- cmpb (%edx), %cl jz loop3 yes: incl 4(%esp) movl 4(%esp), %edi movl (%esp), %esi inc %eax jmp loop3 no: xor %eax, %eax result: add $8, %esp ret //---------------------------- // ungisgned get_c_sum(char *s, char c) // // return char c sum in string s // //------------------------------------ .global get_c_sum get_c_sum: movl 4(%esp), %edx movb 8(%esp), %bl xor %eax, %eax test %edx, %edx jz out_get_c loop_get_c: inc %edx movb -1(%edx), %cl test %cl, %cl jz out_get_c cmp %bl, %cl jnz loop_get_c inc %eax jmp loop_get_c out_get_c: ret // //-------------------------- .global get_pc get_pc: call next next: pop %eax ret //----------------------------------------- .global dump_banry dump_banry: push %ebp mov %esp, %ebp movl 8(%ebp), %edx movb 12(%ebp), %al movl $9, %ecx loop5: dec %ecx jz out5 shl $1, %al jc one zero: movb $48, (%edx) inc %edx jmp loop5 one: movb $49, (%edx) inc %edx jmp loop5 out5: pop %ebp ret