This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Getting multiple return values from a function in registers

Is it possible to get multiple return values from a function in a different way than in fixed memory? I often need to get more return values than 1 from a function, for example 2 integers (16bit) and 1 byte, or something similar. In assembly, the easiest way to do that is to pass them through registers. But if the calling function, or both calling and called, are written in C, there is a problem that I can't reach to the registers. So I must pass them in global variables (useless ehausting of memory) or define a structure. But the structure is passed through fixed memory, too, and it is accessed with a pointer, what is too slow. I have tried several tricks, but I have not succeeded.

So I have these questions:
Is there any "standard" way to pass multiple return values in registers IN A C FUNCTION?
or
Is it possible to easily reach registers in C?
or
Is it possible to acces local variables defined in a C function from an inline assembly?


Thanks a lot. If it isn't possible, I will have to use global variables, but this would be a better and faster way.
Wormik

Parents
  • "I can't use global variables, because the called function is in different module"

    That doesn't prevent you from using a global - just declare it as extern in one of the modules.

    "I can't use global variables, because the called function is in different module, and I don't want to use structure because it is too slowly"

    If you use memory space specific pointers things should speed up a bit.

    "Isn't there any trick to reach the registers in C, for example using inline assembly"

    Yes, there are tricks, but if you are writing 'C' code you should not do this. You will get into a terrible mess.

    "But it's really awful and a warning of "memory overlapping" comes, but it works. What do you think about it?"

    Don't do it. It may appear to work, but it is probably screwing something else up.

    Why don't you post the code for your function and a snippet of code surrounding the function call so we can see exactly what you are trying to do.

Reply
  • "I can't use global variables, because the called function is in different module"

    That doesn't prevent you from using a global - just declare it as extern in one of the modules.

    "I can't use global variables, because the called function is in different module, and I don't want to use structure because it is too slowly"

    If you use memory space specific pointers things should speed up a bit.

    "Isn't there any trick to reach the registers in C, for example using inline assembly"

    Yes, there are tricks, but if you are writing 'C' code you should not do this. You will get into a terrible mess.

    "But it's really awful and a warning of "memory overlapping" comes, but it works. What do you think about it?"

    Don't do it. It may appear to work, but it is probably screwing something else up.

    Why don't you post the code for your function and a snippet of code surrounding the function call so we can see exactly what you are trying to do.

Children
No data