





                                                           12-Dec-1987

                                                          Version 1.01







      CAMEXE (a virtual machine which execute CAMAC operations)

                                 and

          CAMASM (a macro assembler for CAMEXE machine code)











                              M. Nomachi



                          KEK on-line group












                                                                Page 2





                                   CONTENTS



        1       INTRODUCTION . . . . . . . . . . . . . . . . . . . . 3

        1.1       Why Virtual Machine  . . . . . . . . . . . . . . . 3

        2       CAMEXE . . . . . . . . . . . . . . . . . . . . . . . 4

        2.1       Internal Registers . . . . . . . . . . . . . . . . 4

        2.2       Addressing Mode  . . . . . . . . . . . . . . . . . 5

        2.3       MOVE Instructions  . . . . . . . . . . . . . . . . 6

        2.4       LOAD Instructions  . . . . . . . . . . . . . . . . 6

        2.5       CAMAC I/O Instructions . . . . . . . . . . . . . . 6

        2.6       Arithmetic Instructions  . . . . . . . . . . . . . 7

        2.7       Branch Instructions  . . . . . . . . . . . . . . . 8

        2.8       Wait Interrupt Routines  . . . . . . . . . . . . . 9

        2.9       Miscellaneous Instructions . . . . . . . . . . . . 9

        3       CAMASM . . . . . . . . . . . . . . . . . . . . . . . 9

        3.1       Running CAMASM . . . . . . . . . . . . . . . . . . 9

        3.2       Input File Format  . . . . . . . . . . . . . . .  10

        3.2.1     Label Field  . . . . . . . . . . . . . . . . . .  10

        3.2.2     Operation Field. . . . . . . . . . . . . . . . .  10

        3.2.3     Operand Field. . . . . . . . . . . . . . . . . .  11

        3.2.4     Assembly Listing Format. . . . . . . . . . . . .  11

        3.3       Evaluation Of Expressions  . . . . . . . . . . .  11

        3.3.1     Expression Operands  . . . . . . . . . . . . . .  11

        3.3.2     Expression Operators . . . . . . . . . . . . . .  12

        3.4       Macro  . . . . . . . . . . . . . . . . . . . . .  12

        3.4.1     Macro Structure  . . . . . . . . . . . . . . . .  12

        3.4.2     Macro Arguments  . . . . . . . . . . . . . . . .  13

        3.5       Assembler Directive Statements . . . . . . . . .  13

        3.5.1     End Statement  . . . . . . . . . . . . . . . . .  13

        3.5.2     Equ Statement  . . . . . . . . . . . . . . . . .  13

        3.5.3     Title Statement  . . . . . . . . . . . . . . . .  14

        3.5.4     Use Statement  . . . . . . . . . . . . . . . . .  14

        3.6       Object File Format . . . . . . . . . . . . . . .  14





APPENDIX A      CAMEXE INSTRUCTION SET ON VAX





APPENDIX B      CAMEXE PROGRAMMING TECHNIQUES



        B.1     INTERRUPT DRIVEN PROGRAM . . . . . . . . . . . . . B-1

        B.2     HOW TO MAKE A HEADER . . . . . . . . . . . . . . . B-1

        B.3     HOW TO DEFINE A READ ZONE ON YOUR BUFFER . . . . . B-2

        B.4     HOW TO READ A BUFFER MODULE (READ CAMAC) . . . . . B-3

        B.5     HOW TO READ A CAMAC-MP (READ TKO)  . . . . . . . . B-3





APPENDIX C      CAMASM ERROR CODE




                                                                Page 3





1  INTRODUCTION



     CAMASM is a macro assembler for CAMEXE(CAMAC operation executer).

CAMEXE  is a virtual machine implemented on VAX/VMS, PC9801/MS-DOS and

MC68020/OS9.  CAMEXE has CAMAC I/O operations as its instructions, and

has some general arithmetic operations as usual micro processors have.

It must be remembered that there is no real micro processor which  can

execute the CAMEXE instruction set.







1.1  Why Virtual Machine



     Fastest access to CAMAC is direct access from data taking program

dedicated  to  an  experiment.   However,  it  is  very  difficult and

dangerous, in most operation systems.  CAMAC I/O routine is driven  by

an interrupt signal, which comes asynchronous to execution of the data

taking program.  It is necessary to register address of the CAMAC  I/O

routine  to  the  interrupt vector.  In most of operating system, only

system programs and  driver  programs  are  allowed  to  register  the

process  to  the interrupt vector.  It may cause a fatal damage on the

operating system to change the interrupt vectors.  CAMAC I/O registers

are  usually  not  mapped to user program in an operating system which

has memory mapping.  However, it may  cause  a  fatal  damage  on  the

operating  system to change the mapping to access CAMAC I/O registers,

