0

I am having some problems figuring out how to assign to arrays equal to each other in jasmine. I wish to compile code like the following

array a[1];
array b[1];

a = b;

Now I want an actual copy of b not assigning them to the same thing. Suppose a is in register 0 and b is in register 1

then the following is what I thought would work

aload   1
astore  0

but in fact now if I change b then a will also change. How would I do this in jasmin so that the arrays are distinct e.g.

array a[1];
array b[1];
a[1] = 'a';
b[1] = 'b';
a = b;
b[1] = 'a';
print a; //should print 'b' but prints 'a' currently
print b; //should print 'a' and does currently

Note the code that I have written is correct java, however, this is for a different language.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Vladimir_314159
  • 1,457
  • 1
  • 9
  • 21
  • "now if I change b then a will also change" That would also be true in Java. – sepp2k Dec 01 '18 at 15:35
  • Yes I know I this language is different, I am just compiling for the java virtual machine. In fact, I just compiled the code that I outputted and it is the exact same as the java compilers output, which is, in fact, that problem. Since I am trying to do something difforent. @sepp2k – Vladimir_314159 Dec 01 '18 at 15:38

1 Answers1

1

It's not about Jasmin or bytecode at all.

If you want to copy the contents of the array, call Object.clone with invokevirtual instruction or Arrays.copyOf / System.arraycopy with invokestatic.

apangin
  • 92,924
  • 10
  • 193
  • 247