AA, the AVR Assembler

While working on my Plov compiler, intended for the AVR, I wanted to do something simple first. So me and my friend FP decided that an assembler could be of value. The assembler can be used standalone, as an assembler which is fed by a human made source file.
But the assembler can also be invoked and fed by a compiler, thereby eliminating the need to have a separate code generator inside the compiler. More or less like Unix 'as' is used by many a compiler.
The assembler will be based on Plov005.mod and written in Modula-2 with the Mocka compiler. The first thing to do is compose an EBNF formula.

AA, the AVR Assembler : EBNF

During the composition of the EBNF section I hesitated some times if it would be appropriate to introduce some levels of high level languages to the assembler like simpler assignment statements. In the end I decided to omit them. This is an assembler, not a compiler. Not even a simple one.

Program 		= "PROGRAM" Ident Block Ident.
Block 			= {ConstantDeclaration | VariableDeclaration} BlockBody.
ConstantDeclaration 	= "CONST" Ident "=" Number {Ident "=" Number} "END".
VariableDeclaration 	= "DATA" Ident {Ident} "END".
BlockBody 		= "CODE" StatementSequence "END".

StatementSequence 	= Statement { Statement } .
Statement 		= Origin | ( [Label] Opcode [Comment] ) NewLine .
NewLine			= ASCII.LF .
Origin			= "ORIGIN" Expression .
Label			= Identifier .
Comment			= ";" Sentence .
BlockComment		= "COMMENT" StatementSequence "ENDCOMMENT" .
Opcode			= Identifier {Identifier | Expression} .
Sentence		= { {Letter | Digit} } NewLine .

Expression 		= Term {("+" | "-") Term} .
Term 			= Factor { ( "." | "x" | "*" ) | ( "/" | ":" ) Factor} .
Factor 			= Identifier | Number | "(" Expression ")" .
Number 			= Digit {Digit} | HexNumber .
Identifier 		= Letter {Letter | Digit} .
HexNumber		= "$" { HexDigit } { "." { HexDigit } } .
Hexdigit		= Digit | "A" | "B" | "C" | "D" | "E" | "F" .
BinaryNumber		= "#" { BinaryDigit } { "." { BinaryDigit } } .
Digit 			= BinaryDigit | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" .
BinaryDigit		= "0" | "1" .
Letter 			= "a" | "b" | .. | "y" | "z" | "A" | "B" | .. | "Y" | "Z" .
   
The definition for Opcode is a bit clumsy, I guess, but the alternative was to list all 150 mnemonics and that would not make things clearer.
I'm not sure if I need a FUSES section somewhere. But a seperate fuse-editor might be more appropriate. And fuse editing can be done better in a graphical manner. A nice job for Tickel.

Page created on 28 May 2008 and