\documentclass{report}

\title{Some JVM Instructions}

\begin{document}

\chapter*{Some JVM Instructions}

\small

These tables contain all instructions used in Chapters 5 and 6 and some other ones that
can be useful as optimizations in Assignment 4. We use the dot (.) to separate values 
on the stack, and two-letter variables (\textsl{dd,ee}) to represent double values.
The asterisk (*) in an explanation indicates that there is a longer explanation after
the tables. 

\begin{center}\begin{tabular}{lllll}
\textbf{Jasmin} & \textbf{args} & \textbf{stack} & \textbf{explanation} & \textbf{HEX} \\
\texttt{aload} & var $i$ & $. \rightarrow .V(i)$ & load ref from var $i$ & 19 \\
\texttt{aload\_i} (i=0..3) &  & $. \rightarrow .V(i)$ &  & 2A..2D \\
\texttt{areturn} &  & $.r \rightarrow$ & return ref from method & B0 \\
\texttt{astore} & var $i$ & $.r \rightarrow .$ & store ref in var $i$ & 3A \\
\texttt{astore\_i} (i=0..3) &  & $.r \rightarrow .$ & store ref in var $i$ & 4B..4E \\
\texttt{bipush} & byte $i$ & $. \rightarrow .i$ & push byte $i$ as int & 10 \\
\texttt{d2i} &  & $.\mbox{\textsl{dd}} \rightarrow .i$ & convert double to int & 8E \\
\texttt{dadd} &  & $.\mbox{\textsl{dd}}.\mbox{\textsl{ee}} \rightarrow .\mbox{\textsl{dd}}+\mbox{\textsl{ee}}$ & add double & 63 \\
\texttt{dcmpg} &  & $.\mbox{\textsl{dd}}.\mbox{\textsl{ee}} \rightarrow .i$ & compare if $>$* & 98 \\
\texttt{dcmpl} &  & $.\mbox{\textsl{dd}}.\mbox{\textsl{ee}} \rightarrow .i$ & compare if $<$* & 97 \\
\texttt{dconst\_dd} (dd=0,1) &  & $. \rightarrow .\mbox{\textsl{dd}}$ & push double & 0E,0F \\
\texttt{ddiv} &  & $.\mbox{\textsl{dd}}.\mbox{\textsl{ee}} \rightarrow .\mbox{\textsl{dd}}/\mbox{\textsl{ee}}$ & divide double & 6F \\
\texttt{dload} & var $i$ & $. \rightarrow .V(i)$ & load double from var $i$ & 18 \\
\texttt{dload\_i} (i=0..3) &  & $. \rightarrow .V(i)$ & load double from var $i$ & 26..29 \\
\texttt{dmul} &  & $.\mbox{\textsl{dd}}.\mbox{\textsl{ee}} \rightarrow .\mbox{\textsl{dd}}*\mbox{\textsl{ee}}$ & multiply double & 6B \\
\texttt{dneg} &  & $.\mbox{\textsl{dd}} \rightarrow .-\mbox{\textsl{dd}}$ & negate double & 77 \\
\texttt{dreturn} &  & $.\mbox{\textsl{dd}} \rightarrow$ & return double from method & AF \\
\texttt{dstore} & byte $i$ & $.\mbox{\textsl{dd}} \rightarrow .$ & store double in var $i$ & 39 \\
\texttt{dstore\_i} (i=0..3) &  & $.\mbox{\textsl{dd}} \rightarrow .$ & store double in var $i$ & 47..4A \\
\texttt{dsub} &  & $.\mbox{\textsl{dd}}.\mbox{\textsl{ee}} \rightarrow .\mbox{\textsl{dd}}-\mbox{\textsl{ee}}$ & subtract double & 67 \\
\texttt{dup} &  & $.v \rightarrow .v.v$ & duplicate top (for int) & 59 \\
\texttt{dup2} &  & $.\mbox{\textsl{dd}} \rightarrow .\mbox{\textsl{dd}}.\mbox{\textsl{dd}}$ & duplicate top (for double)* & 5C \\
\end{tabular}\end{center}

