Hi, below is the code snippet I am using to try out calling as asm func from a C module. What happens is the asmtest func occupies memory location 0000h and C startup code is unable to execute correctly. How can I relocate the asm func to some other location ? ; in asm file asmtest: MOV A, #64 MOV R0,#16 INC A RET END ----------------------- // in C module #include <reg52.h> extern void asmtest(void); void main() { char i = 2; asmtest(); } -----------------------
He's not babbling, or 'babbeling' for that matter. If you bothered to look at the code fragment he's posted you'd understand what he means. Stefan
If you bothered to look at the code fragment he's posted you'd understand what he means it comes to NOP in disassembly Of course it does, if the asm code happens to be linked last. There is NO statement as to where it goes in execution. Erik
Have you considered taking a look at the following example program? http://www.keil.com/download/docs/c2asm2c.zip.asp This is a C-ASM-C example project that should get you started. Jon
Yes, I've looked at the sample. And I tried to do something similar on my own. The problem of control not returning to the next statement after the call to asmtest() function remains. Here is the full code sample I am using : ------------------------------------------ //test.c #pragma SMALL extern void asmtest(void); void main() { char i = 2; asmtest(); //asm func i++; } ---------------------------------------- ;asm.a51 NAME asm ?PR?asmtest?asm SEGMENT CODE PUBLIC asmtest EXTRN CODE (func) RSEG ?PR?asmtest?asm asmtest: USING 0 LCALL func RET END --------------------------------------- //func.c void func() { } ---------------------------------------- On executing the code above in UV2, the call to asmtest function in assembly works out correct, the call to func() a C module also works, but then the RET from the asm module doesn't give control back to the calling main() function as expected. I get series of NOP in disassembly. Any real suggestions nerds ? thanks J
Your program does exactly what you wrote :-) It calls asmtest() inc i to 3 and the leaves to the OS. Your problem is: you don't have any OS what about this:
void main() { char i = 2; while (1) { asmtest(); //asm func i++; } }
The i++ is not executed. When control is supposed to return back to that statement, I get NOP. Meanwhile the c2asm2c sample seems to be in an infinite loop, wherein the main() keeps repeating. after the calls from C to asm & asm to C are over. J
Hmmm, It works correctly on my compiler. It even executes the i++. I'm using the V7.06a tools with the uVision2 debugger. Jon