linuxassemblystackx86-64fasm

Is there a way to clone `n` amount of elements on the stack to the stack in x86_64 linux assembly?


Basically you can 'remove' elements from the stack by adding to rsp register n * 8, but if you try the opposite (rsp - (n * 8)) it doesn't work, which seems obvious but still

So if I push to the stack using push like this:

push 10
push 20

So the stack is basically (20; 10), how could I make it (20; 10; 20; 10) without needing to use registers (Because you're limited) or needing to repeat the push

But if it's not possible which is better to use as an alternative, repeating the push or using registers using pop and then pushing them back?


Solution

  • Assuming n and the pushed values are constant: