Mail Archives: djgpp/1999/03/06/20:20:31
Dave Bird wrote:
>
> "Parse error before string" at the INPUT line.
>
> #include <stdio.h>
> /* */
> /* STRING-LENGTH of zero-terminated string... */
> /* just a demo of using in-line assembler. */
> /* */
> int str_len(char *str){ int num=0;
> asm(
> "decl %ecx /n/t" /* --num */
> "FIND: incl %ecx /n/t" /* ++num */
> "movb [%ebx], %al /n/t" /* al = [ebx++] */
> "incl %ebx /n/t"
> "orb %al, %al /n/t" /* if al !=0 */
> "jnz FIND /n/t" /* go round again */ |
> :"c"(num) /*[OUTPUT from ECX]*/ |
> :"c"(num) "b"(str) /*[INPUT to EBX,CX]*/ <=+
^^^
You need a comma.
> :"%eax" /*[JUNKED eax] */
> ); return num;
> }
Some other problems:
All "%" signs need to be doubled (so decl %%ecx). Otherwise GCC will
think they refer to asm operands and be confused.
Third line should read "movb (%%ebx), %%al", parens instead of square
brackets.
You shouldn't use a label like FIND; it pollutes the namespace and will
break if you ever compile with -O3 (the function will be inlined and the
label used multiple times). Use a local label instead; see node "Symbol
names" in gas docs.
To mark ecx as an output, use "=c". Actually, since it's read-write,
use "+c" and omit it as an input. Also, you don't tell the compiler
that %ebx will have garbage after the asm finishes. Traditionally you
add %ebx to the clobber list, but that's wrong, according to the GCC
docs, and I think EGCS enforces it. (Can some EGCS guru explain how you
describe a read-clobber operand, other than outputting to a scratch
variable?)
/n/t should use backslashes.
--
Nate Eldredge
nate AT cartsys DOT com
- Raw text -