because the mapping is under control of the operating  system.   Thus,

access  to  CAMAC should be done in the CAMAC driver process under the

control of the operating system.  Not so many I/O functions are needed

to  the CAMAC driver.  Those are CAMAC single action, Q-stop mode data

read, Q-scan mode data read  etc.   If  the  CAMAC  driver  has  those

functions, a data taking program could be described by the combination

of those functions.



     However, it takes a lot of CPU  time  for  calling  the  driver's

function.  Typical overhead in VMS on micro VAX II is an order of mill

second even for one CAMAC single function.  If a number  of  functions

for  one  event is not so many, such over head can be beard.  However,

most  of  cases  needs  several  operations  for  reading  one  event.

Therefor, the CAMAC driver which can execute the combination of simple

CAMAC functions are needed to reduce the overhead.



     Another problem happens in MS-DOS.  CAMAC I/O routine has  to  be

executed  concurrently  with  user program, because the "event" is not

synchronized to execution of the user program.  MS-DOS, which is not a

multi   task  operating  system,  cannot  execute  two  user  programs

concurrently beside one of those is a device driver.  The CAMAC driver

in  MS-DOS  needs  to  be  able  to execute the various combination of

simple CAMAC functions.



     Thus, the CAMAC driver which execute the combination of primitive

CAMAC  functions  is  needed  on  VAX  and  on  PC9801.  CAMAC deriver

dedicated to each experiment is  very  efficient,  but  will  be  very

difficult  to maintain.  CAMAC driver which interprets a list of CAMAC

operations might be one of the  solutions.   This  approach  has  been

taken  at KEK on VAX-11 and micro VAX.  The list becomes more and more


                                                                Page 4





complicated than a simple list of CAMAC  operations.   Repetition  and

dispatch  are introduced in the latest lists.  Dialect in the list has

generated by some experiment group.   It  was  a  situation  of  CAMAC

driver  at KEK.  Thus, we decide to introduce a new CAMAC driver which

interpret a  new  list.   The  list  looks  like  a  program  (set  of

instructions)  of  a  computer  which  executes CAMAC operations.  The

interpreter or the virtual machine of the instruction set can  realize

branch,  dispatch, conditional branch and arithmetic operations.  That

is a CAMEXE.







2  CAMEXE



CAMEXE is realized on VAX as CAMAC driver called CCDRIVER [1], is also

done  on MC68020/OS-9 as subroutine called CAMEXE [2] and CAMAC driver

called CAMLAMDRIV [3], and will be done on PC-9801/MS-DOS as  a  CAMAC

driver.   OS-9 does not need CAMEXE interpreter to be a device driver,

because OS-9 does not  have  memory  mapping,  and  is  a  multi  task

operating  system.   Those  operating  systems  can  assemble the same

assembler source text into their own binary code and can  execute  it.

CAMEXE on OS9 can execute same binary codes as ones on VAX.







2.1  Internal Registers



     CAMEXE has several working registers and pointers.



     1.  "A"

         A 32 bit Working register.  It is mainly used  for  temporary

         register  of  CAMAC  I/O  and of the information load.  It is

         reset on each event.



     2.  "S"

         A 32 bit Status register.  CAMEXE  returns  contents  of  "S"

         register  to the user program.  CAMEXE on VMS returns it as a

         second long word in IOSB.  It is reset at  beginning  of  the

         execution  of  CAMEXE, but not on each events.  Therefore, it

         can be used to pass information to the  next  event  or  user

         program.



     3.  "T"

         A 32 bit test register.  CAMEXE compares the "T" register and

         the reference value on conditional branch instruction.  It is

         reset on each event.



     4.  "PC"



[1]  CCDRIVER reference manual, Y.   Yasu  (KEK  online  group),  1987

    KOL-xxx.

[2]  CAMAC on OS-9 with CES8210, M.  Nomachi (KEK online group),  1987

    KOL-xxx.

[3]  OS9 ESONE  CAMAC  implementation  for  OPAL,  C.   Beard  (CERN),

    28-Aug-1987


                                                                Page 5





         A program counter on CAMEXE.  It is a  word  pointer.   First

         instruction  is in location 1, not in 0.  It is preset to one

         at the beginning.



     5.  "TOP"

         A word pointer on user buffer.  It points first word  of  the

         event.  It is cot accessible by CAMEXE instructions.



     6.  "PTR"

         A word offset from the word pointed by "TOP".  It is equal to

         number  of  words  written  by  the event.  On the end of the

         event, "TOP" is added by "PTR" which is  a  number  of  words

         written  by  the event, and "PTR" is reset to zero.  For each

         event, "PTR" is a word pointer for the  user  buffer  of  the

         event.   It  is not necessary to care about absolute position

         in the user  buffer.   Only  "REMAINDER"  can  tell  absolute

         position in the user buffer.



     7.  "REMAINDER"

         Number  of  remained  words  on  user  buffer.   "RED   ZONE"

         mechanism can be realize by testing "REMAINDER".



     8.  "TIMER":

         System clock.  Its format depends on operating systems.



     9.  "COUNT"

         Event count.  It is reset on the beginning of the buffer, and

         incremented  on  each  event.   Therefore,  it is not a total

         event count, but a count of event written on the buffer.



    10.  "CAMACSTATUS"

         A CAMAC status word.  It can be assigned to  hardware  status

         register.  Therefore its format depends on operating systems.









