s3e: fix build break
[calu.git] / 2_isa / conds.tex
1 \section{Conditions}
2
3 Every instruction can be predicated with a condition that will prevent the execution\footnote{The instruction will be executed, but no changes occur.} of the instruction iff the condition is not met. A list of available conditions, including the suffixes for the instruction, is shown in table~\ref{tab:conds}
4
5 Above and below are for unsigned values. Greater and less for signed values.\\
6 \textbf{Note:} The definition of tests of unsigned values (in the context of bits which will be tested) depends on the ISA. x86, AMD64 and AVR defines below (unsigned lower) as carry not set. ARM on the other hand defines below as carry set. We will follow the definition of arm in this manner.
7
8 \begin{table}[ht]
9         \centering
10         \begin{tabular}{|c|c|c|c|}\hline
11                 \textbf{Bitcode}&\textbf{Condition}& \textbf{Bits to test}       &\textbf{suffixes}\\\hline
12                 0000    & not equal / not zero     & ZF = 0                      & nq, nz        \\ \hline
13                 0001    & equal / zero             & ZF = 1                      & eq, zs        \\ \hline
14                 0010    & not overflow             & OF = 0                      & no            \\ \hline
15                 0011    & overflow                 & OF = 1                      & ov            \\ \hline
16                 0100    & not carry / above or eq. & CF = 0                      & nc, ae        \\ \hline
17                 0101    & carry / below            & CF = 1                      & cs, bl        \\ \hline
18                 0110    & not signed / not neg.    & SF = 0                      & ns, nn        \\ \hline
19                 0111    & signed / neg.            & SF = 1                      & ss, ns        \\ \hline
20                 1000    & above                    & (CF == 0 $\wedge$ ZF ==  0) & ab            \\ \hline
21                 1001    & below or equal           & (CF == 1 $\vee$ ZF == 1)    & be            \\ \hline
22                 1010    & greater than or equal    & SF == OF                    & ge            \\ \hline
23                 1011    & less than                & SF != OF                    & lt            \\ \hline
24                 1100    & greater than             & (ZF == 0 $\wedge$ SF == OF) & gt            \\ \hline
25                 1101    & less than or equal       & (ZF == 1 $\vee$ SF != OF)   & le            \\ \hline
26                 1110    & always                   &                             & \texttt{none} \\ \hline
27                 1111    & never                    &                             & nv            \\ \hline
28         \end{tabular}
29         \caption{coding of conditions}
30         \label{tab:conds}
31 \end{table}
32
33 %note: it seams that the definition of conditions on unsigned values depend on the instruction set. below is CF = 1 by x86/amd64 and avr, CF = 0 by arm. when cmp is defined as cmp r1, r2 == r1-r2 == is r1 COND r2 then arm looks more saner. the conditons marked with a X in the bitcode are open for change because of this unclear situation \Large{RFC} \normalsize
34
35 \begin{table}[hpt]
36         \centering
37         \begin{tabular}{|l|c|c|c|c|} \hline
38                 \textbf{Bit} & 3  & 2  & 1  & 0  \\ \hline
39                 \textbf{Flag}& SF & CF & OF & ZF \\ \hline
40         \end{tabular}
41         \caption{Bits in the PSW}
42 \end{table}