This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Override / replace multiplication routines from library

Hello,

I am developing an 8051 system / chip where I want to put the multiplication/division routines in a ROM.
The real program should then call these routines instead of adding the library to the code.

For UART I exchange/override the getchar/putchar library routines with own ones.
Is such an approach also possible for the multiplication routines?

The fallback method would be to define all possible multiplications/divisions as functions. And replace all * / with rom function calls. This increases the call overhead and I would write the code in a special style. This is what I want to avoid.

Thanks and BR, Joachim

Parents Reply Children
  • The above issue is a reason why time-critical routines are often copied to RAM - then every build may redefine the memory mapping. But the linker will insert code that will copy a freshly compiled function from flash to RAM for every new project build.

    When instead having function code that is not recompiled, then you will always have a huge number of issues with more or less documented dependancies.

  • you need to compile the two together and locate as you need. Then split the .hex to load

    I have already thought about this.
    But faced the problem, how do I make sure that the code does not change on the next compile.

    what do you care, just load both every time

  • Depends - if ROM really is ROM then there might not be a second chance :p

  • ROM is really ROM :(
    And I do not have enough RAM (area issues) where I could load the program to :(

    Maybe I could include the assembler code of the ROM every time I compile the Flash contents?
    So that the compiler/linker is aware of the already used memory locations by the ROM.

    In this case it would be good to reduce the available size of idata for ROM code to a small range.
    Is there an automatic way to achieve this?
    Some setting, pragma, ...?

    Thanks and BR, Joachim

  • But how little RAM do you have - note that there are options to just run individual functions in RAM. The linker can set up the binary so that the C runtime library will copy the code implementation for specific functions into RAM at the same time as it initializes global variables.

    This is regularly used when an ISR or maybe a DSP inner loop is extremely time-critical - RAM normally represents the fastest memory region available.

    Just that not all processors can run code from RAM. And some processors might have lots of RAM but only some of it able to run code - it's a question of caching and interaction with the pipeline.

  • Hello,

    That's a good idea. At least for multiplication this should be possible.

    Nevertheless I already got it to run in a different way.
    I utilized a union located at a fixed position and size (reserved in both program parts) containing structs for each function in ROM for parameter passing
    and the functions should only use R0-R7 (checked manually in assembly code - maybe there is an automatic way?).
    The only critical thing is if R0-R7 hold variables in the calling program part that are overwritten (Compiler does not know which registers are modified).
    Until now I could not see a problem, but maybe somebody has here a better experience with that.
    If this does not work the solution would be to switch the register bank and reserve this bank iram locations as fixed global variables in the flash image.

    Many thanks for your help and suggestions.
    BR, Joachim