2.2  Addressing Mode



     The following addressing modes are supported by CAMEXE.



     1.  Internal registers        Read/Write     A,S,T



     2.  User buffer               Write only     (PTR)+



     3.  Immediate data            Read only      #data



     4.  Header area               Read/Write     HEADER(n)



     5.  CAMAC                     Read/Write     (f,n,a)



HEADER(n) means "n"th word in the event.  HEADER(1) is a first word in

the event.


                                                                Page 6





2.3  MOVE Instructions



"MOVE" instructions can transfer the data from one place  to  another.

"A","S"  and  "T"  registers,  user buffer, Immediate data, and header

area can be used as source or destination.  The following table  shows

combinations  of  source and destination supported in MOVE operations.

"---" means the combination is not supported.  "L" means only  32  bit

transfer  is  supported.  "W" means only 16 bit transfer is supported.

"W(L)" means 32/16 bit transfers are supported, but 16 bit  one  is  a

default  one.   Mnemonics of 32 bit transfer is described as "MOVE.L".

Mnemonics of 16 bit transfer is described as "MOVE.W".   If  you  omit

".L" nor ".W", the data size defined im the following table or default

size is used.



source\destination    A         S         T       (PTR)+  HEADER(n)

                 +---------+---------+---------+---------+---------+

              A  |   ---   |    L    |    L    |   W(L)  |    W    |

                 +---------+---------+---------+---------+---------+

              S  |    L    |   ---   |    L    |   ---   |   ---   |

                 +---------+---------+---------+---------+---------+

              T  |    L    |    L    |   ---   |   ---   |   ---   |

                 +---------+---------+---------+---------+---------+

          #data  |    L    |    L    |    L    |   W(L)  |    W    |

                 +---------+---------+---------+---------+---------+

       HEADER(n) |    W    |   ---   |   ---   |   ---   |   ---   |

                 +---------+---------+---------+---------+---------+







2.4  LOAD Instructions



Other internal registers should be loaded into  the  "A"  register  by

LOAD instructions.  The following registers are accessible.



     1.  LOAD PTR             get number of word written on the event.



     2.  LOAD REMAINDER       get remained word in the user buffer.



     3.  LOAD TIMER           get time.



     4.  LOAD COUNT           get event count.



     5.  LOAD CAMACSTATUS     get CAMAC status.



"PC" and "TOP" is not accessible.







2.5  CAMAC I/O Instructions



16 bit transfer is default in CAMAC I/O.   24  bit  transfer  must  be

described  as xxx.L.  ".L" means 24 bit transfer.  16 bit transfer can

be described as xxx.W explicitly.  All CAMAC actions are done  on  the

current crate, which can be changed by SETCRATE instructions.


                                                                Page 7





     READ     (f,n,a)              CAMAC --> (PTR)+

     READ     (f,n,a),A            CAMAC --> A

     WRITE    #data,(f,n,a)        #data --> CAMAC

     WRITE    A,(f,n,a)            A     --> CAMAC

     NDT      (f,n,a)              no data transfer

     GENC                          generate CAMAC "C"

     GENZ                          generate CAMAC "Z"

     REMI                          remove inhibit

     SETI                          set inhibit

     SETCRATE A                    A  -> current crate number.

     SETCRATE #c                   #c -> current crate number.

     QWAIT    (f,n,a),max          for(i=1;i<max;i++) if(Q) break;

     ENBINT                        interrupt is enabled for the

                                   current crate.

     DSBINT                        interrupt is disabled for the

                                   current crate.



Multiple actions are supported for QS(Q stop),  AS(Address  scan)  and

IGQ(Ignore  Q)  modes.  Read data is written into user buffer.  PTR is

incremented by one for each 16 bit transfer, and is incremented by two

for  each  24  bit  transfer.  Word count is limited by "max" or the A

register.



     QS       (f,n,a),max          Q stop mode, limited by "max"

     QS       (f,n,a),A            Q stop mode, limited by "A"

     AS       (f,n,a),max          Address scan mode, limited by "max"

     AS       (f,n,a),A            Address scan mode, limited by "A"

     IGQ      (f,n,a),max          Ignore Q mode, limited by "max"

     IGQ      (f,n,a),A            Ignore Q mode, limited by "A"







