Using m68k assembly in c

Discussion in 'C Programming' started by par_c, Dec 10, 2003.

  1. par_c

    par_c Guest

    Hi all,
    I have a source code in c that uses some assembly for the motorola
    m68360 chip.
    Here is the part I dont understand:

    #define OR_REG32(reg,val) __asm__("or.l %0,%1" : : "n" (val), "o"
    (reg))

    1) I dont understand the semicolon with a space between them syntax,
    it look likes scope resolution but it isn't (I think). I also dont
    understand the %0 and %1 syntax, haven't seen them before.

    2) Anyone know how to implement this in the code without using the
    #define? Does anyone have experience with this type (using asm mixed
    with c code) of programming that could guide me?

    Thanx in advance.
     
    par_c, Dec 10, 2003
    #1
    1. Advertising

  2. par_c

    Jack Klein Guest

    On 9 Dec 2003 20:55:51 -0800, (par_c) wrote in
    comp.lang.c:

    > Hi all,
    > I have a source code in c that uses some assembly for the motorola
    > m68360 chip.
    > Here is the part I dont understand:
    >
    > #define OR_REG32(reg,val) __asm__("or.l %0,%1" : : "n" (val), "o"
    > (reg))
    >
    > 1) I dont understand the semicolon with a space between them syntax,
    > it look likes scope resolution but it isn't (I think). I also dont
    > understand the %0 and %1 syntax, haven't seen them before.
    >
    > 2) Anyone know how to implement this in the code without using the
    > #define? Does anyone have experience with this type (using asm mixed
    > with c code) of programming that could guide me?
    >
    > Thanx in advance.


    Please do not cross-post to comp.lang.c on issues like this in the
    future. There is no such thing as assembly language defined or
    supported by the C language, and such compiler specific non-standard
    extensions are 100% off-topic here.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c /faq
     
    Jack Klein, Dec 10, 2003
    #2
    1. Advertising

  3. par_c

    Erik Cato Guest

    (par_c) wrote in message news:<>...
    > Hi all,
    > I have a source code in c that uses some assembly for the motorola
    > m68360 chip.
    > Here is the part I dont understand:
    >
    > #define OR_REG32(reg,val) __asm__("or.l %0,%1" : : "n" (val), "o"
    > (reg))
    >
    > 1) I dont understand the semicolon with a space between them syntax,
    > it look likes scope resolution but it isn't (I think). I also dont
    > understand the %0 and %1 syntax, haven't seen them before.
    >
    > 2) Anyone know how to implement this in the code without using the
    > #define? Does anyone have experience with this type (using asm mixed
    > with c code) of programming that could guide me?
    >
    > Thanx in advance.



    Hi!

    Its impossible to say anything definite without refering
    to the manual for the compiler that this code was first
    written for. So my first advice is to find out what compiler
    the code was intended for and then ask your question in a
    more appropriate group. If that is not possible try looking
    at how the macro is being used. That can tell you a lot.

    My guess is that the purpose of the code is to bitwise OR a
    specific register with a value (perhaps a special purpose
    hardware register). This is not possible to do in C.

    You should always try to avoid any inline assembly bacause it
    confuses the optimizer.

    //Erik
     
    Erik Cato, Dec 10, 2003
    #3
  4. >You should always try to avoid any inline assembly bacause it
    >confuses the optimizer.


    One reason why gcc-inline assembler is a little bit more complicated
    is, that it can work very well together with the optimizer.

    ---
    42Bastian
    Do not email to , it's a spam-only account :)
    Use <same-name>@epost.de instead !
     
    42Bastian Schick, Dec 10, 2003
    #4
  5. par_c

    Dan Pop Guest

    In <> (42Bastian Schick) writes:

    >>You should always try to avoid any inline assembly bacause it
    >>confuses the optimizer.

    >
    >One reason why gcc-inline assembler is a little bit more complicated
    >is, that it can work very well together with the optimizer.


    It basically tells the compiler which registers and objects are used
    for input purposes and which for output purposes, so the compiler can
    figure out what's going on inside the asm statement.

    Dan
    --
    Dan Pop
    DESY Zeuthen, RZ group
    Email:
     
    Dan Pop, Dec 10, 2003
    #5
  6. (42Bastian Schick) wrote in message news:<>...
    > >You should always try to avoid any inline assembly bacause it
    > >confuses the optimizer.

    >
    > One reason why gcc-inline assembler is a little bit more complicated
    > is, that it can work very well together with the optimizer.
    >
    > ---
    > 42Bastian
    > Do not email to , it's a spam-only account :)
    > Use <same-name>@epost.de instead !



    Inline ASM, used correctly can produce huge advantages. Consider
    algorithms for 32 bit math on a 16 bit bus, or floating point
    implementations. All of these algorithms rely heavily on testing the
    carry-bit. This flag cannot be read easily from C or most other
    languages.

    Assembly allows the flag to be checked directly, rather than checking
    the result of an addition operation to see if it is less than either
    of the addends.

    Note that ASM should still not be used unnecessarly, but in the right
    place a few clock cycles go a long way.

    "Premature optimization is the root of all evil" - Knuth.

    ---
    Jared Dykstra
    www.bork.org/~jared
     
    Jared Dykstra, Dec 17, 2003
    #6
    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. Prasanna Padmanabhan
    Replies:
    1
    Views:
    825
    Mattias Sjögren
    Nov 19, 2003
  2. Brent
    Replies:
    1
    Views:
    1,373
    Brent
    Jan 23, 2004
  3. SA
    Replies:
    0
    Views:
    482
  4. Horatiu Margavan via .NET 247

    Assembly's manifest definition does not match the assembly reference.

    Horatiu Margavan via .NET 247, Aug 30, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    3,626
    Horatiu Margavan via .NET 247
    Aug 30, 2004
  5. Replies:
    5
    Views:
    125
    Andrew Hamm
    Dec 13, 2004
Loading...

Share This Page