Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebAssembly: Duplicating the top of stack

There is not dup instruction, one that lets me duplicate the top of the stack. Which instruction sequence can I use to replicate this behavior?

like image 548
2080 Avatar asked Aug 09 '18 13:08

2080


1 Answers

Wasm doesn't have stack juggling primitives because it has locals. To duplicate the top of the operand stack you need to define a local variable of the right type. Then you can e.g. use the following instruction sequence:

(tee_local $x) (get_local $x)

where $x is your variable.

like image 76
Andreas Rossberg Avatar answered Jan 04 '23 02:01

Andreas Rossberg