2.6  Arithmetic Instructions



CAMEXE has the following 6 arithmetic operations.  The operations  are

defined in "C" language.



     1.  bit set            BIS S,D               D |= S



     2.  bit clear          BIC S,D               D &= (~S)



     3.  add                ADD S,D               D += S



     4.  subtraction        SUB S,D               D -= S



     5.  multiplication     MUL S,D               D *= S



     6.  division           DIV S,D               D /= S



"A" and  "T"  registers  are  available  as  source  and  destination.

"#data"  is  available  only  as  source.  There are 4 combinations of

source and destination.


                                                                Page 8





     1.  OPERATION A,T                            T ?= A



     2.  OPERATION T,A                            A ?= T



     3.  OPERATION #data,A                        A ?= data



     4.  OPERATION #data,T                        T ?= data



"OPERATION" represents one of arithmetic operations.  "?" is a  symbol

of the operation in "C" language, such as '+', '-'.



     In addition to those operations, there are two more  instructions

which operates on "A" and "T" registers.



     1.  EXCHG A,T         exchange contents of "A" register and

                           "T" register.



     2.  SWAP  A           swap lower 16 bit and higher 16 bit of

                           "A" register.







2.7  Branch Instructions



CAMEXE has conditional branch instructions and a no conditional branch

instruction.   Destination  is  described  by  "label" in source text.

CAMASM translates it to the location of destination.  Location 1 is  a

first  instruction.   Condition is set by subtracting a reference from

"T" register (Not affect on  "T"  register).   "BBC"  and  "BBS"  test

" bit"th bit of "T" register whether set or clear.  Bit zero is a LSB.

Instructions are defined in "C" language.



     1.  BR label                  goto label



     2.  BEQ #ref,label            if (T==ref) goto label;



     3.  BNE #ref,label            if (T!=ref) goto label;



     4.  BGT #ref,label            if (T> ref) goto label;



     5.  BGE #ref,label            if (T>=ref) goto label;



     6.  BLT #ref,label            if (T< ref) goto label;



     7.  BLE #ref,label            if (T<=ref) goto label;



     8.  BBC #bit,label            if ((T&(1<<bit))==0) goto label;



     9.  BBS #bit,label            if ((T&(1<<bit))!=0) goto label;




                                                                Page 9





2.8  Wait Interrupt Routines



CAMEXE can only wait an interrupt.  There is no interrupt routine  nor

asynchronous  routine  on  CAMEXE.   Those  routines are necessary for

concurrent  executions  of  CAMAC  I/O  and  user  written  monitoring

program.   Here,  CAMEXE itself is executed concurrently with the user

program.  Therefore it is not necessary  that  CAMEXE  itself  handles

asynchronous routine.  There are two instruction to wait interrupt.



     1.  WAITINT



     2.  WAITEVENT



Both instructions wait an interrupt signal.  "WAITEVENT", in  addition

to  "WAITINT",  initializes  "A" and "T" registers and adds word count

written by the  event  to  "TOP"  before  waiting  an  interrupt,  and

increments  event  count  after  waiting  the interrupt.  The "ENBINT"

instruction,  which  is  explained  in  the  section  of   CAMAC   I/O

instructions, must be executed before waiting the interrupt.







2.9  Miscellaneous Instructions



"HEADER" instruction add #n to PTR.  It can make a header region of  n

words.   (See  example in the appendix).  The instruction is described

and defined as the following.



         HEADER #n                 PTR += n



On executing "STOP" instruction, CAMEXE returns word count written  on

user  buffer,  content  of  the  "S"  register  and  status  of CAMEXE

execution to the user  program.   The  instruction  is  described  and

defined as the following.



         STOP                      stop CAMEXE execution.









3  CAMASM



CAMASM translates symbolic  source  program  to  CAMEXE's  instruction

codes.   CAMASM  itself is written in very primitive "C" language.  It

works on VAX, MS-DOS and OS9, and  will  work  on  UNIX.   Grammar  of

CAMASM  is  taken  from that of the macro assembler on OS-9 as much as

possible.  The explanation of it  is  also  taken  from  the  language

manual of the assembler [4].







3.1  Running CAMASM





[4]  OS-9/68000 Macro assembler user's manual, Microware.


                                                               Page 10





The format of command line to run the assembler is



         CAMASM   filename [ option ]



The only items absolutely required are the "CAMASM" command name,  and

"filename" which is the source text file name.  Extension of ".asm" is

assumed if you don't specify the extension  in  the  "filename".   The

object  file created by CAMASM has a same name as the source text file

has with extension of ".obj".  There is  no  way  to  control  whether

output  an  object file or not.  A "-l" is an only option available in

