comments comemnts comments
[phd-thesis.git] / appx / bytecode.tex
1 \documentclass[../thesis.tex]{subfiles}
2
3 \input{subfilepreamble}
4
5
6 \begin{document}
7 \input{subfileprefix}
8 \ifSubfilesClassLoaded{\appendix\setcounter{chapter}{2}}{}
9 \chapter{Bytecode instruction set}%
10 \label{chp:bytecode_instruction_set}%
11 This appendix describeds the semantics of the byte code instruction set of \gls{MTASK} (see \cref{chp:implementation}).
12 The byte code instructions are of variable length and automatically encoded and decoded using generic programming (see \cref{sec:ccodegen}).
13 \Cref{tbl:bc_notation} shows the notation convention.
14 \Cref{tbl:instr_task} shows the semantics of all major byte code instructions, shorthand instructions and auxiliary peripherals have been omitted for brevity but have the analogous semantics as their counterparts.
15
16 \begin{table}
17 \caption{Notation convention for the byte code semantics.}%
18 \label{tbl:bc_notation}
19 \centering
20 \begin{tabular}{lll}
21 \toprule
22 variable & meaning & \textnumero{}bytes\\
23 \midrule
24 $fp$ & frame pointer & 2\\
25 $sp$ & stack pointer & 2\\
26 $pc$ & program counter & 2\\
27 $l$ & label & 2\\
28 \midrule
29 $w_r$ & return width & 1\\
30 $w_a$ & argument width & 1\\
31 $i$ & \gls{SDS} or sensor id & 1\\
32 $n$ & number & 1\\
33 $d$ & depth & 1\\
34 \bottomrule
35 \end{tabular}
36 \end{table}
37
38 \begin{landscape}
39 \begin{longtable}[c]{lllll}
40 \caption{Semantics for the bytecode instructions\label{tbl:instr_task}}\\
41 \toprule
42 Instruction & Arguments & Semantics & $sp$ & $pc$\\
43 \midrule
44 \endfirsthead%
45 \caption{Semantics for the bytecode instructions (cont.)}\\
46 \toprule
47 Instruction & Arguments & Semantics & $sp$ & $pc$\\
48 \midrule
49 \endhead%
50 \bottomrule
51 \endfoot%
52 \bottomrule
53 \endlastfoot%
54 \texttt{push} & $n~b_0\ldots b_n$ & $st[sp+i] = s[i]$ {\bf for all} $i\in\{0..n\}$ & $sp+n$ & $pc+2+n$\\
55 \texttt{pop} & $n$ & & $sp\shortminus{}n$ & $pc+2$\\
56 \texttt{rot} & $d~n$ & $rotate\:(d, n)$ & $sp$ & $pc+3$\\
57 \texttt{dup} & & $st[sp] = st[sp\shortminus{}1]$ & $sp+1$ & $pc+1$\\
58 \midrule
59 \texttt{jumpF} & $l$ & & $sp\shortminus{}1$ & $\left\{\begin{array}{ll} pc+1 & \textrm{\bf if } st[sp\shortminus{}1]\\l & \textrm{\bf otherwise}\end{array}\right.$\\
60 \texttt{jump} & $l$ & & $sp\shortminus{}1$ & $l$\\
61 \texttt{jumpSR} & $w_a~l$ & $st[sp\shortminus{}w_a\shortminus{}1]=pc+2$ & & $l$\\
62 \texttt{tailCall} & $w_{a_1}~w_{a_2}~l$ & $rotate\:(w_{a_1}+3+w_{a_2},w_{a_2})$ & $fp$ & $jl$\\
63 & & $fp = fp\shortminus{}w_{a_1}+w_{a_2}$\\
64 & & \multicolumn{3}{p{.75\textwidth}}{{\bf where} $w_{a_1}$ is the width of the current function and $w_{a_2}$ the width of the called function}\\
65 \texttt{arg} & $n$ & $st[sp] = st[fp\shortminus{}1\shortminus{}n]$ & $sp+1$\\
66 \texttt{return} & $w_r~w_a$ & $st[fp\shortminus{}w_a\shortminus{}3+i] = st[fp+1]$ & $st[fp\shortminus{}w_a\shortminus{}3+w_r]$ & $st[fp\shortminus{}w_a\shortminus{}1]$\\
67 & & {\bf for all} $i\in\{0..w_r\}$\\
68 & & $fp = st[fp\shortminus{}w_a\shortminus{}2]$\\
69 \texttt{pushPtrs} & & $st[sp] = sp$ & $sp+3$ & $pc+1$\\
70 & & $st[sp+1] = fp$\\
71 & & $st[sp+2] = 0$\\
72 \midrule
73 \texttt{unOp} & & $st[sp\shortminus{}1] = \diamond{}st[sp\shortminus{}1]$ {\bf for all} $\diamond\in\{\neg\}$ & $sp$ & $pc+1$\\
74 \texttt{binOp} & & $st[sp\shortminus{}2] = st[sp\shortminus{}2] \mathbin{\oplus} st[sp\shortminus{}1]$ & $sp\shortminus{}1$ & $pc+1$\\
75 & & \multicolumn{3}{l}{{\bf for all} $\oplus\in\{+, \shortminus{}, *, /, \wedge, \vee, \equiv, \not\equiv, \leq, \geq, <, >\}$}\\
76 & & \multicolumn{3}{l}{similar for \cleaninline{Real} and \cleaninline{Long} variants}\\
77 \texttt{cast}\textsubscript{f-t} & & $st[sp\shortminus{}1] = cast_{f\shortminus{}-t} (st[sp\shortminus{}1])$ & $sp$ & $pc+1$\\
78 & & \multicolumn{3}{l}{{\bf for all} $f,t\in\{Int, Real, Long\}$}\\
79 % \pagebreak
80 \texttt{mkTask} & \texttt{Stable\textsubscript{n}} & $st[sp\shortminus{}n\shortminus{}1] = node (stable,$ & $sp\shortminus{}n+1$ & $pc+2$\\
81 & & $\qquad\qquad st[sp\shortminus{}1], \ldots, st[sp\shortminus{}n\shortminus{}1])$\\
82 \texttt{mkTask} & \texttt{Unstable\textsubscript{n}} & $st[sp\shortminus{}n\shortminus{}1] = node (unstable,$ & $sp\shortminus{}n+1$ & $pc+2$\\
83 & & $\qquad\qquad st[sp\shortminus{}1], \ldots, st[sp\shortminus{}n\shortminus{}1])$\\
84 \midrule
85 \texttt{mkTask} & \texttt{ReadD} & $st[sp\shortminus{}1] = node (readd, st[sp\shortminus{}1])$ & $sp$ & $pc+2$\\
86 \texttt{mkTask} & \texttt{ReadA} & $st[sp\shortminus{}1] = node (reada, st[sp\shortminus{}1])$ & $sp$ & $pc+2$\\
87 \texttt{mkTask} & \texttt{WriteD} & $st[sp\shortminus{}2] = node (writed, st[sp\shortminus{}1], st[sp\shortminus{}2])$ & $sp\shortminus{}1$ & $pc+2$\\
88 \texttt{mkTask} & \texttt{WriteA} & $st[sp\shortminus{}2] = node (writea, st[sp\shortminus{}1], st[sp\shortminus{}2])$ & $sp\shortminus{}1$ & $pc+2$\\
89 \texttt{mkTask} & \texttt{WriteD} & $st[sp\shortminus{}2] = node (writed, st[sp\shortminus{}1], st[sp\shortminus{}2])$ & $sp\shortminus{}1$ & $pc+2$\\
90 \texttt{mkTask} & \texttt{PinMode} & $st[sp\shortminus{}2] = node (pinmode, st[sp\shortminus{}1], st[sp\shortminus{}2])$ & $sp\shortminus{}1$ & $pc+2$\\
91 \midrule
92 \texttt{mkTask} & \texttt{Repeat} & $st[sp] = node (repeat, st[sp\shortminus{}1])$ & $sp$ & $pc+2$\\
93 \texttt{mkTask} & \texttt{Delay} & $st[sp] = node (delay, st[sp\shortminus{}1])$ & $sp$ & $pc+2$\\
94 \texttt{mkTask} & \texttt{And} & $st[sp\shortminus{}1] = node (and, st[sp\shortminus{}1], st[sp\shortminus{}2])$ & $sp\shortminus{}1$ & $pc+2$\\
95 \texttt{mkTask} & \texttt{Or} & $st[sp\shortminus{}1] = node (and, st[sp\shortminus{}1], st[sp\shortminus{}2])$ & $sp\shortminus{}1$ & $pc+2$\\
96 \texttt{mkTask} & \texttt{Step} $f$ $w_a$ & $st[sp] = node (step, st[sp\shortminus{}1], f, w)$ & $sp$ & $pc+5$\\
97 \midrule
98 \texttt{mkTask} & \texttt{SdsGet} $i$ & $st[sp+1] = node (sdsget, i)$ & $sp+1$ & $pc+3$\\
99 \texttt{mkTask} & \texttt{SdsSet} $i$ & $st[sp\shortminus{}1] = node (sdsset, st[sp\shortminus{}1], i)$ & $sp$ & $pc+3$\\
100 \texttt{mkTask} & \texttt{SdsUpd} $i$ $l$ & $st[sp+1] = node (sdsset, i, l)$ & $sp+1$ & $pc+5$\\
101 \midrule
102 \texttt{mkTask} & \texttt{Interrupt} & $st[sp\shortminus{}2] = node (interrupt, st[sp\shortminus{}1], st[sp\shortminus{}2])$ & $sp\shortminus{}1$ & $pc+2$\\
103 \texttt{mkTask} & \texttt{RateLimit} & $st[sp\shortminus{}1] = node (ratelimit, st[sp\shortminus{}1])$ & $sp$ & $pc+2$\\
104 \texttt{mkTask} & \texttt{TuneRate} & $st[sp\shortminus{}1] = node (tunerate, st[sp\shortminus{}1], st[sp\shortminus{}2])$ & $sp\shortminus{}1$ & $pc+2$\\
105 \midrule
106 \texttt{mkTask} & \texttt{DHTTemp} $i$ & $st[sp+1] = node (dhttemp, i)$ & $sp+1$ & $pc+3$\\
107 \texttt{mkTask} & \texttt{DHTHumid} $i$ & $st[sp+1] = node (dhthumid, i)$ & $sp+1$ & $pc+3$\\
108 \end{longtable}
109 \end{landscape}
110
111 \input{subfilepostamble}
112 \end{document}%chktex 16