SPARC v8: local registers usage

129 Views Asked by At

I am using assembly program mixed with high level language. Can I use a local registers (l0 to l7), for programming? As I have two observations.

  1. Machine code generated by compiler don't have local registers.
  2. Register l0 to l3 used by trap model.

Considering the above two points, can I use the local register for assembly programming?

Thanks in advance.

1

There are 1 best solutions below

0
Jousboxx On

First of all, if you haven't already, have a look at this wheel diagram: https://icps.u-strasbg.fr/people/loechner/public_html/enseignement/SPARC/sparcstack.html It's taken from the SPARC V8 architecture manual and shows how the in, out, and local registers work.

There are two main takeaways from this diagram.

  • The in registers of one register window overlap with the out registers of the next window. This can be used to pass parameters from caller functions to callees.
  • The local registers for each window do not overlap with anything, so you can use them however you want without them being clobbered by other functions. Even if local registers have to be reused in hardware due to a call stack deeper than the number of physical windows, the local register values should be restored transparently via traps on window changes.

In short, the answer to your question is yes, you can use the local registers for assembly programming.

To address your observations:

  1. Compilers will sometimes generate assembly that uses input and output registers over locals. I'm not sure why this is exactly, but I have observed the same thing on "toy" programs. If you add more variables and/or use higher optimization levels, it will likely start using locals. Remember that the i and o registers are also general purpose and can be used for more than just passing params.
  2. I suspect you're mistaken here. How did you come to this conclusion?

Hope this helps. This is mostly from memory and I haven't worked on SPARC within the past year, so I welcome corrections.