IAR, __ASM(), and *.s33 to *.C files

Discussion in 'C Programming' started by robin.pain@tesco.net, Oct 3, 2003.

  1. Guest

    Inlining assembler in a *.c file:-

    Both

    __asm("nop \n")

    and

    __asm("nop")

    work

    I have abandonned using __asm() it because it only seems to accept a
    literal string. Trying to pass it an <unsigned char*> as the manual
    suggests fails with a syntax error. Also as a last resort I tried
    this:-

    __asm ("ldaa SC1SR1")
    __asm ("std SC1DRH")

    but it failed with a "unknown variable or function identifier".
    Despite the proceeding:-

    #include <r812a4.h>

    That contains SC1SR1 etc. It only works if you avoid labels entirely
    e.g.

    __asm ("ldaa 0xCC")
    __asm ("std 0xCD")

    Which is asking for it! "I didn't get where I am today by..." as the
    famous Rigsby used to say.

    What I have opted for is to add a *.s33 file to the project containing
    the assembler [and my beloved macro that I originally intended to pass
    to the __asm ( ) ]:-

    //****************.s33 file *********************
    $equates.equ

    RSEG RCODE //Root-Code: assemble in common or
    shared rom
    public init_sci_and_send_a_percent

    ....
    init_sci_and_send_a_percent
    ldaa SC1SR1 //step 1 of clear pending data
    interrupts
    std SC1DRH //step 2 of clear pending data
    interrupts
    aux_tx '%' //send an % char from RS232
    rtc

    END
    //****************end of *.s33 file***************



    And then calling if from the *.c file



    //****************.c file ************************
    extern init_sci_and_send_a_percent
    ....
    init_sci_and_send_a_percent();
    //**************end of *.c file*******************

    It is easy to mix and match *.s33 and *.c files but only the crudest
    inlining is possible and only by breaking the one definition rule. At
    the very least we should be able to inline a macro that's the whole
    point!

    Robin
     
    , Oct 3, 2003
    #1
    1. Advertising

  2. <> scribbled the following:
    > Inlining assembler in a *.c file:-


    ....is entirely system-specific and therefore off-topic on
    comp.lang.c.

    --
    /-- Joona Palaste () ---------------------------\
    | Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
    | http://www.helsinki.fi/~palaste W++ B OP+ |
    \----------------------------------------- Finland rules! ------------/
    "Stronger, no. More seductive, cunning, crunchier the Dark Side is."
    - Mika P. Nieminen
     
    Joona I Palaste, Oct 3, 2003
    #2
    1. Advertising

  3. Richard Bos Guest

    () wrote:

    > Inlining assembler in a *.c file:-


    Stop right there.

    Inlining assembly is not only not ISO Standard C, it is arguably the
    single most system-dependent function your compiler may (or may not)
    have. You really need to ask this in a compiler-specific newsgroup.

    Richard
     
    Richard Bos, Oct 3, 2003
    #3
  4. Guest

    (Richard Bos) wrote in message news:<>...
    > () wrote:
    >
    > > Inlining assembler in a *.c file:-

    >
    > Stop right there.
    >
    > Inlining assembly is not only not ISO Standard C, it is arguably the
    > single most system-dependent function your compiler may (or may not)
    > have. You really need to ask this in a compiler-specific newsgroup.
    >
    > Richard


    Ok ok I stop. Don't you guys ever get your hands dirty?

    Robin
     
    , Oct 3, 2003
    #4
  5. -berlin.de Guest

    <> wrote:
    > (Richard Bos) wrote in message news:<>...
    >> () wrote:
    >>
    >> > Inlining assembler in a *.c file:-

    >>
    >> Stop right there.
    >>
    >> Inlining assembly is not only not ISO Standard C, it is arguably the
    >> single most system-dependent function your compiler may (or may not)
    >> have. You really need to ask this in a compiler-specific newsgroup.
    >>
    >> Richard


    > Ok ok I stop. Don't you guys ever get your hands dirty?


    We do, but we wash them before having dinner ;-)

    Regards, Jens
    --
    _ _____ _____
    | ||_ _||_ _| -berlin.de
    _ | | | | | |
    | |_| | | | | | http://www.physik.fu-berlin.de/~toerring
    \___/ens|_|homs|_|oerring
     
    -berlin.de, Oct 3, 2003
    #5
  6. () wrote in
    news::

    >> > Inlining assembler in a *.c file:-

    >>
    >> Stop right there.
    >>
    >> Inlining assembly is not only not ISO Standard C, it is arguably the
    >> single most system-dependent function your compiler may (or may not)
    >> have. You really need to ask this in a compiler-specific newsgroup.


    > Ok ok I stop. Don't you guys ever get your hands dirty?


    Yes, but we do it in comp.arch.embedded! Come on over and re-post.

    --
    - Mark ->
    --
     
    Mark A. Odell, Oct 3, 2003
    #6
  7. Guest

    Joona I Palaste <> wrote in message news:<bljb1h$ip6$>...
    > <> scribbled the following:
    > > Inlining assembler in a *.c file:-

    >
    > ...is entirely system-specific and therefore off-topic on
    > comp.lang.c.


    (Ouch) it's (oww) not for you boss (oof) this is for a fellow
    low-grade trying to iterate their way from a hybrid assembler/C to
    pure C. (phew)

    Robin
     
    , Oct 3, 2003
    #7
  8. () wrote in
    news::

    >> > Inlining assembler in a *.c file:-

    >>
    >> ...is entirely system-specific and therefore off-topic on
    >> comp.lang.c.

    >
    > (Ouch) it's (oww) not for you boss (oof) this is for a fellow
    > low-grade trying to iterate their way from a hybrid assembler/C to
    > pure C. (phew)


    Nonetheless, it's still an off-topic question. I await your post in
    comp.arch.embedded where it is topical.

    --
    - Mark ->
    --
     
    Mark A. Odell, Oct 3, 2003
    #8
  9. Kevin Easton Guest

    <> wrote:
    > Inlining assembler in a *.c file:-

    [...]
    > I have abandonned using __asm() it because it only seems to accept a
    > literal string. Trying to pass it an <unsigned char*> as the manual
    > suggests fails with a syntax error. Also as a last resort I tried
    > this:-


    (<OT> Well "duh" - there isn't a runtime assembler included in your
    program you know...</OT>)

    I think there's actually a standard C question here:

    > __asm ("ldaa SC1SR1")
    > __asm ("std SC1DRH")
    >
    > but it failed with a "unknown variable or function identifier".


    I'm guessing SC1SR1 and SC1DRH are macros defined in the header file you
    mention. Macros aren't expanded inside string literals - but if those
    macros expand to string literals, then you can use the fact that
    adjacent string literals are concatenated:

    __asm ("ldaa " SC1SR1)
    __asm ("std " SC1DRH)

    - Kevin.
     
    Kevin Easton, Oct 4, 2003
    #9
  10. Chris Torek Guest

    In article <newscache$wwn8mh$ba2$>
    Kevin Easton <> writes:
    >I think there's actually a standard C question here ...
    >Macros aren't expanded inside string literals - but if those
    >macros expand to string literals, then you can use the fact that
    >adjacent string literals are concatenated:
    >
    >__asm ("ldaa " SC1SR1)
    >__asm ("std " SC1DRH)


    This is indeed likely to work (it does in GCC for instance), but
    there is no guarantee that anything following a compiler-specific
    keyword like __asm is going to be treated lexically or syntactically
    like C code. So it could fail. The answer should be in the
    compiler's documentation; if not, the "try it and see" method is
    always available, however flawed it may be. :)
    --
    In-Real-Life: Chris Torek, Wind River Systems (BSD engineering)
    Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
    email: forget about it http://67.40.109.61/torek/index.html (for the moment)
    Reading email is like searching for food in the garbage, thanks to spammers.
     
    Chris Torek, Oct 4, 2003
    #10
  11. Kevin Easton Guest

    Chris Torek <> wrote:
    > In article <newscache$wwn8mh$ba2$>
    > Kevin Easton <> writes:
    >>I think there's actually a standard C question here ...
    >>Macros aren't expanded inside string literals - but if those
    >>macros expand to string literals, then you can use the fact that
    >>adjacent string literals are concatenated:
    >>
    >>__asm ("ldaa " SC1SR1)
    >>__asm ("std " SC1DRH)

    >
    > This is indeed likely to work (it does in GCC for instance), but
    > there is no guarantee that anything following a compiler-specific
    > keyword like __asm is going to be treated lexically or syntactically
    > like C code. So it could fail. The answer should be in the
    > compiler's documentation; if not, the "try it and see" method is
    > always available, however flawed it may be. :)


    Hmm. I reasoned that the __asm doesn't introduce undefined behaviour
    until after the preprocessing phases of translation are complete,
    because until then it's just a pptoken, and it's not a reserved pptoken
    (or is it?).

    - Kevin.
     
    Kevin Easton, Oct 5, 2003
    #11
  12. Chris Torek Guest

    In article <newscache$6zi9mh$s5e$>
    Kevin Easton <> writes:
    >Hmm. I reasoned that the __asm doesn't introduce undefined behaviour
    >until after the preprocessing phases of translation are complete,
    >because until then it's just a pptoken, and it's not a reserved pptoken
    >(or is it?).


    Given that __asm starts with a double underscore, it seems to me
    that all bets are off. I believe we have existence proofs (in the
    form of old x86 C compilers) of "__asm-like" constructs that do
    not obey C syntax. But I have no examples.
    --
    In-Real-Life: Chris Torek, Wind River Systems (BSD engineering)
    Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
    email: forget about it http://67.40.109.61/torek/index.html (for the moment)
    Reading email is like searching for food in the garbage, thanks to spammers.
     
    Chris Torek, Oct 5, 2003
    #12
  13. Kevin Easton Guest

    Chris Torek <> wrote:
    > In article <newscache$6zi9mh$s5e$>
    > Kevin Easton <> writes:
    >>Hmm. I reasoned that the __asm doesn't introduce undefined behaviour
    >>until after the preprocessing phases of translation are complete,
    >>because until then it's just a pptoken, and it's not a reserved pptoken
    >>(or is it?).

    >
    > Given that __asm starts with a double underscore, it seems to me
    > that all bets are off. I believe we have existence proofs (in the
    > form of old x86 C compilers) of "__asm-like" constructs that do
    > not obey C syntax. But I have no examples.


    You're probably right. I always thought that's what #pragma was for,
    though (introducing undefined behaviour during preprocessing).

    - Kevin.
     
    Kevin Easton, Oct 6, 2003
    #13
  14. Guest

    Kevin Easton <> wrote in message news:<newscache$wwn8mh$ba2$>...
    > <> wrote:
    > > Inlining assembler in a *.c file:-

    > [...]
    > > I have abandonned using __asm() it because it only seems to accept a
    > > literal string. Trying to pass it an <unsigned char*> as the manual
    > > suggests fails with a syntax error. Also as a last resort I tried
    > > this:-

    >
    > (<OT> Well "duh" - there isn't a runtime assembler included in your
    > program you know...</OT>)
    >


    (<gagged><OT> urgggg! it's mrghhh! all mrrghhh! statically compiled!
    phheww </gagged><OT>

    Robin
     
    , Oct 6, 2003
    #14
  15. Richard Bos Guest

    () wrote:

    > (Richard Bos) wrote in message news:<>...
    > > () wrote:
    > >
    > > > Inlining assembler in a *.c file:-

    > >
    > > Stop right there.
    > >
    > > Inlining assembly is not only not ISO Standard C, it is arguably the
    > > single most system-dependent function your compiler may (or may not)
    > > have. You really need to ask this in a compiler-specific newsgroup.

    >
    > Ok ok I stop. Don't you guys ever get your hands dirty?


    Yes. The blood is damn hard to get rid of, too.

    Richard
     
    Richard Bos, Oct 6, 2003
    #15
  16. Dan Pop Guest

    In <bloogh$8aa$> Chris Torek <> writes:

    >In article <newscache$6zi9mh$s5e$>
    >Kevin Easton <> writes:
    >>Hmm. I reasoned that the __asm doesn't introduce undefined behaviour
    >>until after the preprocessing phases of translation are complete,
    >>because until then it's just a pptoken, and it's not a reserved pptoken
    >>(or is it?).

    >
    >Given that __asm starts with a double underscore, it seems to me
    >that all bets are off.


    Use the asm keyword instead (as suggested by the standard itself) and
    all the bets are on at least until translation phase 8 ;-) If the
    compiler doesn't recognise it as a keyword, it must handle it as a valid
    function call. It's an ordinary pp-token, as far as the preprocessor is
    concerned...

    There is little point in compiling such code with the compiler in
    conforming mode, anyway.

    Dan
    --
    Dan Pop
    DESY Zeuthen, RZ group
    Email:
     
    Dan Pop, Oct 6, 2003
    #16
  17. Off Topic: IAR, __ASM(), and *.s33 to *.C files

    wrote:

    > Inlining assembler in a *.c file:-
    >
    > Both
    >
    > __asm("nop \n")
    >
    > and
    >
    > __asm("nop")
    >
    > work
    >
    > I have abandoned using __asm() it because it only seems to accept a
    > literal string. Trying to pass it an <unsigned char*> as the manual
    > suggests fails with a syntax error.
    > Also, as a last resort, I tried this:-
    >
    > __asm ("ldaa SC1SR1")
    > __asm ("std SC1DRH")
    >
    > but it failed with a "unknown variable or function identifier".
    > Despite the proceeding:-
    >
    > #include <r812a4.h>
    >
    > That contains SC1SR1 etc. It only works if you avoid labels entirely
    > e.g.
    >
    > __asm ("ldaa 0xCC")
    > __asm ("std 0xCD")
    >
    > Which is asking for it! "I didn't get where I am today by..." as the
    > famous Rigsby used to say.
    >
    > What I have opted for is to add a *.s33 file to the project containing
    > the assembler [and my beloved macro that I originally intended to pass
    > to the __asm ( ) ]:-
    >
    > //****************.s33 file *********************
    > $equates.equ
    >
    > RSEG RCODE //Root-Code: assemble in common or
    > shared rom
    > public init_sci_and_send_a_percent
    >
    > ...
    > init_sci_and_send_a_percent
    > ldaa SC1SR1 //step 1 of clear pending data
    > interrupts
    > std SC1DRH //step 2 of clear pending data
    > interrupts
    > aux_tx '%' //send an % char from RS232
    > rtc
    >
    > END
    > //****************end of *.s33 file***************
    >
    >
    >
    > And then calling if from the *.c file
    >
    >
    >
    > //****************.c file ************************
    > extern init_sci_and_send_a_percent
    > ...
    > init_sci_and_send_a_percent();
    > //**************end of *.c file*******************
    >
    > It is easy to mix and match *.s33 and *.c files but only the crudest
    > inlining is possible and only by breaking the one definition rule.
    > At the very least we should be able to inline a macro.
    > That's the whole point!


    Hi Robin,

    I see that you've already met our "Off Topic Cops".
    Please ignore them.

    If you can tell us which compiler (and operating system) you are using,
    we can probably redirect you to a more appropriate forum.
    Subscribers to the comp.lang.c newsgroup don't usually respond
    to questions about compiler specific features
    but also subscribe to compiler specific newsgroups
    and would be more that happy to respond to your questions
    if you would only post them in the appropriate newsgroup.
     
    E. Robert Tisdale, Oct 6, 2003
    #17
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    974
    M.E.Farmer
    Feb 13, 2005
  2. kashumoto_tokugawa
    Replies:
    1
    Views:
    1,713
  3. Steven Woody
    Replies:
    2
    Views:
    394
    Victor Bazarov
    Nov 14, 2005
  4. Replies:
    3
    Views:
    1,500
    Rolf Magnus
    Jan 18, 2009
  5. Replies:
    15
    Views:
    535
    Sjouke Burry
    Oct 30, 2011
Loading...

Share This Page