I'm not sure this is the right place, since this touches both C and asm.
I have trouble making tigcc understand that he is not to use some specific variables after I have used them in an inline assembly instruction. Here is a working code sample :

(This strlen works for <65535 chars strings, and should be faster than a romcall for short strings)
#define strlen(x) ({register unsigned short _result_; \
			__asm__("move.l %1,%%a0	\n\t" \
				"moveq #-1,%0	\n\t" \
				"tst.b %%a0@+	\n\t" \
				"dbeq	%0,.-2	\n\t" \
				"not.w	%0	\n\t" \
				: "=d" (_result_) \
				: "a" (x) \
				: "a0"); _result_; })

However I'm not satisfied with it, because:
- it uses a hardcoded register
- the first instruction may be an extra copy if x is not used anymore after the call.

Here is what I tried :

#define strlen(x) ({register unsigned _result_; \
			__asm__("moveq #-1,%0	\n\t" \
				"tst.b %1@+	\n\t" \
				"dbeq	%0,.-2	\n\t" \
				"not.w	%0	\n\t" \
				: "=d" (_result_) \
				: "a" (x) \
				: "%1"); _result_; })

I get no error. However, if I use x after the call, tigcc reuses the register %1, without reloading it first.
What did I miss ?

[edit: Well, it seems that this way of specifying cloberred registers is wong. That would explain]


You can't specify an input as a clobber. What you can do is to make it an output into a dummy variable:
: "=d" (_result_), "=a" (dummy) : "1" (x)
avatarMes news pour calculatrices TI: Ti-Gen
Mes projets PC pour calculatrices TI: TIGCC, CalcForge (CalcForgeLP, Emu-TIGCC)
Mes chans IRC: #tigcc et #inspired sur irc.freequest.net (UTF-8)

Liberté, Égalité, Fraternité