The title may be a little unclear, so here is a clarification:
The problem:
a = b + c * d;
which in my implementation is resolved to those two "instructions"
mul(c, d, temp)
add(b, temp, a)
I am currently using temporary objects to store the temporary values, which mandates the storing of the temporary value in RAM and fetching it again when it is needed, both of which are not really needed and lower performance.
I am implementing the VM in C++, so my question is if there is some portable way to avoid the storage of temporary values into main memory but keep them on the actual CPU register?
I've done some testing with using the register keyword, but judging from the lack of performance improvement, I'd say the compiler is ignoring it.
As a last resort, I am willing to go for platform specific assembly, but I am pretty much in the dark on the subject, so if this is the only possible way, good info is welcome. I do realize this example I've given is a basic one, and it is more than likely to encounter a situation where a lot of temporary objects are needed, in which case there should be some way to determine how much registers to use and use memory storage for the rest...
Perhaps there is some way to ask for register storage, and if the compiler "runs out of" registers, automatically push the temporaries on the stack? As far as I am familiar with assembly, you "address" specific registers by their name, and I am unclear on how exactly the compiler handles potential register usage conflicts...