HC08: When to use RTS in in-line assembly code?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

HC08: When to use RTS in in-line assembly code?

ソリューションへジャンプ
3,558件の閲覧回数
bigmac
Specialist III
Hello all,
 
Consider that we have a C function that consists entirely of in-line assembly code, of the form -
 
void func1(void)
{
  asm {
 
  ; // Assembly code here
 
  }
}
 
The question then arises about the inclusion of a final RTS instruction, or not.  I have seen examples of both.  My best guess is that if the function is called from C there should not be RTS.  But if the function is called by other in-line code (JSR func1), the final RTS should be included.  If this is the case, this would seem to make the calling of the function within both C and in-line assembly mutually excusive.
 
Can anyone clarify the situation for me?  One example is in the start08.c file generated by CW.  The loadByte() function does include RTS.
 
Another couple of questions also arise -
  1. Whether to use asm or _asm for a block of in-line code - what is the difference between the two forms?
  2. What is the correct way to make a comment within in-line assembly code, since the semi-colon has different meanings for C and assembler?

Regards,
Mac

 

Message Edited by bigmac on 2006-09-15 04:39 PM

Message Edited by CrasyCat on 2007-04-13 02:16 PM

ラベル(1)
タグ(1)
0 件の賞賛
1 解決策
1,120件の閲覧回数
CrasyCat
Specialist III
Hello
 
Just my 10 cents here.
 
When a function is implemented as an inline assembly function (contains only inline assembly instructions), you do not have to explicitly generate the RTS or whatever exit code is requested.
The compiler will care about that for you.
 
Only case where you may have to add exit code yourself is if for any reason you want to exit the function some other places.
Anyway in that case also I would recommend to use the standard function exit code and branch to a label at the end of the function.
 
Main advantage of letting the compiler manage function exit code is that compiler knows how the function is invoked and will adjust exit code accordingly.
Exit code may be different depending if function is invoked using a  JSR or directly inlined in the calling function.
 
Just let the compiler manage this all :smileywink:.
 
loadByte is preceded by the pragmas
 
#pragma NO_ENTRY
#pragma NO_EXIT
#pragma NO_FRAME
These pragmas explicitly tells the compiler to generate no entry or exit code. In that particular case the programmer decided to keep whole control over function entry and exit code.
 
I would not use that as a standard.
 
Around your other questions,
asm and _asm have identical behavior. Only difference I know is asm is not accepted if you build with option "Strict ANSI" (-Ansi) activated. _asm will be accepted in strict ANSI mode as well.
 
Comment in inline assembler can be specified in either ANSI C, C++ or assembly syntax.
So you can use:
   ; ...
   // ...
   /* ...  */
 
; and // are valid till the end of the line, whereas /* */ strictly enclosed the text in comment. Anything after */ will not be considered as comment.
 
I hope that helps. 
 
CrasyCat

元の投稿で解決策を見る

0 件の賞賛
3 返答(返信)
1,121件の閲覧回数
CrasyCat
Specialist III
Hello
 
Just my 10 cents here.
 
When a function is implemented as an inline assembly function (contains only inline assembly instructions), you do not have to explicitly generate the RTS or whatever exit code is requested.
The compiler will care about that for you.
 
Only case where you may have to add exit code yourself is if for any reason you want to exit the function some other places.
Anyway in that case also I would recommend to use the standard function exit code and branch to a label at the end of the function.
 
Main advantage of letting the compiler manage function exit code is that compiler knows how the function is invoked and will adjust exit code accordingly.
Exit code may be different depending if function is invoked using a  JSR or directly inlined in the calling function.
 
Just let the compiler manage this all :smileywink:.
 
loadByte is preceded by the pragmas
 
#pragma NO_ENTRY
#pragma NO_EXIT
#pragma NO_FRAME
These pragmas explicitly tells the compiler to generate no entry or exit code. In that particular case the programmer decided to keep whole control over function entry and exit code.
 
I would not use that as a standard.
 
Around your other questions,
asm and _asm have identical behavior. Only difference I know is asm is not accepted if you build with option "Strict ANSI" (-Ansi) activated. _asm will be accepted in strict ANSI mode as well.
 
Comment in inline assembler can be specified in either ANSI C, C++ or assembly syntax.
So you can use:
   ; ...
   // ...
   /* ...  */
 
; and // are valid till the end of the line, whereas /* */ strictly enclosed the text in comment. Anything after */ will not be considered as comment.
 
I hope that helps. 
 
CrasyCat
0 件の賞賛
1,120件の閲覧回数
bigmac
Specialist III
Hello Crasycat,
 
Thank you for your explanation.  On reflection, it may even be "dangerous" to do an in-line exit, without use of the pragmas, since you would need to be aware what the compiler would be pushing onto the stack prior to the in-line, to avoid a crash.
 
I presume that there would be no restriction on this type of function being called either as a C function, or as a JSR within other inline code.  Is this correct?
 
Regards,
Mac
 
0 件の賞賛
1,120件の閲覧回数
CompilerGuru
NXP Employee
NXP Employee
I dont see any problem here.
Note that you cannot call the before mentioned loadByte from C code as this function does expect a very specific stack layout (not C compatible), it is not really a void (*)(void) function. If you call your code from C, you have to implemen the exact C calling convention.

Daniel