91
Other Discussion / Re: ELF files are confusing.
« Last post by Frank Kotler on August 14, 2023, 01:04:52 PM »Okay, I'm confused on general principles.
Are you straightened out, Ben?
Frank
Are you straightened out, Ben?
Frank
Yeah, I am probably confused. Should have stopped after "I don't know'"Frank, I was talking about the "program headers" in the original post.
Best,
Frank
That would return string length + 1....Ops... sorry... my bad...
So strlen could be implemented as:Code: [Select]; Same as: size_t strlen( const char * );
; the function assumes ALL strings will be NUL terminated.
strlen_:
xor eax,eax
lea ecx,[rax-1] ; Limiting the string size to 2³²-1, max.
mov rdx,rdi
repnz scasb ; Scan for '\0'...
sub rdi,rdx
mov rax,rdi ; returns size in RAX.
ret
xor eax, eax
lea ecx, [rax - 1]
mov rdx, rdi
repnz scasb
sub rdi, rdx
;mov rax, rdi
lea rax, [rdi - 1] ; not counting the null terminator