\begin{center}\begin{tabular}{lllll}
\textbf{Jasmin} & \textbf{args} & \textbf{stack} & \textbf{explanation} & \textbf{HEX} \\
\texttt{goto} & label $L$ &  & go to label $L$ & A7 \\
\texttt{i2d} &  & $.i \rightarrow .\mbox{\textsl{dd}}$ & convert int to double & 87 \\
\texttt{iadd} &  & $.v.u \rightarrow .v+u$ & add int & 60 \\
\texttt{iconst\_m1} &  & $. \rightarrow .-1$ & push int constant -1 & 02 \\
\texttt{iconst\_i} (i=0..5) &  & $. \rightarrow .i$ & push int constant & 03..08 \\
\texttt{idiv} &  & $.v.u \rightarrow .v/u$ & divide int & 6C \\
\texttt{if\_icmpeq..le} & label $L$ & $.v.u \rightarrow .$ & compare ints on stack* & 9F..A4 \\
\texttt{ifeq..le} & label $L$ & $.v \rightarrow .$ & compare int with 0* & 99..9E \\
\texttt{iinc} & var $i$, byte $c$ &  & increment var $i$ with $c$ & 84 \\
\texttt{iload} & ref $i$ & $. \rightarrow .V(i)$ & load int from var $i$ & 15 \\
\texttt{iload\_i} (i=0..3) &  & $. \rightarrow .V(i)$ & load int from var $i$ & 1A..1D \\
\texttt{imul} &  & $.v.u \rightarrow .v*u$ & multiply int & 68 \\
\texttt{ineg} &  & $.v \rightarrow .-v$ & negate int & 74 \\
\texttt{invokestatic} & method & $.v...w \rightarrow .$ & call static method & B8 \\
\texttt{invokevirtual} & method & $.v...w \rightarrow .$ & call virtual method & B6 \\
\texttt{irem} &  & $.v.u \rightarrow .v\%u$ & remainder int & 70 \\
\texttt{ireturn} &  & $.v \rightarrow$ & return int from method & AC \\
\texttt{istore} & ref $i$ & $.v \rightarrow .$ & store int in var $i$ & 36 \\
\texttt{istore\_i} (i=0..3) &  & $.v \rightarrow .$ & store int in var $i$ & 3B..3E \\
\texttt{isub} &  & $.v.u \rightarrow .v-u$ & subtract int & 64 \\
\texttt{ldc} & int $v$ & $. \rightarrow .v$ & push int constant $v$* & 12 \\
\texttt{ldc2\_w} & double $dd$ & $. \rightarrow .\mbox{\textsl{dd}}$ & push double constant $dd$* & 14 \\
\texttt{nop} &  &  & do nothing & 00 \\
\texttt{pop} &  & $.v \rightarrow .$ & pop int & 57 \\
\texttt{pop2} &  & $.\mbox{\textsl{dd}} \rightarrow .$ & pop double* & 58 \\
\texttt{return} &  & $. \rightarrow$ & return void from method & B1 \\
\end{tabular}\end{center}

\noindent
More explanations:

\begin{itemize}
\item \texttt{dcmpg}, \texttt{dcmpl}: the value left on the stack is 1 if the inequality holds, 0 if the
values are equal, and -1 otherwise.

\item \texttt{dup2}: the instruction duplicates the topmost two words, which can be one double value
or two integer values.

\item \texttt{if\_icmpeq}, \texttt{if\_icmpne}, \texttt{if\_icmplt}, \texttt{if\_icmpge}, \texttt{if\_icmpgt}, \texttt{if\_icmple}
corresponding to $=, \neq, <, \geq, >, \leq$ jump to the label if the comparison holds
between the top-2 integer values on the stack. 

\item \texttt{ifeq}, \texttt{ifne}, \texttt{iflt}, \texttt{ifge}, \texttt{ifgt}, \texttt{ifle} 
corresponding to $=, \neq, <, \geq, >, \leq$ jump to the label if the comparison holds
between the top integer value on the stack and 0. 

\item \texttt{ldc}, \texttt{ldc2\_w}: the constants pushed are stored in the constant pool, and the
actual bytecode argument (after assembly) is a reference to this pool.

\item \texttt{pop2}: the instruction pops the topmost two words, which can be one double value
or two integer values.
\end{itemize}

\end{document}