UNPKG

4.33 kBJavaScriptView Raw
1/*
2Language: MIPS Assembly
3Author: Nebuleon Fumika <nebuleon.fumika@gmail.com>
4Description: MIPS Assembly (up to MIPS32R2)
5Website: https://en.wikipedia.org/wiki/MIPS_architecture
6Category: assembler
7*/
8
9function mipsasm(hljs) {
10 // local labels: %?[FB]?[AT]?\d{1,2}\w+
11 return {
12 name: 'MIPS Assembly',
13 case_insensitive: true,
14 aliases: [ 'mips' ],
15 keywords: {
16 $pattern: '\\.?' + hljs.IDENT_RE,
17 meta:
18 // GNU preprocs
19 '.2byte .4byte .align .ascii .asciz .balign .byte .code .data .else .end .endif .endm .endr .equ .err .exitm .extern .global .hword .if .ifdef .ifndef .include .irp .long .macro .rept .req .section .set .skip .space .text .word .ltorg ',
20 built_in:
21 '$0 $1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12 $13 $14 $15 ' // integer registers
22 + '$16 $17 $18 $19 $20 $21 $22 $23 $24 $25 $26 $27 $28 $29 $30 $31 ' // integer registers
23 + 'zero at v0 v1 a0 a1 a2 a3 a4 a5 a6 a7 ' // integer register aliases
24 + 't0 t1 t2 t3 t4 t5 t6 t7 t8 t9 s0 s1 s2 s3 s4 s5 s6 s7 s8 ' // integer register aliases
25 + 'k0 k1 gp sp fp ra ' // integer register aliases
26 + '$f0 $f1 $f2 $f2 $f4 $f5 $f6 $f7 $f8 $f9 $f10 $f11 $f12 $f13 $f14 $f15 ' // floating-point registers
27 + '$f16 $f17 $f18 $f19 $f20 $f21 $f22 $f23 $f24 $f25 $f26 $f27 $f28 $f29 $f30 $f31 ' // floating-point registers
28 + 'Context Random EntryLo0 EntryLo1 Context PageMask Wired EntryHi ' // Coprocessor 0 registers
29 + 'HWREna BadVAddr Count Compare SR IntCtl SRSCtl SRSMap Cause EPC PRId ' // Coprocessor 0 registers
30 + 'EBase Config Config1 Config2 Config3 LLAddr Debug DEPC DESAVE CacheErr ' // Coprocessor 0 registers
31 + 'ECC ErrorEPC TagLo DataLo TagHi DataHi WatchLo WatchHi PerfCtl PerfCnt ' // Coprocessor 0 registers
32 },
33 contains: [
34 {
35 className: 'keyword',
36 begin: '\\b(' // mnemonics
37 // 32-bit integer instructions
38 + 'addi?u?|andi?|b(al)?|beql?|bgez(al)?l?|bgtzl?|blezl?|bltz(al)?l?|'
39 + 'bnel?|cl[oz]|divu?|ext|ins|j(al)?|jalr(\\.hb)?|jr(\\.hb)?|lbu?|lhu?|'
40 + 'll|lui|lw[lr]?|maddu?|mfhi|mflo|movn|movz|move|msubu?|mthi|mtlo|mul|'
41 + 'multu?|nop|nor|ori?|rotrv?|sb|sc|se[bh]|sh|sllv?|slti?u?|srav?|'
42 + 'srlv?|subu?|sw[lr]?|xori?|wsbh|'
43 // floating-point instructions
44 + 'abs\\.[sd]|add\\.[sd]|alnv.ps|bc1[ft]l?|'
45 + 'c\\.(s?f|un|u?eq|[ou]lt|[ou]le|ngle?|seq|l[et]|ng[et])\\.[sd]|'
46 + '(ceil|floor|round|trunc)\\.[lw]\\.[sd]|cfc1|cvt\\.d\\.[lsw]|'
47 + 'cvt\\.l\\.[dsw]|cvt\\.ps\\.s|cvt\\.s\\.[dlw]|cvt\\.s\\.p[lu]|cvt\\.w\\.[dls]|'
48 + 'div\\.[ds]|ldx?c1|luxc1|lwx?c1|madd\\.[sd]|mfc1|mov[fntz]?\\.[ds]|'
49 + 'msub\\.[sd]|mth?c1|mul\\.[ds]|neg\\.[ds]|nmadd\\.[ds]|nmsub\\.[ds]|'
50 + 'p[lu][lu]\\.ps|recip\\.fmt|r?sqrt\\.[ds]|sdx?c1|sub\\.[ds]|suxc1|'
51 + 'swx?c1|'
52 // system control instructions
53 + 'break|cache|d?eret|[de]i|ehb|mfc0|mtc0|pause|prefx?|rdhwr|'
54 + 'rdpgpr|sdbbp|ssnop|synci?|syscall|teqi?|tgei?u?|tlb(p|r|w[ir])|'
55 + 'tlti?u?|tnei?|wait|wrpgpr'
56 + ')',
57 end: '\\s'
58 },
59 // lines ending with ; or # aren't really comments, probably auto-detect fail
60 hljs.COMMENT('[;#](?!\\s*$)', '$'),
61 hljs.C_BLOCK_COMMENT_MODE,
62 hljs.QUOTE_STRING_MODE,
63 {
64 className: 'string',
65 begin: '\'',
66 end: '[^\\\\]\'',
67 relevance: 0
68 },
69 {
70 className: 'title',
71 begin: '\\|',
72 end: '\\|',
73 illegal: '\\n',
74 relevance: 0
75 },
76 {
77 className: 'number',
78 variants: [
79 { // hex
80 begin: '0x[0-9a-f]+' },
81 { // bare number
82 begin: '\\b-?\\d+' }
83 ],
84 relevance: 0
85 },
86 {
87 className: 'symbol',
88 variants: [
89 { // GNU MIPS syntax
90 begin: '^\\s*[a-z_\\.\\$][a-z0-9_\\.\\$]+:' },
91 { // numbered local labels
92 begin: '^\\s*[0-9]+:' },
93 { // number local label reference (backwards, forwards)
94 begin: '[0-9]+[bf]' }
95 ],
96 relevance: 0
97 }
98 ],
99 // forward slashes are not allowed
100 illegal: /\//
101 };
102}
103
104module.exports = mipsasm;