Computing.Net > Forums > Programming > passing parameters (assembly)

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

passing parameters (assembly)

Reply to Message Icon

Name: geohoffman49431
Date: March 23, 2006 at 07:37:47 Pacific
OS: XP PRO
CPU/Ram: 512 DDR 2700
Product: Generic
Comment:

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?



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: March 23, 2006 at 08:11:51 Pacific
Reply:

Could you use a pair of regidters?


If at first you don't succeed, you're about average.

M2


0

Response Number 2
Name: Wolfbone
Date: March 23, 2006 at 09:27:08 Pacific
Reply:

"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.


0

Response Number 3
Name: geohoffman49431
Date: March 23, 2006 at 10:14:18 Pacific
Reply:

"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?



0

Response Number 4
Name: geohoffman49431
Date: March 23, 2006 at 10:56:32 Pacific
Reply:

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.


0

Response Number 5
Name: Wolfbone
Date: March 23, 2006 at 18:15:13 Pacific
Reply:

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

So it is - my bad !


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: passing parameters (assembly)

Passing parameters from a Vbscripts www.computing.net/answers/programming/passing-parameters-from-a-vbscripts/9529.html

Passing parameter to exe file www.computing.net/answers/programming/passing-parameter-to-exe-file/4717.html

Pass parameter in hyperlink www.computing.net/answers/programming/pass-parameter-in-hyperlink/14184.html