TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: Pascal Schmidt
from: Jasen Betts
date: 2004-04-20 17:56:12
subject: strlen

Hi Pascal.

19-Apr-04 13:33:34, Pascal Schmidt wrote to Jasen Betts

 PS> Hi Jasen! :-)

 JB>> This is my first attempt at gcc style inline asm, I'd welcome any
 JB>> comments...

 PS> Looks good. Most people prefer to put a "\n" as the last thing on
 PS> each asm line. I think that makes error messages from the
 PS> assembler more readable since otherwise all of your asm block is
 PS> one big line

that makes sense... I was getting cryptic error messages from the assembler
(refering to a temporary file instead of the C source file)

 JB>> hmm, if I had the glibc source I could see how the experts did
 JB>> it.

 PS> The generic i386 version is mixed asm and C and can be found in
 PS> the file glibc-2.3.2/sysdeps/i386/strlen.c

 PS> size_t strlen (const char *str) { int cnt;

 PS> asm("cld\n"                   /* Search forward.  */
 PS>     "repnz\n"                 /* Look for a zero byte.
 PS>     "scasb" /* %0, %1, %3 */
 PS>     : "=c" (cnt)
 PS>     : "D" (str), "0" (-1), "a" (0));

 PS> return -2 - cnt; }

 PS> Short and to the point, mostly replacing some of what you did in
 PS> asm with proper input and output operand specs. There are also
 PS> long (more than 50 lines) variants for 486 and 586 processors

 JB>> is the syntax for inline asm described somewhere in the GCC info
 JB>> tree? (where?)

 PS> Well, there are some notes about input and output operands under C
 PS> Extensions, Extended Asm.

yeah, extremely generic notes... like I didn't know I could call EDI "D"
or ECX "c" in the inputs and outputs fields... I assume the 0 refers to ECX
again.

 -=> Bye <=-

---
* Origin: Open the pod bay doors, HAL. (3:640/1042)
SEEN-BY: 633/267 270
@PATH: 640/1042 531 954 774/605 123/500 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.