| 1 |
avremu: An AVR Emulator written in pure LaTeX |
| 2 |
====================================================== |
| 3 |
|
| 4 |
LaTeX is known as a typesetting system. But the underlying TeX system |
| 5 |
is a powerful macro processor. In fact, TeX is a Turing-complete |
| 6 |
programming language. TeX can compute anything, that is |
| 7 |
computable. Computeability is a concept from theoretical computer |
| 8 |
science. After visiting a theoretical CS course, you will know that |
| 9 |
there are things that cannot be solved by a machine. Never. Look out |
| 10 |
for the halting problem. So, Turing-complete does not say "It's a |
| 11 |
proper programming language", but more "someone can write a proper |
| 12 |
interpreter for any programming language in it, theoretically". |
| 13 |
|
| 14 |
So back to TeX. To be honest, TeX is a horrible language to code |
| 15 |
in. After writing my master thesis in LaTex, after crafting every |
| 16 |
graphic within with TiKz[1] and pgfplots[2], and after writing my |
| 17 |
first LaTeX package[3], I can honestly say: TeX is the Quasimodo of |
| 18 |
all widely used programming languages. If you can avoid it, avoid it. |
| 19 |
But if you are forced to use it, you can abstract from TeX, since it |
| 20 |
is a "proper" programming language. |
| 21 |
|
| 22 |
Let's say we want to program our document in C on Top of Tex. Then |
| 23 |
there would be the need to interpret the C semantic. Basically we |
| 24 |
would have to write a compiler for C in TeX. Not a very promising |
| 25 |
future, if you start this. But, we can use a normal C compiler to |
| 26 |
compile the C code to some simple platform. Like AVR[4]. Since I have |
| 27 |
other things to do than writing an AVR Emulator in TeX, here it is! |
| 28 |
|
| 29 |
The newest source can be found at https://gitlab.brokenpipe.de/stettberger/avremu |
| 30 |
|
| 31 |
The package is licensed under LPPL 1.3 |
| 32 |
|
| 33 |
You are writing an CPU emulator in TeX, the TYPESETTING system? |
| 34 |
--------------------------------------------------------------- |
| 35 |
|
| 36 |
Yep. |
| 37 |
|
| 38 |
What Microcontroller is emulated? |
| 39 |
--------------------------------- |
| 40 |
|
| 41 |
I aimed for an ATmega8. The AVR platform is an 8 Bit Processor with 16 |
| 42 |
Bit memory addresses. The hardware version is shipped with 1 KByte of |
| 43 |
RAM and 8 Kbyte Flash memory, but of course, the emulated processor |
| 44 |
can handle more memory. |
| 45 |
|
| 46 |
Are you insane? |
| 47 |
--------------- |
| 48 |
|
| 49 |
Not that anybody knows of. |
| 50 |
|
| 51 |
Are all OP codes implemented? |
| 52 |
----------------------------- |
| 53 |
|
| 54 |
Unfortunately not. I'm still missing 5 opcodes (MULS, MULSU, FMUL, |
| 55 |
FMULS, FMULSU), but until now I did not encounter a C file, the |
| 56 |
AVR-GCC emits these opcodes. The fractional multiply opcodes are also |
| 57 |
somewhat arcane. |
| 58 |
|
| 59 |
Is it fast? |
| 60 |
----------- |
| 61 |
|
| 62 |
Ok, you are asking me, whether a CPU simulator written in TeX, that |
| 63 |
simulates an 8-Bit microcontroller is fast? Propably not. On my |
| 64 |
notebook I could achieve 2.5 KHz, so this is a factor 10000 slower |
| 65 |
than the actual hardware with the highest supported clock rate. |
| 66 |
|
| 67 |
----- |
| 68 |
|
| 69 |
[1] http://www.ctan.org/pkg/pgf |
| 70 |
|
| 71 |
[2] http://pgfplots.sourceforge.net/ |
| 72 |
|
| 73 |
[3] http://www.ctan.org/pkg/dataref |
| 74 |
|
| 75 |
[4] http://en.wikipedia.org/wiki/Atmel_AVR |