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
Thank you for advise. I probubly use the manualy "composed" longint, but it will be problem ina function, which returns 3 integers... 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 (accesing via pointer...). Isn't there any trick to reach the registers in C, for example using inline assembly? I have found out one solution, but it is realy awful. To declare a variable in a fixed memory location to the adress of register - something like unsigned char data R0 _at_ 0x00; (I don't remember it now exactly, maybe it is little different). But it's really awful and a warning of "memory overlapping" comes, but it works. What do you think about it? Thanks. Wormik
"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.
in a function, which returns 3 integers" The whole point of the concept of a "function" in all structured programming languages is that it returns a single value. "I can't use global variables, because the called function is in different module" Eh??? The whole point of Global variables is that they are, well, Global - ie, accessible to the whole system!! "I don't want to use structure because it is too slowly (accesing via pointer...)." Have you actually checked? If you use a memory-specific pointer, and locate the structure in DATA space, even pointer-access could be quicker than "direct" access to variables in XDATA! "unsigned char data R0 _at_ 0x00; a warning of "memory overlapping" comes" Of course it does - you are forcing a 'C' variable into the same memory location already occupied by R0 in Bank 0! Your 'C' variable overlaps R0 Bank 0! But what you're doing here is effectively creating a Global variable - which you said you can't do! "but it works" Only by extreme good luck! You have absolutely no guarantee whatsoever that the Compiler won't also be using R0 directly for its own internal purposes. That's precisely why you get the warning about the overlap! Do Not Do This!