Free Web Hosting by Netfirms
Web Hosting by Netfirms | Free Domain Names by Netfirms

 
9. DEVICE DESCRIPTION FILES
Mas is generic assembly, so it can make code for another PICxxx microcontrollers or others. Do not think that mas can generate code for any assembler (like Motorola, x86, ...) mas's scripts are very limited.

All scripts are in 'device' directory where mas is installed or in user specifed (see '2. Command syntax') and any script have extension '.dev'.

Script has two parts: header and instruction-descriptors. Header is just few assignments that describe device:

  'device' = name-of-device

  'core' = number-of-bits-per-opcode

  'memory' = max-memory-size-for-code

  'inst' = number-of-instructions
(must be in this order). For PIC16C84 it will be:
  device = P16C84

  core = 14  

  memory = 0x3FF  

  inst = 37
'device' represents name of device. Name will be prefixed with '__'. So, in asm code it can be used for checking:
  .if .isndef __P16C84

   .error Device must be PIC16C84

  .endif
WARNING: device names are case-sensitive!

'core'  is number of bits per instruction
'memory'is number of how mutch memory is implemented on chip
'inst'  number of instructions

After header, comes descriptors for instructions. Syntax is:

 name '='  '('   'opcode' = number [ 'param'
= operand-desc]

  ['param' = operand-desc]] ['param' = operand-desc] ')'
 operand-desc := '(' 'size' = number 'position' = number
    [{'warning', 'error'} = '<' any chars'>']

To describe simple instruction without operands (like NOP) :

 nop = ( opcode = 0 ) ; opcode for NOP is 0x0
If instruction have one operand (like addlw) we must use operand-descriptor. Let see first one example: Format of 'addlw' is:
  addlw f
where 'f' is file-register (7bit number). Generaly, opcode is:
  0b1111100fffffff

        ...6543210
where 'ff..f' is bits of operand (file register). So, operand is 7bit in size and starting offset of operand in opcode is 0. We must know this for 'size' and 'position' assignments in script. Script will be:
  addlw = (

   opcode = 0b11111000000000

   param = (    ; operand 1 description

    size = 7 ; size of operand

    position = 0 ; position of operand

   )

  )
 

 
 
 

If we write, in asm code, operand that is bigger than 7bits warning is issued:

 operand too big, truncating to ...

Sometimes, this is not what we want. Let see 'addwf' instruction:

   addwf f, d


f - file-register
d - destination (0 or 1)

opcode is:

 111dfffffff

If, we write:

  addwf 0x20, 3  ; dest must be 0 or 1
mostly this is error. So we need syntax to issue error. We just write in script:
 addwf = (

  opcode = 0b11100000000

  param = (  ; first param

   size = 7 ; 7bit file register

   position = 0 ; starting at position 0

  )

  param = (  ; second param

   size = 1 ; destination 0 or 1

   position = 7 ; starting at position 7

   error = <destination must be 0 or 1>

  )

 )


If mas find second operand for 'addwf' that can not be represented with 'size' bits, it will issue error with our text:

'destination must be 0 or 1'

Sometimes, we will issue warning - just replace 'error' with warning. In p16c84.dev 'addwf' instruction is written like:

 addwf = (

       opcode = 0x0700

       param = (

            
size = 7

            
position = 0

            
warning = <check for bank>

       )

       param = (

            
size = 1

            
position = 7

            
error = <destination must be 1 or 0>

       )

 )
Maximum is 3 parametars for instruction!

Finally, let write some hypothetical processor. This processor have just 4 instructions:
 

  • increment accumulator
  • load constant into accumulator
  • write accumulator to memory
  • jump if accumulator is not zero


with this instructions it can be implemented what ever we wannt!
 

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

 ;

 ;  hipo.dev

 ;

 ;  Hypothetical processor.

 ;  Format of instructions are:

 ;

 ; inc  0000000000

 ; jnz addr 01cccccccc

 ; lda const       10cccccccc

 ; wa  addr 11cccccccc

 
 device = HYPOTETIC
 core = 10
 memory = 256
 inst = 4

 inc = ( 
  opcode = 0 
 )

 wa  = ( 
  opcode = 0b1100000000 
  param = (
   size = 8
   position = 0
  )
 )

 jnz = (
  opcode = 0b0100000000
  param = (
   size = 8
   position = 0
  )
 )

 lda = (
  opcode = 0b100000000
  param = (
   size = 8
   position = 0
   error = <address out of range>
  )
 )

; end of hipo.dev
 

[PREV][INDEX][NEXT]