mipsasm.js (4203B)
1 /* 2 Language: MIPS Assembly 3 Author: Nebuleon Fumika <nebuleon.fumika@gmail.com> 4 Description: MIPS Assembly (up to MIPS32R2) 5 Website: https://en.wikipedia.org/wiki/MIPS_architecture 6 Category: assembler 7 */ 8 9 function 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: '\\|', end: '\\|', 72 illegal: '\\n', 73 relevance: 0 74 }, 75 { 76 className: 'number', 77 variants: [ 78 {begin: '0x[0-9a-f]+'}, //hex 79 {begin: '\\b-?\\d+'} //bare number 80 ], 81 relevance: 0 82 }, 83 { 84 className: 'symbol', 85 variants: [ 86 {begin: '^\\s*[a-z_\\.\\$][a-z0-9_\\.\\$]+:'}, //GNU MIPS syntax 87 {begin: '^\\s*[0-9]+:'}, // numbered local labels 88 {begin: '[0-9]+[bf]' } // number local label reference (backwards, forwards) 89 ], 90 relevance: 0 91 } 92 ], 93 illegal: '\/' 94 }; 95 } 96 97 module.exports = mipsasm;