CAMASM.  It control whether it outputs listing or  not.   The  listing

file  created  by  CAMASM has a same name as the source text file does

with extension of ".lis".







3.2  Input File Format



The CAMASM reads its input from an input file which contains  variable

length  lines  of  ASCII  characters.  The maximum length of the input

line is 132 characters.  The line started with an "*" (asterisk) is  a

comment  line.   Blank  lines  are included in listing output, but are

ignored.  A field following  a  character  ";"  is  a  comment  field.

Comment  field  is  optional.   The source line can have the following

three field.



     1.  A label field.



     2.  An operation field.



     3.  An operand field if the operation requires.



A label field or an operation field can not be omitted.







3.2.1  Label  Field - The  label  field  must  begins  in  the   first

character  of  the  line.   The  first character of the line must be a

space or a tab if the line does not contain a label field.  Labels are

required by some statements (i.e., equ and macro).  Labels are used to

define the destination of the branch instructions.  Label field can be

followed  by  ":" (colon).  It does not means that the label is global

nor anything else, is just ignored.



     The label must be a legal symbolic name consisting of from  1  to

32  alphanumeric  characters, or characters "$" or "_".  Labels cannot

defined twice.  First definition will be used.







3.2.2  Operation Field. - The operation field  specifies  the  machine

language  instruction  or assembler directive statement mnemonic name.

It is separated from the prior field (label field or null) by  one  or

more  tabs  or  spaces.   CAMASM can accept instruction mnemonic names

only in uppercase characters, and can accept assembler directive names


                                                               Page 11





only  in lowercase characters.  (end not yet) Many CAMEXE instructions

require a size attribute such as "xxx.l" or "xxx.w".  The default size

is  ".w" (word) in CAMAC operations and MOVE operations with (PTR)+ or

HEADER(n).  In other operations, the default size is ".l" (long word).

The size attribute must be described by a lowercase characters.







3.2.3  Operand Field. - The operand field follows the operation field.

They must be separated by one or more tabs or spaces.  Some operations

don't use an operand field.







3.2.4  Assembly Listing Format. - If  the  "-l"  option  is  given  in

CAMASM  command  line, a formatted assembly listing will be written to

the listing output file.  The output listing has the following format.



 F0   1:                        ADC    equ    18

 F0   1: 0204 2400              start  READ.l (0,ADC,0),A  ; read ADC



 |    |  |                      |      |      |            comment field

 |    |  |                      |      |      |

 |    |  |                      |      |      Start of operand field

 |    |  |                      |      |

 |    |  |                      |      Start of operation field

 |    |  |                      |

 |    |  |                      Start of label field

 |    |  |

 |    |  Start of object code word

 |    |

 |    Location counter value (start from one)

 |

 Input mode (F0 is source text file, Fn is input from "use" file,

             M0 is macro definitions, and Mn indicates macro expansion.)









3.3  Evaluation Of Expressions



The assembler can evaluate expressions of almost any complexity  using

a  form similar to the algebraic notation used in programing languages

such as FORTRAN.  Expressions  consist  of  operands  (constants)  and

operators (arithmetic functions).  Expressions are evaluated from left

to right using the algebraic order of operations.  Parentheses can  be

used to alter the natural order of evaluation.







3.3.1  Expression  Operands - The  following  items  may  be  used  as

operands within an expression.


                                                               Page 12





         DECIMAL NUMBER:  an optional minus sign followed  by  one  to

         twelve digits.  For example,



                            100             3167789



                              0              -23457





         HEXADECIMAL  NUMBERS:   "0x"  followed  by   one   to   eight

         hexadecimal characters (0-9, A-F, of a-f).  For example,



                     0xF8100000                0x37











3.3.2  Expression Operators - Operators used in expressions operate on

one  operand (negative) or on two operands ('*','/','+','-').  '*' and

'/' are evaluated before '+' and '-' are done.







3.4  Macro



Often identical or similar sequences of instructions may  be  repeated

in  different places in a program.  Writing a sequence of instructions

repeatedly can be tedious if it is long or must be used  a  number  of

times.  A macro is a definition of an instruction sequence that can be

used in numerous places within a program.  The macro is given  a  name

by  a  "macro"  instruction.  The symbol name is used similarly to any

other instruction mnemonic.  Whenever CAMASM encounters the name of  a

macro  in the instruction field, it outputs all the instructions given

in the macro definition.  A sequences of instructions  which  is  used

frequently in data aquisition programs should be defined in macro.  It

makes the maintenances easy.







3.4.1  Macro  Structure - A  macro  definition   consists   of   three

sections.



name   macro       ; the macro header assigns a name to the macro.

       :

       :

       body        ; the macro body contains the macro statements.

       :

       :

       endm        ; the macro terminator indicates the end of the

                   ; macro definition.



