|
|
|
|
|
||
| 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 .endifWARNING: device names are case-sensitive! 'core' is number of bits per instruction
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 0x0If instruction have one operand (like addlw) we must use operand-descriptor. Let see first one example: Format of 'addlw' is: addlw fwhere 'f' is file-register (7bit number). Generaly, opcode is: 0b1111100fffffff ...6543210where '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
opcode is: 111dfffffff If, we write: addwf 0x20, 3 ; dest must be 0 or 1mostly 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> ) )
'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:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; hipo.dev ; ; Hypothetical processor. ; Format of instructions are: ; ; inc 0000000000 ; jnz addr 01cccccccc ; lda const 10cccccccc ; wa addr 11ccccccccdevice = HYPOTETIC core = 10 memory = 256 inst = 4 inc = (
wa = (
jnz = (
lda = (
; end of hipo.dev
|
||
|
|