Compilers

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • Problem involved porting LCC to a 8 bit microcontroller

    5 answers - 924 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    Just a student project !Porting porting LCC to a 8 bit microcontroller
    with which char is 8 bit and int is 16bit.
    But I found in LCC character and short-integer actual arguments are
    always promoted to the coresponding type even in the presence of a
    prototype!(And does there any place in it did similar thing?)
    So I have to use 2 8bit regsters for a char type argument!This is
    unbearable here!
    I want to change the front end, but not sure. All I have to do is
    change codes for function declarations and definitions in decl.c?
    Further more , in arithmetric computing "char c1,c2; c1 = c1 + c2;"
    does lcc promote char into int? I doubt of it because there isn't an
    dag operator for ADDI1!
    May be the questions is silly! But it's the questions in my way and the
    book mentioned little about this.
    Any help would be greatly appreciated. Thanks a lot!
  • No.1 | | 1307 bytes | |

    amker.cheng@gmail.com wrote:

    But I found in LCC character and short-integer actual arguments are
    always promoted to the coresponding type even in the presence of a
    prototype!(And does there any place in it did similar thing?)
    So I have to use 2 8bit regsters for a char type argument!

    chars are probably promoted to int when they're passed to a function.
    LCC is mostly a K&R C compiler and, if my memory is correct, I don't
    think they support ANSI prototypes? Maybe it only lets you declare the
    return types of functions in the declaration that precedes the function
    implementation?

    You might also want to look at the TCC compiler if you can select a
    compiler of your choice. Also, the SDCC compiler was specifically
    designed to target small devices.

    TCC produces an internal code which is then translated to native code.
    I like this model because its easier to work with. And the TCC source
    looks easier to read.

    I think SDCC uses a yacc type of tool to assist in parser generation,
    and this can be harder to work with if you don't have a good feel for
    BNF. But if your task is to write a code generator for another
    processor, then you shouldn't have to mess with the front-end.

    Eric

  • No.2 | | 1985 bytes | |

    amker.cheng@gmail.com wrote:
    Just a student project !Porting porting LCC to a 8 bit microcontroller
    with which char is 8 bit and int is 16bit.
    But I found in LCC character and short-integer actual arguments are
    always promoted to the coresponding type even in the presence of a
    prototype!(And does there any place in it did similar thing?)
    So I have to use 2 8bit regsters for a char type argument!This is
    unbearable here!

    The compiler is allowed to do promotions of the arguments.

    If you change the calling conventions, check first if your processor
    needs int to be aligned on an even address. In this case you'll have
    sometimes to insert padding for the arguments placed on the stack, and
    ensure that the frame is always properly aligned (padding at the end).
    Alternatively, if you don't need padding, you should change the vararg
    macros.

    The reason for this behaviour of lcc and many other compilers for
    RISC processors is that the size of int is usually equal to the size
    of the registers, and promotion to int makes faster function calls.
    Unfortunately, this is not the case for your processor.

    I want to change the front end, but not sure. All I have to do is
    change codes for function declarations and definitions in decl.c?
    Further more , in arithmetric computing "char c1,c2; c1 = c1 + c2;"
    does lcc promote char into int? I doubt of it because there isn't an
    dag operator for ADDI1!

    Your problem is C language, and not lcc. Find any book about
    standard (IS/ANSI) C and look at the rules of promotion. Your c1 and
    c2 will be promoted to int, then the sum of the values will be
    computed, and after that the result will be truncated to char. In your
    case it's not a big problem, because all the computations of the
    higher 8 bits will be dead code and the optimizer will remove them in
    one of the phases of compilation.

    Michael
  • No.3 | | 1087 bytes | |

    amker.cheng@gmail.com wrote:
    Just a student project !Porting porting LCC to a 8 bit microcontroller
    with which char is 8 bit and int is 16bit.
    But I found in LCC character and short-integer actual arguments are
    always promoted to the coresponding type even in the presence of a
    prototype!(And does there any place in it did similar thing?)
    So I have to use 2 8bit regsters for a char type argument!This is
    unbearable here!
    I want to change the front end, but not sure. All I have to do is
    change codes for function declarations and definitions in decl.c?
    Further more , in arithmetric computing "char c1,c2; c1 = c1 + c2;"
    does lcc promote char into int? I doubt of it because there isn't an
    dag operator for ADDI1!

    That's because in C all arithmetic (and argument passing) uses promoted
    values. You can find some notes on a solution here

    Searching past posts in this newsgroup may also help.

    lcc's most comfortable on modern 32-bit architectures; it can be
    awkward outside this sweet spot.

  • No.4 | | 642 bytes | |

    amker.cheng@gmail.com wrote:

    Just a student project !Porting porting LCC to a 8 bit microcontroller
    with which char is 8 bit and int is 16bit.
    But I found in LCC character and short-integer actual arguments are
    always promoted to the coresponding type even in the presence of a
    prototype!(And does there any place in it did similar thing?)
    So I have to use 2 8bit regsters for a char type argument!This is
    unbearable here!

    Do you have the book about LCC? It will require a little more work
    than using the existing rules, but it should be possible, even as a
    student project.
    -- glen

  • No.5 | | 243 bytes | |


    amker.cheng@gmail.com wrote:
    Just a student project !Porting porting LCC to a 8 bit microcontroller
    with which char is 8 bit and int is 16bit.
    You can try nwcc (http://nwcc.sourceforge.net) if it fits your need.

Re: Problem involved porting LCC to a 8 bit microcontroller


max 4000 letters.
Your nickname that display:
In order to stop the spam: 6 + 5 =
QUESTION ON "Compilers"

EMSDN.COM