From: cuz Date: Tue, 16 Sep 2003 20:35:37 +0000 (+0000) Subject: New %s inline asm format specifier X-Git-Tag: V2.12.0~1329 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=ffb77285dee823d0b05e00826e4efca8970743d0;p=cc65 New %s inline asm format specifier git-svn-id: svn://svn.cc65.org/cc65/trunk@2442 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/doc/cc65.sgml b/doc/cc65.sgml index c0599be2a..d574a3dd0 100644 --- a/doc/cc65.sgml +++ b/doc/cc65.sgml @@ -910,6 +910,7 @@ the format specifier before passing the assembly code line to the backend.

@@ -949,7 +950,7 @@ variables or functions into your asm statements. Code like this

may stop working if the way, the compiler generates these names is changed in -a future version. +a future version. Instead use the format specifiers from the table above.

diff --git a/src/cc65/asmstmt.c b/src/cc65/asmstmt.c index 7552ede48..d680f0b69 100644 --- a/src/cc65/asmstmt.c +++ b/src/cc65/asmstmt.c @@ -7,8 +7,8 @@ /* */ /* */ /* (C) 2001-2003 Ullrich von Bassewitz */ -/* Wacholderweg 14 */ -/* D-70597 Stuttgart */ +/* Römerstrasse 52 */ +/* D-70794 Filderstadt */ /* EMail: uz@musoftware.de */ /* */ /* */ @@ -274,6 +274,41 @@ static void ParseLVarArg (StrBuf* T, unsigned Arg) +static void ParseStrArg (StrBuf* T, unsigned Arg attribute ((unused))) +/* Parse the %s format specifier */ +{ + ExprDesc Expr; + char Buf [64]; + + /* We expect an argument separated by a comma */ + ConsumeComma (); + + /* Check what comes */ + switch (CurTok.Tok) { + + case TOK_IDENT: + /* Identifier */ + SB_AppendStr (T, CurTok.Ident); + NextToken (); + break; + + case TOK_SCONST: + /* String constant */ + SB_AppendStr (T, GetLiteral (CurTok.IVal)); + ResetLiteralPoolOffs (CurTok.IVal); + NextToken (); + break; + + default: + ConstSubExpr (hie1, InitExprDesc (&Expr)); + xsprintf (Buf, sizeof (Buf), "%ld", Expr.ConstVal); + SB_AppendStr (T, Buf); + break; + } +} + + + static void ParseAsm (void) /* Parse the contents of the ASM statement */ { @@ -304,6 +339,7 @@ static void ParseAsm (void) * %l - Numerical 32 bit value * %v - Assembler name of a (global) variable * %o - Stack offset of a (local) variable + * %s - Any argument converted to a string (almost) * %% - The % sign */ Arg = 0; @@ -322,12 +358,13 @@ static void ParseAsm (void) ++Arg; C = SB_Get (&S); switch (C) { + case '%': SB_AppendChar (&T, '%'); break; case 'b': ParseByteArg (&T, Arg); break; - case 'w': ParseWordArg (&T, Arg); break; case 'l': ParseLongArg (&T, Arg); break; - case 'v': ParseGVarArg (&T, Arg); break; case 'o': ParseLVarArg (&T, Arg); break; - case '%': SB_AppendChar (&T, '%'); break; + case 's': ParseStrArg (&T, Arg); break; + case 'v': ParseGVarArg (&T, Arg); break; + case 'w': ParseWordArg (&T, Arg); break; default: Error ("Error in __asm__ format specifier %u", Arg); AsmErrorSkip ();