#  Try to put the more specialized forms before the
#  general ones
#
# syntax files xxx.syntax
# Using these is a bit too strict:
# It copies data from input line until the next char in parse line is found
# This becomes a problem when there are two tags in a row and the first
# one is a .syntax tag (<num> <+->). This is because
# the parser doesn't know it want's to stop at + and tries to match 3+0 as a 
# number 
#       <num>           matches & converts bin,dex,oct,hex nubers
#       <mathnum>       mathces immediate (eg 3+4) numbers (uses <num>
#	<main>		rather use <more> (it matches the rest of line)

# parse line special tags
#	<more>          restart parsing the rest of line (use with care)
#       space           skips all spaces in source text (no error if none)
# output line special tags
#	<nl>    	newline
#	<cm>		comment char '#'
# general tags (omit the :xx in output line)
#	<text>		any text
#       <+->            + or - (modify 'sgn')
#       <op>  		any assembly opcode
#	<op:xx>		bitmask select assembly opcode
#	 01     	 most
#	 02		 single & unmodified
#	 04		 mmx
#	<reg>		any register (modify: 'r')
#	<reg:xx> 	bitmask select register
#	 01     	 dword regs
#	 02     	 word regs
#	 04     	 byte regs
#	 08     	 segment/selector regs
#	 10     	 mmx regs
#	<data>          data initialization sizes (modify 'dtype')
#	 01 		 
#        02
#        04
#	<size>		memory size modifiers (modify: 'm')
#	 01              byte
#	 02              dword
#	 04 		 rest

# variables used:
#	<label>		last label
#       <dtype>         last data initialization type size
#       <r>		last registers type
#       <r-n>           previous register types
#       <m>             last memory type
#	<m-1>           
#       <sgn>           sign of last <+-> parse: +:nothing -:minus

General settings:
@src_comment=;
@dst_comment=<cm>
-
# Single instructions that don't need converting or extending
<op:22>
<op>
-

# cmps,lods,movs,stos,iret...  size extended
<op:20>b
<op>b
-
<op:20>w
<op>w
-
<op:20>d
<op>l
-

#pushfd, popfd
p<text>fd
p<text>f
-

#shl&shr , 1 
<op:08> <@><size> [ <address>] , 1
<op><m> <@><address>
-
<op:08> <@><reg> , 1
<op><r> <@>%<reg>
-

# movsx & movzx
mov<text>x <@><reg1> , <reg2>
mov<text><r><r-1> <@>%<reg2>,%<reg1>
-
mov<text>x <@><reg> , <size> [ <address>]
mov<text><m><r> <@><address>,%<reg>
-
mov<text>x <@><reg> , [ <address>]
mov<text><m><r> <@><address>,%<reg>
-

#correct?
enter <@><mathnum1>, <mathnum2>
enter <@>$<mathnum2>,$<mathnum1>
-

# Some mmx routines (and other that don't need the b/w/l extension)
# can use either op:04 or reg:10
<op:04> <@><reg:10> , [ <address>]
<op> <@><address>,%<reg>
-
<op:04> <@><reg> , <size> [ <address>]
<op> <@><address>,%<reg>
-
<op:04> <@>[ <address>] , <reg>
<op> <@>%<reg>,<address>
-
<op:04> <@><reg1> , <reg2>
<op> <@>%<reg2>,%<reg1>
-
<op:04> <@><reg> , <mathnum>
<op> <@>$<mathnum>,%<reg>
-

# normal instructions
<op> <@><size> [ <address>]
<op><m> <@><address>
-
<op> <@><reg> , [ <address>]
<op><r> <@><address>,%<reg>
-
<op> <@>[ <address>] , <size> <mathnum>
<op><m> <@>$<mathnum>,<address>
-
<op> <@><size> [ <address>] , <size> <mathnum>
<op><m-1> <@>$<mathnum>,<address>
-
<op> <@><size> [ <address>] , <mathnum>
<op><m-1> <@>$<mathnum>,<address>
-
<op> <@>[ <address>] , <reg>
<op><r> <@>%<reg>,<address>
-

<op> <@><reg1> , <reg2>
<op><r> <@>%<reg2>,%<reg1>
-
<op> <@><reg> , <size> <mathnum>
<op><r> <@>$<mathnum>,%<reg>
-
<op> <@><reg> , <mathnum>
<op><r> <@>$<mathnum>,%<reg>
-

# Simple instructions
<op> <@><size> [ <address>]
<op><m> <@><address>
-
<op> <@><mathnum>
<op> <@>$<mathnum>
-
<op> <@><reg>
<op><r> <@>%<reg>
-

# rep instructions
rep <text>d
rep<nl><text>l
-
rep <text>
rep<nl><text>
-

# set flag->register
set<text> <@><reg>
set<text>b <@>%<reg>
-
set<text> <@>[ <address>]
set<text>b <@><address>
-

# Jump instructions to local & general variables
j<text1> <@>.<text2>
j<text1> <@><label>.<text2>
-
jmp <@>[ <address>]
jmp <@>*<address>
-
jmp <@><discard> .<text2>
jmp <@><label>.<text2>
-
jmp <@><discard> <text>
jmp <@><text>
-
j<text1> <@><text2>
j<text1> <@><text2>
-
loop <@>.<text>
loop <@><label>.<text>
-
loop <@><text>
loop <@><text>
-


# Labels: convert local labels to lastbiglabel.locallabel
# The <more> allows an instruction be placed on the same line
.<text>: <@><more>
<label>.<text>: <@><more>
-
.<text> <@><more>
<label>.<text>: <@><more>
-
<text>: <@><more>
@label=<text>
<label>: <@><more>
-

# Some special directives
BITS <num>
SKIPLINE
-
# Can someone help with this one
GLOBAL <text>:function
.globl <text>
-
GLOBAL <text>
.globl <text>
-
EXTERN <text>
.extern <text>
-
SECTION <text>
<text>
-
RESD <text>
.space <text>*4
-
ALIGN <num1>, db <num2>
.align <num1>, <num2>
-
ALIGN <num>
.align <num>
-

# more directives
%include '<text>'
<cm>include "<text>"
-
<text> <@1>equ <@2><mathnumber>
.equ <@1><text>, <@2><mathnumber>
-
<text1> <@1>equ <@2><text2>
.equ <@1><text1>, <@2><text2>
-

# data initialization
<text>: <data> <num>
<text>: .<dtype> <num>
-
<text> <data> <num>
<text>: .<dtype> <num>
-
<text>: <data> <num>, <num>
<text>: .<dtype> <num>,<num>
-
<text> <data> <num>, <num>
<text>: .<dtype> <num>,<num>
-
<data> <num>
.<dtype> <num>
-


# string constants
db <@>'<string>' , 0
.asciz <@>"<string>"
-
db <@>'<string>' , <num>
.ascii <@>"<string>"<nl>.byte <@><num>
-
db <@>'<string>'
.ascii <@>"<string>"
-
