Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
If I have a c program with the main function and it is calling a subroutine in assembly how do I get the parameters passed? It is for SPARC processor. If the parameter is an int I can get it (it is passed in register 24). But if it is a double then it is not going to register 24 (probably because it is a double and does not fit in a register). How can I get the double that is passed in as a parameter? Off the stack?

"How can I get the double that is passed in as a parameter? Off the stack?"
That is where the C calling convention says it goes.

"Could you use a pair of regidters?"
The prof. defines how the parameter is passed and the syntax of the function. The prototype must be
int is_negative(double);
Once I get the parameter (the actual double value being passed in) loaded into memory it will be in 2 registers because the registers are 32 bits.
"That is where the C calling convention says it goes."The convention for SPARC assembly I believe is to pass the first 6 arguments in registers %o0 - %o5. Then it will allocate memory on the stack. %fp points to the bottom of the current stack frame. %sp points to the top of the stack frame. That being said I have no idea where in the stack frame the parameters are to be located.
If I look at the memory in the stack frame I can see that my parameters are indeed there if they are ints, but I cant find any double parameters.
if I pass the parameters as doubles and pass the values 1 and -1 the values in the registers are 3F8000000 and BF800000. At first I thought these were memory addresses but they sure can't be in the stack cause the stack pointer is FFBFF838, way higher.
What gives?

I figured out my problem. In the header file for the assembly code the parameter was defined as float instead of double (I had changed it a while ago to run some tests on how parameters are passed and forgot to switch it back to double). Everything works ok now. The double parameter is passed in using 2 registers which is what I thought it was supposed to do to begin with. Thanks for the help Wolfbone and mechanix2GO.

"The convention for SPARC assembly I believe is to pass the first 6 arguments in registers %o0 - %o5."
So it is - my bad !

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |