dup

Duplicate top operand stack word

Bytecode

Type Description
u1 dup opcode = 0x59 (89)

Stack ..., word => ..., word, word

Description
This pops the top single-word value off the operand stack, and then pushes that value twice - i.e. it makes an extra copy of the top item on the stack.

The top word on the operand stack is duplicated and pushed onto the operand stack.

The dup instruction must not be used unless word contains a 32-bit data type.

This instruction cannot be used to duplicate two-word items (longs or doubles) - use dup2 instead.

Example

; This is like the java expression:
;
;   StringBuffer x = new StringBuffer();
;

; Make a new StringBuffer object and leave a reference to it
; on the stack:
new java/lang/StringBuffer

; [ Stack now contains: objectref ]

dup		; Duplicate the object reference:

; [ Stack now contains: objectref objectref ]

invokespecial java/lang/StringBuffer/<init>()V ; Invoke the object's initializer:

; [ Stack now contains: objectref ]

astore_1 	; Store the objectref in local variable 1.

; [ Stack is now empty. ]

Notes
Except for restrictions preserving the integrity of 64-bit data types, the dup instruction operates on an untyped word, ignoring the type of the datum it contains.