The macro name can be any legal label in CAMASM assembler.  It can  be

defined  in  either  uppercase characters or lowercase characters.  It

must be referred exactly same way as it is defined.  The body  of  the

macro can contain any number of legal CAMEXE instructions, but can not


                                                               Page 13





contain any other assembler directives nor another  macro  definition.

Macro  call  can  be  nested,  that is, the name of a macro defined in

another macro definition can be contained in the instruction field  in

the  macro body.  The nesting is possible up to ten deep.  The text of

macro definitions are stored on a storage  area  on  memory.   It  can

limit the number of macro definitions.







3.4.2  Macro Arguments - Arguments permit variations in the  expansion

of  macro.   A  macro  can  have  up  to  nine formal arguments.  Each

argument consists of a backslash character and the sequence number  of

the  formal  argument  (1,2,...9).   On  expansion  of the macro, each

formal argument is replaced by the corresponding text  string  "actual

argument"  given  in  macro  call.  For example "2" is replaced by the

second actual argument in the macro call operand field.  Arguments can

be used in any part of the macro body even in label field or operation

field.  Arguments can  have  non  symbolic  characters  such  as  tab,

spaces,  ",",  "+"  etc., but can not have end-of-line character.  The

argument with non symbolic character should be quoted by  "s.   Formal

arguments can be used in any order and any number of times.



     Examples can be seem in the appendix.







3.5  Assembler Directive Statements



Assembler directive statements give  the  assembler  information  that

affects  the  assembly process, but do not cause code to be generated.

Assembler directive's mnemonics  such  as  "equ",  "use"  have  to  be

written in uppercase characters.







3.5.1  End Statement -



SYNTAX:     end



Indicates the end of the program.  It is an optional,  because  it  is

assumed on end-of-file on the source text file.







3.5.2  Equ Statement -



SYNTAX:  label equ string

SYNTAX:  label equ "string"

SYNTAX:  label =   string



"equ" statement is used to assign a  string  to  a  symbol  name  (the

label).   On  appearing  the  symbol  in  the  source  text  or  macro

expansion, the assembler substitutes the symbol to the string  defined

in  "equ"  statement.   A symbol name can be quoted by ""s to separate

from other source line characters.  Nesting is possible  in  assigning


                                                               Page 14





the  symbol.  Symbols must be defined before using them on the program

or on other assignments.  It is better that all assignments are on the

top.  The string contains a character not allowed for symbol name must

be quoted by "s.







3.5.3  Title Statement -



SYNTAX:      title string



It allows users to define a listing title line which will  be  printed

on the first line of each listing page's header.







3.5.4  Use Statement -



SYNTAX:      use filename



"Use" statements cause the assembler  to  pause  reading  the  current

input file.  Then, it requests to open the file of the name defined by

"filename" in the "use" statement.  The new file will be read until an

end-of-file occurs.  Then, the latest file is closed and the assembler

resumes reading the previous file.  It is a same manner as an  INCLUDE

statement in FORTRAN has.



     "Use" statements can be  nested.   The  file  appeared  in  "use"

statement  can  contain  "use" statements.  up to 9 nests are allowed,

not including the source text file.







3.6  Object File Format



The object codes are written on a object output file.  It  is  written

in  hexadecimal  constants.   First  line has one constant which gives

total word counts of the program including itself.  Lines following it

contains  four  constants.   All constants are 16 bit data size.  Each

constant has four digits, and  separated  by  a  space.   For  example

CAMASM create a object file from the following program.



SOURCE PROGRAM:



        ADC     equ     18

        start   READ.l  (0,ADC,0),A

                end



OBJECT FILE:



         0003                    ----- this program size is 3

         0204 2400 0000 0000     ----- two of four constants are the codes.



VAX FORTRAN can read the object file with the FORMAT of FORMAT(4Z5).

























                              APPENDIX A



                    CAMEXE INSTRUCTION SET ON VAX







Id  Mnemonic                      2nd word    3rd word    4th word

--  --------                      --------    --------    --------

00  STOP



01  READ{.w}  (f,n,a)             fna

02  READ.l    (f,n,a)             fna

03  READ{.w}  (f,n,a),A           fna

04  READ.l    (f,n,a),A           fna

05  WRITE{.w} #data,(f,n,a)       fna         data

06  WRITE.l   #data,(f,n,a)       fna         data_L      data_H

07  WRITE{.w} A,(f,n,a)           fna

08  WRITE.l   A.(f,n,a)           fna



09  NDT       (f,n,a)             fna

0A  SETCRATE  A

0B  SETCRATE  #c                  c

0C  GENZ

0D  GENC

0E  REMI

0F  SETI

10  ENBINT

11  DSBINT



12  QWAIT     (f,n,a),max         fna         max



