![]() |
Access variable within inline asm
Is there a way to access a local variable via inline assembly? I'm working on a Solaris machine with g++. What I'd like to do is this:
:
long myWrapper(long *value1, long value2)So basically I'm going through this assembly algorithm, and the value I want to return from the function is in a particular register in the middle of the algorithm. Any thoughts? Thanks in advance. |
This sort of thing will work:
:
#include <iostream> |
Thanks DaWei. This is for SPARC assembly, so the syntax is different and I'm not sure I can reference variable names within inline asm with my compiler.
But I found a similar solution: :
register int tmp asm("l2");I guess this allocates my local variable to the contents of register %l2, which is a local register for SPARC. I can modify that register in the asm block and the change is made to the variable as well. :) |
Whatever woiks, see my sig :D. I judge you'd be interested in exploring the means by which your compiler passes values to, and returns values from, functions. It comes in handy in mixed-language programming. I can't really discern your level of familiarity from the posts thus far; if you'd like some material on a generic (but fairly common), stack-based method, I can probably dig something up.
|
Certainly. I've read a little bit about "function preludes/prologues" with regard to pushing parameters onto the stack, etc. Don't recall much about return values, other than maybe having dedicated registers (i.e., eax on Intel?) for return values...?
But anyways, yeah I'm always interested in building up the bookmark list with some good docs/tutorials for rainy days, if you happen to have anything around... Thanks. |
Nothing so formal. If you've read that, it's probably old news. You'd be surprised, though, how many people don't really understand how parameters are passed or WHY local values disappear when a function returns. Of course, there's nothing in the language standards specifiying that a stack be used, but it's a very common implementation. Some stacks grow downwards, some upwards, some move the pointer before the storage, some after, and some micros don't have a stack at all.
You are correct about the return in the case of the x86 C/C++ platform. Some languages allow multiple returns of any type object, so those are usually stack-based, also. Anyway, here it is, maybe someone can get some insight from it. I hope it reproduces the spacing properly. :
GENERIC STACK-USAGE METHOD |
| All times are GMT -5. The time now is 6:09 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC