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

A51 help!

Hi,

I need to be able to call a c function from within the STARTUP.A51 file (actually, any *.a51 file), so that the code listing has the startup code, then the call of this new function, then the LJMP to main.

I imagine this will involve 'exporting' the C function name (label), and using this label as an operand of the asm CALL
instruction, but I can't seem to figure out how to do this.

I'd also be really interested if someone can suggest a more readily understandable assembler manual than the A51 user guide...

Thanks for any suggestions!

David

Parents
  • That was my first thought! But there's no reference to main within the startup asm file. What there is, however, is

    LJMP ?c_start

    Which seems to serve as the jump to main
    instruction.

    I imagine somewhere main is aliased as c_start, but I've no idea where or how this is done. Unfortunatley, I can't seem to get on very well with the A51 user manual, which I imagine is where the answer lies (or maybe the BL51 manual)

    Any thoughts?

Reply
  • That was my first thought! But there's no reference to main within the startup asm file. What there is, however, is

    LJMP ?c_start

    Which seems to serve as the jump to main
    instruction.

    I imagine somewhere main is aliased as c_start, but I've no idea where or how this is done. Unfortunatley, I can't seem to get on very well with the A51 user manual, which I imagine is where the answer lies (or maybe the BL51 manual)

    Any thoughts?

Children
  • You are right: startup.a51 does not call main; instead, it calls Keil's 'C' initialisation stuff, which then calls main.

    ?c_start is the entry point for Keil's 'C' initialisation stuff.

    Back to your original question, you need to read the section Interfacing C Programs to Assembler in Chapter 6 of the C51 User Guide.

    You could also look at the Assembler listing from C51 - that'll show you how 'C' functions are called in Assembler!

    In fact, this is often a good way to start a mixed 'C'+Assembler project - write the "skeleton" in 'C', then work on the generated Assembler.