13  QS{.w}    (f,n,a),max         fna         max

14  QS.l      (f,n,a),max         fna         max

15  QS{.w}    (f,n,a),A           fna

16  QS.l      (f,n,a),A           fna



17  AS{.w}    (f,n,a),max         fna         max

18  AS.l      (f,n,a),max         fna         max

19  AS{.w}    (f,n,a),A           fna         max

1A  AS.l      (f,n,a),A           fna         max



1B  IGQ{.w}   (f,n,a),max         fna         max

1C  IGQ.l     (f,n,a),max         fna         max

1D  IGQ{.w}   (f,n,a),A           fna         max

1E  IGQ.l     (f,n,a),A           fna         max


CAMEXE INSTRUCTION SET ON VAX                                 Page A-2





Id  Mnemonic                      2nd word    3rd word    4th word

--  --------                      --------    --------    --------

23  MOVE{.l}  A,S                                         

24  MOVE{.l}  A,T                                         

25  MOVE{.l}  S,A                                         

26  MOVE{.l}  S,T                                         

27  MOVE{.l}  T,A                                         

28  MOVE{.l}  T,S                                         



29  MOVE{.l}  #data,A             data_L      data_H

2A  MOVE{.l}  #data,S             data_L      data_H

2B  MOVE{.l}  #data,T             data_L      data_H



2C  MOVE{.w}  A,(PTR)+                        

2D  MOVE.l    A,(PTR)+                        

2E  MOVE{.w}  #data,(PTR)+        data

2F  MOVE.l    #data,(PTR)+        data_L      data_H



30  MOVE{.w}  A,HEADER(n)         n

31  MOVE{.w}  HEADER(n),A         n

32  MOVE{.w}  #data,HEADER(n)     n           data



33  LOAD      PTR

34  LOAD      REMAINDER

35  LOAD      TIMER

36  LOAD      COUNT

37  LOAD      CAMACSTATUS



38  HEADER    #n                  n

39  EXCHG     A,T

3A  SWAP      A



3B  BIS{.l}   A,T

3C  BIS{.l}   T,A

3D  BIS{.l}   #data,A             data_L      data_H

3E  BIS{.l}   #data,T             data_L      data_H



3F  BIC{.l}   A,T

40  BIC{.l}   T,A

41  BIC{.l}   #data,A             data_L      data_H

42  BIC{.l}   #data,T             data_L      data_H



43  ADD{.l}   A,T

44  ADD{.l}   T,A

45  ADD{.l}   #data,A             data_L      data_H

46  ADD{.l}   #data,T             data_L      data_H



47  SUB{.l}   A,T

48  SUB{.l}   T,A

49  SUB{.l}   #data,A             data_L      data_H

4A  SUB{.l}   #data,T             data_L      data_H


CAMEXE INSTRUCTION SET ON VAX                                 Page A-3





Id  Mnemonic                      2nd word    3rd word    4th word

--  --------                      --------    --------    --------

4B  MUL{.l}   A,T

4C  MUL{.l}   T,A

4D  MUL{.l}   #data,A             data_L      data_H

4E  MUL{.l}   #data,T             data_L      data_H



4F  DIV{.l}   A,T

50  DIV{.l}   T,A

51  DIV{.l}   #data,A             data_L      data_H

52  DIV{.l}   #data,T             data_L      data_H



53  WAITINT

54  WAITEVENT



55  BR        label               n

56  BEQ       #ref,label          n           ref_L       ref_H

57  BNE       #ref,label          n           ref_L       ref_H

58  BGT       #ref,label          n           ref_L       ref_H

59  BGE       #ref,label          n           ref_L       ref_H

5A  BLT       #ref,label          n           ref_L       ref_H

5B  BLE       #ref,label          n           ref_L       ref_H

5C  BBC       #ref,label          n           ref_L       ref_H

5D  BBS       #ref,label          n           ref_L       ref_H







Higher byte of the first word is a  word  count  of  the  instruction.

Lower byte of the first word is an instruction Id.



        +---------------+---------------+

        |   code size   |instruction Id |     first word

        +---------------+---------------+

        15             8 7              0



"fna" has the following format.



        +---+---------+-------+---------+

        |0 0|    N    |   A   |    F    |     fna format

        +---+---------+-------+---------+

        15  13       9 8     5 4        0



























                              APPENDIX B



                    CAMEXE PROGRAMMING TECHNIQUES







B.1  INTERRUPT DRIVEN PROGRAM





         title   INTERRUPT test

;

         ENBINT                  ; Enable interrupt

         :

         :                       ; Enable INTERRUPT on CAMAC module.

         :

loop     WAITEVENT               ; wait an event

         :

         :                       ; Interrupt driven routine

         :

         BR      loop            ; Repeat forever

;

         end









