Work / Virtual Machine / Instruction Set

2012-01-14 21:38:00

Structural

The following constitute the subset of instructions that manage the structural operation of a program. Specifically they allow for the passing of control to (and return from) other sections of code.

For more information on how the stack is managed in regards to these instructions, please see the page about stack semantics.


NOP (NO OPERATION)

Usage:

1
2
3

nop ; no operation
 

Operation:

  • No operation - does nothing. EIP is merely incremented to point to the next instruction.

ENTR (ENTER STACK FRAME)

Usage:

1
2
3

entr    n ; enter stack frame large enough for n local variables
 

Operation:

  • Pushes the value of the current stack frame base pointer (EBP) onto the stack.
  • Pushes null onto the stack to fill the stack slot that is queried when an exception occurrs within the newly created frame (for more information on exception handling, please refer to the exception handling instructions).
  • Sets the value of EBP to the value of ESP.
  • Increments ESP by the requested size (n) - note: the requested size is in 32bit-wide values, not bytes; so specifying n = 1 would increase ESP by 4 bytes (assuming an architecture where a byte = 8bits).
  • The new values of EBP and ESP are then validated to ensure they point to memory locations within the stack frame. If they do not, an exception is raised.

ENTF (ENTER FUNCTION)

Usage:

1
2
3

entf    n, m ; enter stack frame for n local variables, copying m parameters into the first m frame slots
 

Operation:

  • Performs the same operations as ENTR.
  • Copies the specified number of parameters (m) into the local variables (starting at the zeroth slot) of the newly created frame.

LEAV (LEAVE STACK FRAME)

Usage:

1
2
3

leav ; leave current stack frame
 

Operation:

  • Sets the value of ESP to the value of EBP.
  • Decrements ESP to pop the exception handler address from the new stack top.
  • Pops the previous value of EBP from the stack top into EBP.

CALL (CALL SYMBOL)

Usage:

1
2
3

call    symbol ; call the specified symbol
 

Operation:

  • Pushes the current value of EIP onto the stack.
  • Sets the value of EIP to the address of the specified local symbol.
  • EBP and ESP are then validated.

CLLA (CALL ADDRESS)

Usage:

1
2
3

clla    n ; call the address in the specified local variable n
 

Operation:

  • Pushes the current value of EIP onto the stack.
  • Sets the value of EIP to the address contained in the specified local variable.
  • EBP and ESP are then validated.

Note: The specified address must be absolute.


FARC (FAR CALL SYMBOL)

Usage:

1
2
3

farc    symbol ; call the specified symbol
 

Operation:

  • Jumps execution out of the current context and into the context that contains the specified symbol (native or virtual).

Note: The specified symbol must be external (defined in a separate program or library) to the program that calls it. If the symbol is implemented by another virtual machine program, the stack of the current context is used as if the code issued the CALL instruction. If the symbol is implemented natively, the current context remains unchanged (bar the pushing onto the stack of any values returned from the native implementation).


RET (RETURN VARIABLE)

Usage:

1
2
3

ret n ; push the value of local variable n onto stack and return control to caller
 

Operation:

  • Pops the return address from the stack.
  • Pushes the value of the specified local variable onto the stack.
  • If the popped return address is null, the HALT instruction is executed, otherwise EIP is set to the return address.
  • EBP and ESP are then validated.

Note: The return address is null when execution entered the current context from another separate context and the stack semantics between the two differ. This mostly occurrs when the caller code is implemented natively and the callee code is implemented virtually. This is also the mechanism used by the virtual machine executive to determine when a virtual program has completed its execution.


RETI (RETURN VALUE)

Usage:

1
2
3

reti    n ; push the value n onto the stack the return control to caller
 

Operation:

  • Performs the same operations as RET, but instead pushes the literal value n onto the stack.

RETN (RETURN)

Usage:

1
2
3

retn ; return control to caller
 

Operation:

  • Performs the same operations as RET, but does not push a value onto the stack.

LRET (LEAVE AND RETURN VARIABLE)

Usage:

1
2
3

lret    n ; leave frame and return value of local variable n to caller
 

Operation:

  • Performs the same operations as LEAV.
  • Ten performs the same operations as RET.

LRTN (LEAVE AND RETURN)

Usage:

1
2
3

lrtn ; leave frame and return control to caller
 

Operation:

  • Performs the same operations as LEAV.
  • Then performs the same operations as RETN.

LRTI (LEAVE AND RETURN VALUE)

Usage:

1
2
3

lrti    n ; leave frame and return value n to caller
 

Operation:

  • Performs the same operations as LEAV.
  • Then performs the same operations as RETI.