Le support aux utilisateurs et les demandes de création de comptes externes doivent être faites depuis les issues du projet GitLab HEFR (https://gitlab.forge.hefr.ch/forge-hefr/gitlab-hefr)

Commit e0262909 authored by Jacques Supcik's avatar Jacques Supcik
Browse files

Initial import

parents
.sconsign.dblite
build/
*.pdf
basename = 'thymio2_vm_asm'
Export('basename')
build_dir = 'build'
SConscript('src/SConscript', variant_dir=build_dir)
doc = Command(
basename +".pdf",
"build/" + basename + ".pdf",
Copy("$TARGET", "$SOURCE")
)
Alias ('install', [doc])
Clean('.', build_dir)
import os
Import('basename')
env=Environment(ENV = {'PATH' : os.environ['PATH']})
env.Replace(PDFLATEX='xelatex')
env.Replace(BIBTEX='biber')
env.AppendUnique(PDFLATEXFLAGS='-synctex=1')
# env.AppendUnique(PDFLATEXFLAGS='-papersize=a4')
env.AppendUnique(PDFLATEXFLAGS='-shell-escape')
doc = env.PDF(basename + '.tex')
env.Requires(doc, Glob('inc/*'))
env.Requires(doc, Glob('fig/*'))
env.Clean(doc, basename + '.synctex.gz')
env.Clean(doc, '_minted-' + basename)
Default(doc)
\documentclass{heiafr-tr}
\usepackage{tikz}
\usepackage{tikzscale}
\usepackage{calc}
\usepackage{xstring}
\usepackage[compact]{titlesec}
\usepackage{enumitem}
\usepackage{hyperref}
%\titlespacing\subsection*{0pt}{1.0ex plus -1ex minus -.2ex}{-\parskip}
\setlist[description]{noitemsep, nosep}
\newenvironment{cbox}{%
\begin{tikzpicture}[xscale=.6, yscale=.5]
\draw [thick](-0.5,0) rectangle (15.5,2);
\draw (0,2.5) node {15};
\draw (15,2.5) node {0};
}{%
\end{tikzpicture}
}
\newenvironment{iBox}[1]{%
\begin{tikzpicture}[xscale=.6, yscale=.5]
\draw [thick](-0.5,0) rectangle (15.5,2);
\draw (0,2.5) node {15};
\draw (15,2.5) node {0};
\foreach \i in {11,...,14} {\draw (15-\i,2.5) node {\i};}
\draw (3.5,0) -- (3.5,2);
\foreach \i in {1,...,4} {\draw (\i-1,1) node {\StrChar{#1}{\i}};}
}{%
\end{tikzpicture}
}
\begin{document}
\frontmatter
\newcommand{\opBox}[2]{
\begin{iBox}{#1}
\draw (5.5,1) node {unused};
\foreach \i in {1,...,8} {\draw (15-\i,2.5) node {\i};}
\draw (7.5,0) -- (7.5,2);
\foreach \i in {1,...,8} {\draw (\i+7,1) node {\StrChar{#2}{\i}};}
\end{iBox}
}
\newcommand{\overflow}{Raises a \texttt{STACK\_OVERFLOW} exception if the stack is full}
\newcommand{\underflow}{Raises a \texttt{STACK\_UNDERFLOW} exception if the stack is empty}
\title{Thymio II Virtual Machine}
\subtitle{Instructions\\and Assembly language}
\author{Jacques Supcik <jacques.supcik@hefr.ch>}
\reportno{SUP-0001-0}
\input{heiafr-tr-title}
%--------------------------------------------------------------------------
\newpage
\thispagestyle{plain}
\par\vspace*{\fill}
Copyright \textcopyright{} 2015 Jacques Supcik
Haute école d'ingénierie et d'architecture de Fribourg\\
Bd. de Pérolles 80 - cp 32\\
1705 Fribourg\\
Switzerland
This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit\\
\url{http://creativecommons.org/licenses/by/4.0/}.
\newpage
\setcounter{tocdepth}{2}
\tableofcontents
\newpage
\mainmatter
\chapter{Introduction}
This document describes the instructions of the Aseba/Thymio~II virtual machine. It is usefull for compiler developpers and for everyone who want to fully understand the Aseba/Thymio~II systems.
For each instruction, we propose a notation that could be used by an assembler. At the time of writing this document, such assembler does not yet exist.
We also give the exceptions that could be raised for each instructions. Please note that the Thymio~II only raise these exceptions if it runs in debug mode.
\chapter{Instructions}
\section{STOP}
\begin{iBox}{0000}
\draw (9.5,1) node {unused};
\end{iBox}
Stops the processing of events
\subsection*{Syntax}
\texttt{STOP}
\subsection*{Exceptions}
None.
\subsection*{Operation}
\begin{verbatim}
Flags[EVENT_ACTIVE_MASK] := 0;
\end{verbatim}
\subsection*{Usage}
n/a
%--------------------------------------------------------------------------
\newpage
\section{SMALL\_IMMEDIATE}
Pushes a number between -2048 and 2047 to the stack.
\begin{iBox}{0001}
\draw (9.5,1) node {signed value};
\end{iBox}
\subsection*{Syntax}
\texttt{PUSH <n>}
Where \texttt{<n>} is an integer between -2048 and 2047
\subsection*{Exceptions}
\overflow.
\subsection*{Operation}
\begin{verbatim}
SP := SP + 1;
Stack[SP] := value;
\end{verbatim}
\subsection*{Usage}
n/a
%--------------------------------------------------------------------------
\newpage
\section{LARGE\_IMMEDIATE}
Pushes a number between -32768 and 32767 to the stack.
\begin{iBox}{0011}
\draw (9.5,1) node {unused};
\draw [thick](-0.5,-2) rectangle (15.5,0);
\draw (7.5,-1) node {signed value};
\end{iBox}
\subsection*{Syntax}
\texttt{PUSH <n>}
Where \texttt{<n>} is an integer between -32768 and 32767.
\subsection*{Exceptions}
\overflow.
\subsection*{Operation}
\begin{verbatim}
SP := SP + 1;
Stack[SP] := value;
\end{verbatim}
\subsection*{Usage}
n/a
%--------------------------------------------------------------------------
\newpage
\section{LOAD}
\begin{iBox}{0011}
\draw (9.5,1) node {unsigned index};
\end{iBox}
Loads a 16 bits variable from the memory and pushes it to the stack
\subsection*{Syntax}
\texttt{LOAD <i>}
Where \texttt{<i>} is the index of the variable to be loaded.
\subsection*{Exceptions}
Raises a \texttt{OUT\_OF\_VARIABLES\_BOUNDS} exception if the the index does not represent a valid variable.\\
\overflow.
\subsection*{Operation}
\begin{verbatim}
SP := SP + 1;
Stack[SP] := Variables[index];
\end{verbatim}
\subsection*{Usage}
n/a
%--------------------------------------------------------------------------
\newpage
\section{STORE}
\begin{iBox}{0100}
\draw (9.5,1) node {unsigned index};
\end{iBox}
Pulls a value from the stack and stores it to the memory
\subsection*{Syntax}
\texttt{STORE <i>}
Where \texttt{<i>} is the index of the variable to be loaded.
\subsection*{Exceptions}
\underflow.\\
Raises a \texttt{OUT\_OF\_VARIABLES\_BOUNDS} exception if the the index does not represent a valid variable.
\subsection*{Operation}
\begin{verbatim}
Variables[index] := Stack[SP];
SP := SP - 1;
\end{verbatim}
\subsection*{Usage}
n/a
%--------------------------------------------------------------------------
\newpage
\section{LOAD\_INDIRECT}
\begin{iBox}{0101}
\draw (9.5,1) node {unsigned array};
\draw [thick](-0.5,-2) rectangle (15.5,0);
\draw (7.5,-1) node {unsigned array size};
\end{iBox}
Loads a 16 bits element from an array in memory and pushes it to the stack
\subsection*{Syntax}
\texttt{LOAD [<i>], <n>}
Where \texttt{<i>} is the index of the element to be loaded and \texttt{<n>} is the size of the array.
\subsection*{Exceptions}
\underflow.\\
Raises a \texttt{ARRAY\_ACCESS\_OUT\_OF\_BOUNDS} exception if the the index is greater or equal to the size of the array.
\subsection*{Operation}
\begin{verbatim}
i := Stack[SP];
Stack[SP] := Variables[array + i];
\end{verbatim}
\subsection*{Usage}
n/a
%--------------------------------------------------------------------------
\newpage
\section{STORE\_INDIRECT}
\begin{iBox}{0110}
\draw (9.5,1) node {unsigned array};
\draw [thick](-0.5,-2) rectangle (15.5,0);
\draw (7.5,-1) node {unsigned array size};
\end{iBox}
Pulls a 16 bit integer from the stack and stores it as an element to an array in memory.
\subsection*{Syntax}
\texttt{STORE [<i>], <n>}
Where \texttt{<i>} is the index of the element to be stored and \texttt{<n>} is the size of the array.
\subsection*{Exceptions}
\underflow.\\
Raises a \texttt{ARRAY\_ACCESS\_OUT\_OF\_BOUNDS} exception if the the index is greater or equal to the size of the array.
\subsection*{Operation}
\begin{verbatim}
i := Stack[SP];
Variables[array + i] := Stack[SP - 1];
SP := SP - 2;
\end{verbatim}
\subsection*{Usage}
n/a
%--------------------------------------------------------------------------
\newpage
\section{UNARY\_ARITHMETIC / SUB}
\opBox{0111}{00000000}
\subsection*{Syntax}
\texttt{NEG}
\subsection*{Exceptions}
\underflow.
\subsection*{Operation}
\begin{verbatim}
Stack[SP] := -Stack[SP]
\end{verbatim}
\subsection*{Usage}
n/a
%--------------------------------------------------------------------------
\newpage
\section{UNARY\_ARITHMETIC / ABS}
\opBox{0111}{00000001}
\subsection*{Syntax}
\texttt{ABS}
\subsection*{Exceptions}
\underflow.
\subsection*{Operation}
\begin{verbatim}
if Stack[SP] < 0 then
Stack[SP] := -Stack[SP];
end;
\end{verbatim}
\subsection*{Usage}
n/a
%--------------------------------------------------------------------------
\newpage
\section{UNARY\_ARITHMETIC / BIT\_NOT}
Unary not.
\opBox{0111}{00000010}
\subsection*{Syntax}
\texttt{INV}
\subsection*{Exceptions}
\underflow.
\subsection*{Operation}
\begin{verbatim}
Stack[SP] := ~Stack[SP];
\end{verbatim}
\subsection*{Usage}
n/a
%--------------------------------------------------------------------------
\newpage
\section{BINARY\_ARITHMETIC / SHIFT\_LEFT}
\opBox{1000}{00000000}
\subsection*{Syntax}
\texttt{ASL}
\subsection*{Exceptions}
\underflow.
\subsection*{Operation}
\begin{verbatim}
x := Stack[SP-1] << Stack[SP];
SP := SP - 1;
Stack[SP] := x;
\end{verbatim}
\subsection*{Usage}
n/a
%--------------------------------------------------------------------------
\newpage
\section{BINARY\_ARITHMETIC / SHIFT\_RIGHT}
\opBox{1000}{00000001}
\subsection*{Syntax}
\texttt{ASR}
\subsection*{Exceptions}
\underflow.
\subsection*{Operation}
\begin{verbatim}
x := Stack[SP-1] >> Stack[SP];
SP := SP - 1;
Stack[SP] := x;
\end{verbatim}
\subsection*{Usage}
n/a
%--------------------------------------------------------------------------
\newpage
\section{BINARY\_ARITHMETIC / ADD}
\opBox{1000}{00000010}
\subsection*{Syntax}
\texttt{ADD}
\subsection*{Exceptions}
\underflow.
\subsection*{Operation}
\begin{verbatim}
x := Stack[SP-1] + Stack[SP];
SP := SP - 1;
Stack[SP] := x;
\end{verbatim}
\subsection*{Usage}
n/a
%--------------------------------------------------------------------------
\newpage
\section{BINARY\_ARITHMETIC / SUB}
\opBox{1000}{00000011}
\subsection*{Syntax}
\texttt{SUB}
\subsection*{Exceptions}
\underflow.
\subsection*{Operation}
\begin{verbatim}
x := Stack[SP-1] - Stack[SP];
SP := SP - 1;
Stack[SP] := x;
\end{verbatim}
\subsection*{Usage}
n/a
%--------------------------------------------------------------------------
\newpage
\section{BINARY\_ARITHMETIC / MUL}
\opBox{1000}{00000100}
\subsection*{Syntax}
\texttt{MUL}
\subsection*{Exceptions}
\underflow.
\subsection*{Operation}
\begin{verbatim}
x := Stack[SP-1] * Stack[SP];
SP := SP - 1;
Stack[SP] := x;
\end{verbatim}
\subsection*{Usage}
n/a
%--------------------------------------------------------------------------
\newpage
\section{BINARY\_ARITHMETIC / DIV}
\opBox{1000}{00000101}
\subsection*{Syntax}
\texttt{DIV}
\subsection*{Exceptions}
\underflow.\\
Raises a \texttt{DIVISION\_BY\_ZERO} exception if the element at the top of the stack is zero.
\subsection*{Operation}
\begin{verbatim}
x := Stack[SP-1] / Stack[SP];
SP := SP - 1;
Stack[SP] := x;
\end{verbatim}
\subsection*{Usage}
n/a
%--------------------------------------------------------------------------
\newpage
\section{BINARY\_ARITHMETIC / MOD}
\opBox{1000}{00000110}
\subsection*{Syntax}
\texttt{MOD}
\subsection*{Exceptions}
\underflow.\\
Raises a \texttt{DIVISION\_BY\_ZERO} exception if the element at the top of the stack is zero.
\subsection*{Operation}
\begin{verbatim}
x := Stack[SP-1] % Stack[SP];
SP := SP - 1;
Stack[SP] := x;
\end{verbatim}
\subsection*{Usage}
n/a
%--------------------------------------------------------------------------
\newpage
\section{BINARY\_ARITHMETIC / BIT\_OR}
\opBox{1000}{00000111}
\subsection*{Syntax}
\texttt{OR}
\subsection*{Exceptions}
\underflow.
\subsection*{Operation}
\begin{verbatim}
x := Stack[SP-1] | Stack[SP];
SP := SP - 1;