0

I'm using the SPARC architecture. I have to update the number of a long passed as an argument without returning it, but I don't know how to do that because the input registers are used for both the parameters and for returning a value. I've seen from using instructions such as

add   %l0, %l1, %i1

that it's possible to modify the contents of an i register, but as far as I can tell that changes the "copy" of the parameter rather than the parameter itself. I've experimented with the load command and store command in ways such as

ld    [%o1], %i1

and

st    %l1, [%fp-8]

and they don't seem to change what I need to be changed.

Rez
  • 187
  • 12
  • You need to know what is in the register beforehand and how it works ld - load a word and st - store a word. Try reading this article [link] (http://stackoverflow.com/questions/23402899/sparc-assembly-load-and-store) – Ting Shun Ng Feb 08 '16 at 06:52
  • I did some research and figured out that the save function makes the arguments available in the input registers, but I still don't know whether to use the frame pointer or the expected i register for storing. – Rez Feb 09 '16 at 05:42

1 Answers1

0

I figured it out. The save instruction makes the argument available in an in register (in my case, %i1), and from there it's just

st %l1, [%i1 + 1]

and I have to make sure the number in place of 4 is compatible with the number of bytes between the elements of the array. So in this case +1 works for a char array.

Rez
  • 187
  • 12
  • A store *doesn't* modify any registers. So it can't change what's available in a register. If the caller wants you to write to memory, then do this, but that's not a normal return value. – Peter Cordes Feb 09 '16 at 14:56
  • Yes, that's my intention. I had to do a modification for this, and then make something else the return value. – Rez Feb 09 '16 at 19:28