Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Assembly function question

Status
Not open for further replies.

electroRF

Member
Hi,
I wanna write an Assembly function asmFunc which takes 3 parameters.

The function will do something and will then call cFunc and would pass the same untouched three parameters to cFunc.

Since the parameters are saved in registers R0, R1, R2, it means that I can simply call cFunc, and cFunc would get the same 3 parameters, right?

Thank you.
 
There could be different calling conventions, which determine how the parameters are passed and what registers can be modified without doing harm. It all depends on the processor and on the compiler.

If you are not going to do anything after cFunc returns, the most efficient way is to jump (goto) to the beginning of cFunc. cFunc will then return to the code that called your function.
 
This is where you really need to know your compiler. I use avr-gcc all the time and the documentation and examples are awesome. If your compiler does not have a good documentation then you have a really tough job finding things out.

This is summary from the avr-gcc documentation.. maybe it gives you some idea about what you have to find out for your compiler:
  • Arguments - allocated left to right, r25 to r8. All arguments are aligned to start in even-numbered registers (odd-sized arguments, including char, have one free register above them). This allows making better use of the movw instruction on the enhanced core.
If too many, those that don't fit are passed on the stack.

Return values: 8-bit in r24 (not r25!), 16-bit in r25:r24, up to 32 bits in r22-r25, up to 64 bits in r18-r25. 8-bit return values are zero/sign-extended to 16 bits by the called function (unsigned char is more efficient than signed char - just clr r25). Arguments to functions with variable argument lists (printf etc.) are all passed on stack, and char is extended to int.


Since the parameters are saved in registers R0, R1, R2, it means that I can simply call cFunc, and cFunc would get the same 3 parameters, right?

If the documentation says so.. yes. Try it.. be brave. You do debug your code don't you (with a simulator or JTAG etc.)?

Edit: For some reason I have a feeling:"do you really need to do this?".. I have read your previous posts and if this is related to them, then I think you are not solving any problems.. you are creating new ones.
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top