I need to transform 654321 into 654321321, using only DUP2_X1, POP, DUP_X2, POP2. I have a really difficult time with the DUP. Can anyone help?
I tried to go like this: 654321 DUP2_X1 654654321, then POP goes to 65465432, then DUP_X2 we'd have 6543265432... but I don't think I am doing them correctly.
So, basically you want to duplicate the last three elements of the operand stack while keeping all other elements intact and not use local variables nor heap space.
One sequence to achieve this would be
A straight-forward program to test it using the ASM library looks like
and prints
You may look at the
dupinstruction and following sections in JVM specification for further reference.