How to use the assembler A4

From the command line     a4 inputfile
will generate two files :  file.lst  listing and file.s  S-format object code.

The assembler is a two-pass  assembler.   The input file consists of 5 "commands" in the following format :

.s
symbol value
 ...
.a address
.b sym sym ...
.c
:label opcode operand
 ...
.e
operand = #sym sym @sym
sym = numeric symbol label
numeric begins with 0..9
symbol  found in the symbol table

.s  start the symbol defining section.  A symbol is associated with its numerical value.  When the assembler encounters a symbol in the input file it will substitute that symbol with its value.
.a  set the address.  It is used to define a location.
.b  define constant in the memory.  It is useful when building a table of value or to assemble a sequence of values even inside code segment.
.c  code segment.
.e the last line of program

The addressing modes are specified with prefix :
  #  immediate
  @  jump relative
without any prefix the symbolic operand is considered to be direct address.

.s .a .b .c  can occur in any sequence.  Input scanning is case insensitive.  Internally all symbols are converted into uppercase and stored in the symbol table.  No comment fields are allowed.  You can implement one easily using another program to "filter" out all the comments.  For example, a  comment can be defined as anything after  ;; or // until the end of line.

Example

.s
print 1000
stop 1001
half  100
temp  101
temp2  102
base 2
.a  0
.c
:begin
  lds #300
  lds temp
  lda #30
  lda temp
  psh
  sta half
  jmp begin
  jmp @begin
  jpz next
  jpc @begin
  jsr next
  and #20
  and temp2
  pop
  add #40
  add data
  rts
  rol
  ror
:next
  jsr print
 
:data
.b 1 2 3
.e
 
The output S-format file that is ready to be used to write into a EEPROM is :

S113000004012C0C0065141E1C0065203C00644C8B
S1130010000048EC5C002A68E77C002A84148C0009
S113002066A0C428CC002DD0E0F07C03E8010203D4
S9030000FC
 

The main objective of this implementation of a4 assembler is to make it as simple as possible.  The source code is only 200 lines long.  It is a two passes assembler.  The first pass collects all the symbol and counts the address.   The second pass does the actual generation of machine code.   As this is the first release, it is not yet robust.   Please report any bug found to  prabhas@chula.ac.th

20 July 2004
Prabhas Chongstitvatana