\documentclass[11pt]{article}
\usepackage{a4wide,times,verbatim}

\title{{\sc BaD :\\A Basic language compiler\\
for the TMS320\,C31 Dsp}}
\author{Fran\c{c}ois Auger\thanks{I am 33 years old. I learned 
programming when I was 14 on a small 6502 board. After an engineer 
degree in mechanical engineering and automatic control, I made a PhD
on Signal Processing. Now I am a university professor at the 
University of Nantes, and I teach Signal Processing, Computer Science
and Electronics. I wrote a textbook in Signal Processing, and
a \textsc{Matlab} toolbox for time-frequency analysis of 
non-stationary signals. My research activities are now active 
vibration suppression, active harmonic rejection in power networks, 
and sensorless control of AC machines.}\\
GE\,44-LRTI, Center for Research and Technology Transfer (CRTT),\\
Bd de l'Universit\'e, BP 406, 44602 Saint Nazaire cedex, France\\
home page : {\tt http://crttsn.univ-nantes.fr/$_{\widetilde{ }}$\,auger}\\
e-mail~: {\tt francois.auger@ge44.univ-nantes.fr}}
\date{\today}

\begin{document}
\maketitle

The TMS 320\,C31 floating point DSP is a very interesting and powerfull
processor. With the forthcoming C33, such tools should bring
solutions to industrial problems which were technically impossible (or too 
expensive) to solve up to now in signal processing, control and 
instrumentation applications.

I first bought a starter kit, learned to use it, and then tried to 
explain it to students, in technical, engineer and PhD degrees.
All these students found it too difficult to use, either in assembler 
or in C.

Hence, large signal processing or control algorithms will be 
efficiently programmed in assembler, but this requires many hours
of work for someone which will mainly write \emph{one} program.
One reason which makes the C31 difficult to overcome for engineer 
students is the non orthogonality (not all adressing modes are 
allowed with all instructions). Things must then be done with care,
or require trial and error loops. In addition, a small algorithm 
modification can lead to an important rewriting of the assembler code.

Choosing the C language is an alternative (but loosing some 
efficiency), but this requires to learn the C language, something that
the french physicians or electronicians don't learn enough in France.
In addition, one may ask if using the C language is a good choice
when instructions such as
\begin{center}
{\tt volatile int *PBASE=(volatile int *) 0x808000 ;}
\end{center}
have to be used and understood, or when interrupts are needed.

As a conclusion, I have been deceived by the results of my students
working on this DSP more deeply than just clicking on the ``code 
generation'' button of the \textsc{Matlab/Simulink} software to generate 
C code and send it to a \textsc{Dspace} card. Some efforts must be 
made to make this product more accessible to unspecialized programmers.

For this reason, I decided to write a Basic Compiler, which generates
assembler code from a clearly readable language, as easy to learn as
the Visual Basic or the \textsc{Matlab} languages. A good example of 
this approach is the 
\textsc{Basic Stamp}\footnote{see \texttt{http://www.parallaxinc.com}}, 
a PIC microcontroller
so easy to use that since I use it for teaching microcontrollers,
my students come on saturdays to play with it. After many hours
and nights, my compiler (which runs under windows 95.) is near 
to be in a satisfying state.
I showed it to several students and engineers, who found it very
interesting. The main characteristics of this compiler are
\begin{itemize}
\item Easy variable declarations, including arrays~:
\begin{center}
\begin{tabular}{l}
\texttt{var x float 0, 0}\\
\texttt{var k int}
\end{tabular}
\end{center}
\item Easily written arithmetic operations on variables~:
\begin{center}
\begin{tabular}{l}
\texttt{x(1) += z * y(k)}\\
\texttt{k += 1}
\end{tabular}
\end{center}
\item Use of labels, allowing jumps (\texttt{goto}), subroutine calls
(\texttt{gosub}) and conditional jumps such as
\begin{center}
\texttt{if x(0)==x(1) thengoto loopstart}
\end{center}
Some reserved labels also allow an easy use of interruptions.
\item Possibility to include assembler instructions, allowing 
subroutines to be efficiently written by a specialist, and called
by \texttt{Basic} instructions written by a student or a new user.
\end{itemize}

Two examples of Basic programs, and the assembler codes generated by
my compiler are shown below.

I wrote my compiler to allow different targets, ie other C31 boards 
than the starter kit, and/or other DSPs such as the C50 or the C240.
My compiler is therefore not dedicated to the starter kit, and could
be used for any other board. It is also possible (for a specialist)
to improve the code generated by the compiler so as to make it more
efficient.

My first wish was to publish this work somewhere, and to make this
compiler freely available. But I thought you 
could be interested to support it, since it makes the C31 easier 
to use, and the C31 DSK more friendly for students. You could for 
example be interested to freely distribute my compiler, combined with 
an extended user's guide in pdf format. 
You may also have other ideas \ldots

You may also be interested to support the writing of basic compilers 
for other DSPs, such as the C50 or the C240.

\newpage
%\noindent\hrulefill
\begin{footnotesize}
\verbatiminput{pgcd.bad}
\noindent\hrulefill
\newpage
\verbatiminput{pgcd.asm}
\noindent\hrulefill
\newpage
\verbatiminput{sinus8i.bad}
\noindent\hrulefill
\newpage
\verbatiminput{sinus8i.asm}
\end{footnotesize}
\noindent\hrulefill
\newpage
\end{document}