B.2  HOW TO MAKE A HEADER





         title   HEADER test

;

         HEADER  #10             ; reserve ten words area for header

         MOVE    #0xFF,HEADER(1) ; Write a constant '00FF' on the first word.

         :

         :

         :

         MOVE    A,HEADER(2)     ; Write a content of "A" register on the

         :                       ; second word.

         :

         :

         LOAD    PTR             ; Get a number of words written on the event

         MOVE    A,HEADER(10)    ; Write it on tenth word in the header.

;

         end



You can define the following macro.


CAMEXE PROGRAMMING TECHNIQUES                                 Page B-2







MARKER   macro

         LOAD    PTR

         MOVE    A,HEADER(\1)    ; First formal argument points the place

                                 ; in the header

         endm



This can be used as the following.



         MARKER  10              ; will be expanded

                                 ;

                                 ;       LOAD    PTR

                                 ;       MOVE    A,HEADER(10)

                                 ;









B.3  HOW TO DEFINE A READ ZONE ON YOUR BUFFER





         title   RED zone

;

red_zone equ     300             ; define a red zone size

;

loop

         :

         :

         :

         :

         LOAD    REMAINDER       ; Get a number of words remained on

         :                       ; user buffer

         MOVE    A,T             ; Copy it to "T" register for comparison

         BGT     #red_zone,loop  ; If "T" (remainder) is greater than

                                 ; 300 (red zone), then branch to loop

         STOP                    ; If remainder is less than the red zone,

                                 ; stop the execution.

         end



You can define the following macro.



red_test macro

         LOAD    REMAINDER

         MOVE    A,T

         BGT     #/1,/2

         endm



It can be read as the following.



         red_test        red_zone,loop   ; is expanded as the above example

                                         ; titled "RED zone".




CAMEXE PROGRAMMING TECHNIQUES                                 Page B-3





B.4  HOW TO READ A BUFFER MODULE (READ CAMAC)





READ_BM  macro

;

;        1st argument is a CAMAC station number of the buffer module.

;

         READ    (1,\1,0),A      ; Read a word count

         BIC     #0xFFF,A        ; Limit it less than 4096

         WRITE   #0,(17,\1,0)    ; Reset the pointer on the buffer module.

         QS      (0,\1,0)        ; Read with Q-stop mode

;

         endm









B.5  HOW TO READ A CAMAC-MP (READ TKO)





READ_MP  macro

;

;        1st argument is a CAMAC station number of the CAMAC-MP.

;

         READ    (0,\1,2),A      ; Get a number of long word in MP

         MUL     #2,A            ; Word count

         BIC     #0xFFF,A        ; Limit it less than 4096

         WRITE   #0,(16,\1,0)    ; Reset the pointer

         QS      (0,\1,0),A      ; Read max "A" words

         endm



























                              APPENDIX C



                          CAMASM ERROR CODE







"'(' is missing"

          '(' is missing where it is expected such  as  '('  following

          'HEADER'.





"')' is missing"

          ')' is missing for the previous ')'.





"endm is found in not macro input mode"

          'endm' is allowed only in the end of macro definition.





"equ label is missing"

          'equ' statement needs label.





"error in compiler MNTABLE "

          Error in assembler program is found.





"factor is missing"

          A factor is missing.  Only a number is  used  as  factor  in

          CAMASM assembler.





"invalid CAMAC function"

          CAMAC function (F) needs to be an integer of "0" to "31".





"invalid CAMAC station number"

          CAMAC station number (N) needs to be an integer  of  "0"  to

          "31".





"invalid CAMAC sub address"

          CAMAC subaddress (A) needs to be an integer of "0" to "15".





"invalid character in operand"


CAMASM ERROR CODE                                             Page C-2





          Unexpected character is found in operand field.





"invalid character is found after ')'"

          Unexpected character is found after ')'.





"invalid data size .l or .w are allowed"

          As data size attribute, ".l" or ".w" are allowed.





"invalid number"

          Error in reading a number.





"invalid representation"





"macro name error or missing"





"mnemonic is missing"





"no such label"

          No such label is defined in the program.





"no such mnemonic"

          No such instruction,  nor  assembler  directive,  nor  macro

          call.





"not defined error is found.  Something wrong!!!"

          This error is not expected by CAMASM.





"not defined error"

          This error is not expected by CAMASM.





"too much use file nesting"

          Nesting is allowed up to 9 deep.





"undefined location label"





"unexpected data size"

          This data size is not allowed to the instruction.





"unexpected macro name is found"

          This symbol is defined as the name of macro definition.   It

          cannot be used here.


CAMASM ERROR CODE                                             Page C-3





"unexpected operand is found"

          This operand type is not allowed in the instruction.





"use file open error"

          The file required by the  "use"  instruction  could  not  be

          opened.

