mipsasm.js 4.3 KB

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