Dear all, I have a question about jumping to some specific label in other file(in Keil C51 project)
Ex. In file A there is one label named _xxx. In file B can we use
goto _xxx
? (maybe _xxx should be declared as extern, right ?)
The reason why I want this is: We did NOT want to do the tasks before label _xxx because they are wrong...! And unfornately file A is located in ROM and we can not modify it...
So we want to just jump to label _xxx and skip wrong codes....
More detailed information is:
File A located in ROM
... // wrong code here _xxx // label ... // OK code
File B in RAM
ccc // corrected code here goto _xxx // this can skip wrong code in File A
Thus the calling sequence will be: - execute corrected code in File B - jump to ROM code labeled _xxx - execute OK code in File A
Note: We still want to execute the remaining codes after label _xxx in ROM !!!
I'm a bit confused about your terminology.
You use name "goto" which is a keyword in C. But this goto will not allow you to jump out of your current function, because of all issues with stack frames, auto variables, stack cleanup, register variables, ...
For assembler, you can jump anywhere. Since the destination is a fixed location in ROM, you have to give the assembler code the absolute address.
Thanks for your opinion.(I guess I can use "goto" to jump out of current function...)
Is there any way to solve this issue ?
Absolute address of Label _xxx is known and can I use inline assembly in C51 to jump to this address ?
Thanks in advance...
No, it wasn't an opinion, but a representation of limitations of the C goto mechanism. There is a "longjmp" functionality but that is also outside the scope of this issue.
Assembler code can jump to anywhere in the code address space. You just have to make use of the correct absolute address which you might have picked up from listings/map files of the original ROM code.
C code can perform a call (not jump) using a function pointer that have been set to the absolute address. But that requires that stack etc are properly setup and that your current C function perfectly matches all assumptions required at the "reception point". And that the called (not jumped) target never returns, or that it contains a code sequence that returns in a compatible way back to your C function - while still fullfilling all requirements/assumptions about used registers etc.
My opinion is that performing "cut" and "paste" trying to reuse already existing binary code is best done from assembler where you have 100% control of every register etc before jumping into this address. The question here is if you have created a list of all requirements that needs to be fulfilled for this absolute jump to give the expected result.
By the way - you have never mentioned if the code in ROM is compiled code from a C program or is created from hand-written assembler instructions. That makes a big difference when itemizing all requirements that needs to be fulfilled for this jump to give expected result.
The code in ROM is compiled code from a C program.
And the reason why I did not use the redirection way(like Erik said) is: what I want to call is NOT a function, but a piece of code segments in ROM. Thus I can not use RalphReplace() to replace Ralph() !
I have one idea about this issue and maybe you all can give me some opinions...
(1) create .a51 file where .a51 contains: - function C() - The function body of C() is only "jump to the specific absolute address"(I can get it in .m51 file) (2) add this .a51 to my project (3) declare function C() as "extern" (4) In File B, call C()...
Is it possible to solve this issue ?
.... how are you going to get back?
Erik
View all questions in Keil forum