单片机a51汇编 Vim语法脚本

这个脚本以前就写好了,一直没有时间放上来,由于没有学过Vim的脚本语法,可能写得有点ws,大牛们不要鄙视啊…

不过这个脚本依然存在bug,就是跳转指令后面的标号不能高亮,这个应该是正则表达式的问题,由于没学过,自己看了资料还是没办法接解决,希望大牛们能给点意见啊.

脚本如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
" Vim syntax file
" Language: MCS-51 Assembler (A51)
" Maintainer: Killua

if version < 600
syntax clear
elseif exists("b:current_syntax")
finish
endif

setlocal iskeyword=a-z,A-Z,48-57,.,_
setlocal isident=a-z,A-Z,48-57,.,_
syn case ignore

"Working Register
syn keyword a51WorkReg r0 r1 r2 r3 r4 r5 r6 r7

"Special Function Registers
syn keyword a51SFR p0 p0.0 p0.1 p0.2 p0.3 p0.4 p0.5 p0.6 p0.7
syn keyword a51SFR p1 p1.0 p1.1 p1.2 p1.3 p1.4 p1.5 p1.6 p1.7
syn keyword a51SFR p2 p2.0 p2.1 p2.2 p2.3 p2.4 p2.5 p2.6 p2.7
syn keyword a51SFR p3 p3.0 p3.1 p3.2 p3.3 p3.4 p3.5 p3.6 p3.7
syn keyword a51SFR SP dpl dph dptr pcon
syn keyword a51SFR tcon tf1 tr1 tf0 tr0 ie1 it1 ie0 it0
syn keyword a51SFR tmod tl0 tl1 th0 th1
syn keyword a51SFR scon sm0 sm1 sm2 ren tb8 rb8 ti ri
syn keyword a51SFR sbuf
syn keyword a51SFR ie ea et2 es et1 ex1 et0 ex0
syn keyword a51SFR ip pt2 ps pt1 px1 pt0 px0
syn keyword a51SFR psw cy ac f0 rs1 rs0 ov p
syn keyword a51SFR a acc.0 acc.1 acc.2 acc.3 acc.4 acc.5 acc.6 acc.7
syn keyword a51SFR b b.0 b.1 b.2 bc.3 b.4 b.5 b.6 bc.7

" Instruction
syn keyword a51Instr mov movx movc push pop xch xchd swap

syn keyword a51Instr add addc subb inc dec mul div da

syn keyword a51Instr clr setb cpl rl rlc rr rrc anl orl xrl

syn keyword a51Instr lcall acall ret reti ajmp sjmp ljmp nop jb jnb

syn keyword a51Instr jz jnz cjne djnz

syn keyword a51Prefix cseg at db ds end

"Symbol
syn match a51Symbol "[@#]"
syn match a51Symbol "[()|/[/]:]"

"Label
syn match a51Label "^/s*[^; /t]/+:"
syn match a51Label "[$]"

" Numbers
syn match a51BinaryNumber "/<[01]/+b/>"
syn match a51HexNumber "/</d/x*h/>"
syn match a51HexNumber "/</(0x/|$/)/x*/>"
syn match a51OctalNumber "/</(0/o/+o/=/|/o/+o/)/>"
syn match a51DecimalNumber "/</(0/|[1-9]/d*/)/>"

" Comment
syn region a51Comment start=";" end="$"
" String
syn region a51String start="/"" end="/"/|$"
syn region a51String start="'" end="'/|$"

"define link
hi def link a51BinaryNumber a51Number
hi def link a51HexNumber a51Number
hi def link a51OctalNumber a51Number
hi def link a51DecimalNumber a51Number

hi def link a51WorkReg a51Keyword
hi def link a51SFR a51Keyword

" Colors
hi a51Comment guifg=#0033FF
hi a51Keyword guifg=#339933
hi a51Number guifg=#FF00FF
hi a51Symbol guifg=#FF00FF
hi a51String guifg=#FF00FF
hi a51Instr guifg=#0000CC
hi a51Label guifg=#FF0000
hi a51Prefix guifg=#9933CC

let b:current_syntax = "a51"
" vim: ts=8 sw=8 :

添加方法:

将脚本复制到Vim目录下的syntax文件夹里面

添加到列表里面

修改synmenu.vim

1
2
3
4
5
6
7
8
" The following menu items are generated by makemenu.vim.
" The Start Of The Syntax Menu

an 50.20.100 &Syntax.C :cal SetSyn("c")<CR>
an 50.20.110 &Syntax.C++ :cal SetSyn("cpp")<CR>
an 50.20.120 &Syntax.A51 :cal SetSyn("a51")<CR>

" The End Of The Syntax Menu

列表里面的语法脚本应该茫茫多,只要加在他们后面就可以了,至于50.20.120,自己把握放到适当位置.

坚持原创技术分享,您的支持将鼓励我继续创作!