Information about http://www.circuitcellar.com/avr2006/winners/DE/DE_Abstracts/AT3378_abstract.pdf

Atmel AVR 2006 Design Contest ­…

Tags: compilers and interpreters, evaluation system, example implementation, functional enhancements, intermediate code, language processor, language processors, microcomputer applications, minimum maintenance, parallel fashion, postfix notation, program flow, ram capacity, sec c, serial communications interface, source text, stack machines, text editors, usb interface, user interface software,
Pages: 5
Language: english
Created: Thu Jan 4 15:24:12 2007
Display cached document
Page 1
image
Page 2
image
Page 3
image
Page 4
image
Page 5
image
                                     Atmel AVR 2006 Design Contest ­ AT3378




AVR Components: ATmega88 and ATtiny45
Abstract


                                ForCy

             The Embedded Language Processor

I have developed a technique to embed compilers into systems equipped
with microprocessors. This will provide for minimum maintenance in the
long term when effecting repairs or functional enhancements, since all
the development environment is inside the system.




            Photo 1: Example Implementation of the ForCy


The language offers low implementation cost and high scalability through
modifications and simplification allowing improved program flow. ForCy
is a programming language in a postfix notation similar to the C language
with PostScript syntax. It generates intermediate code for virtual stack
machines. Due to the small RAM capacity, the one-pass processing is
designed to compile into self-programmable flash memory while receiving
source text through a serial communications interface.
The compiler itself is also encoded into intermediate codes and operates
on the interpreter. The entire language processors including compilers
and interpreters can be implemented in 5 kilobytes of code.
An interrupt mechanism is available and it can easily activate tasks
at regular intervals and process multiple tasks in quasi-parallel
fashion.



                                - 1 / 5 -
                                       Atmel AVR 2006 Design Contest ­ AT3378




       @s { } do for break while continue if ifelse case switch of self

       . .. nip swap dup over @ =

       == != < > = ++ -- + - * / % div > & | ^ ~ && || ! min max rand

       sfr =sfr interrupt clk sec

       @c? @c %c %s %d %x



                  List 1: ForCy System Defined Words




The evaluation system is developed as an educational material for
microcomputer applications. This system is programmable with only text
editors and user interface software. To add a USB interface, CDC protocol
is implemented into ATtiny45. RS-232C timing (4800bps) is made by 8bit
timers and the data is transmitted by USI.


The following applications are expected to be available:
   (1) Control of microcomputers in FA systems for a long-term maintenance.

   (2) Customization of behavior for experimental equipment and sequencers.




     Figure 5: ForCy Evaluation System Hardware Block Diagram



                                 - 2 / 5 -
                              Atmel AVR 2006 Design Contest ­ AT3378




ForCy v 0.99 Schematic




                         - 3 / 5 -
                                             Atmel AVR 2006 Design Contest ­ AT3378




//       compile
0xff =err
0 =iptr
{
         lex =len            //         lexical analyzer
         len while

        //        parse
        0 token
        {
                  ':' {               //          register word
                             ' ' %c puts

                             0 code_out                    // iRET
                             cstart 0 1 dic_add =err       // iWRD
                             cptr ++ =cstart               //        keep next entry
                  } case

                  '¥'' {              //      constant
                             1 token number_out
                  } case

                  ';' {      //       register variable
                             vptr 4 1 dic_add =err      // iVAR
                             vptr ++ =vptr
                  } case

                  '[' {                 //        register array
                             vptr 6                        // iARY
                             1
                             {
                                        dup token ']' == nip break
                                        ++
                             } do
                             ++
                             dic_add =err
                             1 atoi vptr + =vptr

                  } case

                  //       default
                  0
                  0 token '=' == nip {
                           ++
                  } if =eq

                  0 dic_find
                  0xff ==
                  0 token isdigit nip && {
                           .. 0 atoi 2
                  } if

                  0xff != {
                           1 >> {
                                        word_out
                                        number_out
                                        variable_out
                                        array_out
                             } of
                  }
                  {
                             .. 0xfe =err         // err: undefined word
                  } ifelse

        } switch .

        err 0xff != nip break
} do

   List 3: Self-Programmed ForCy Compiler (portion)


                                    - 4 / 5 -
                               Atmel AVR 2006 Design Contest ­ AT3378




SysLP:
             movw   zL, cpL
             clr    tH
             lpm    tL, z+          ; get {} block length
             st     -y, zH          ; push {} entry to RS
             st     -y, zL
             add    zL, tL          ; add length to PC
             adc    zH, tH
             movw   cpL, zL         ; skip {} block
             rjmp   CodeNext

SysFor:
             ld     tH, -x
             ld     tL, -x
             adiw   xL, 2
             cp     tL, dtL
             cpc    tH, dtH         ; index==limit?
             brne   SysDo
             adiw   yL, 2           ; exit
             rjmp   CodeNext
SysDo:
             cpi    cpL, 0
             brne   do_nc
             dec    cpH
do_nc:
             dec    cpL             ; PC--
             ld     tL, y
             ldd    tH, y+1         ; copy {} entry
             st     -y, cpH         ; push PC to RS
             st     -y, cpL
             movw   cpL, tL         ; set {} entry to PC
             rjmp   CodeNext
SysDo_:
             ldd    cpL, y+2        ; copy {} entry to PC
             ldd    cpH, y+3
             rjmp   CodeNext

SysBreak:
             movw   tL, dtL
             ld     dtH, -x
             ld     dtL, -x
             or     tL, tH
             breq   brk_end         ; TOS != 0?
             ld     cpL, y+
             ld     cpH, y+         ; pop PC from RS
             adiw   yL, 2
             inc    cpL             ; PC++
             brne   brk_end
             inc    cpH
brk_end:
             rjmp   CodeNext



   List 4: ForCy Interpreter for ATmega88 (portion)




                       - 5 / 5 -