We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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
You can figure out how a function is called using 'main' as an example. List through STARTUP.A51 to find all references to 'main'. It should be something like 'EXTERN something main something'. After such declaration you should be able to use your function name as operand of CALL.
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?
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.