armasm.js (4845B)
1 /* 2 Language: ARM Assembly 3 Author: Dan Panzarella <alsoelp@gmail.com> 4 Description: ARM Assembly including Thumb and Thumb2 instructions 5 Category: assembler 6 */ 7 8 /** @type LanguageFn */ 9 function armasm(hljs) { 10 //local labels: %?[FB]?[AT]?\d{1,2}\w+ 11 12 const COMMENT = { 13 variants: [ 14 hljs.COMMENT('^[ \\t]*(?=#)', '$', {relevance: 0, excludeBegin: true }), 15 hljs.COMMENT('[;@]', '$', {relevance: 0}), 16 hljs.C_LINE_COMMENT_MODE, 17 hljs.C_BLOCK_COMMENT_MODE, 18 ] 19 }; 20 21 return { 22 name: 'ARM Assembly', 23 case_insensitive: true, 24 aliases: ['arm'], 25 keywords: { 26 $pattern: '\\.?' + hljs.IDENT_RE, 27 meta: 28 //GNU preprocs 29 '.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 .arm .thumb .code16 .code32 .force_thumb .thumb_func .ltorg '+ 30 //ARM directives 31 'ALIAS ALIGN ARM AREA ASSERT ATTR CN CODE CODE16 CODE32 COMMON CP DATA DCB DCD DCDU DCDO DCFD DCFDU DCI DCQ DCQU DCW DCWU DN ELIF ELSE END ENDFUNC ENDIF ENDP ENTRY EQU EXPORT EXPORTAS EXTERN FIELD FILL FUNCTION GBLA GBLL GBLS GET GLOBAL IF IMPORT INCBIN INCLUDE INFO KEEP LCLA LCLL LCLS LTORG MACRO MAP MEND MEXIT NOFP OPT PRESERVE8 PROC QN READONLY RELOC REQUIRE REQUIRE8 RLIST FN ROUT SETA SETL SETS SN SPACE SUBT THUMB THUMBX TTL WHILE WEND ', 32 built_in: 33 'r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13 r14 r15 '+ //standard registers 34 'pc lr sp ip sl sb fp '+ //typical regs plus backward compatibility 35 'a1 a2 a3 a4 v1 v2 v3 v4 v5 v6 v7 v8 f0 f1 f2 f3 f4 f5 f6 f7 '+ //more regs and fp 36 'p0 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14 p15 '+ //coprocessor regs 37 'c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 '+ //more coproc 38 'q0 q1 q2 q3 q4 q5 q6 q7 q8 q9 q10 q11 q12 q13 q14 q15 '+ //advanced SIMD NEON regs 39 40 //program status registers 41 'cpsr_c cpsr_x cpsr_s cpsr_f cpsr_cx cpsr_cxs cpsr_xs cpsr_xsf cpsr_sf cpsr_cxsf '+ 42 'spsr_c spsr_x spsr_s spsr_f spsr_cx spsr_cxs spsr_xs spsr_xsf spsr_sf spsr_cxsf '+ 43 44 //NEON and VFP registers 45 's0 s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 s12 s13 s14 s15 '+ 46 's16 s17 s18 s19 s20 s21 s22 s23 s24 s25 s26 s27 s28 s29 s30 s31 '+ 47 'd0 d1 d2 d3 d4 d5 d6 d7 d8 d9 d10 d11 d12 d13 d14 d15 '+ 48 'd16 d17 d18 d19 d20 d21 d22 d23 d24 d25 d26 d27 d28 d29 d30 d31 ' + 49 50 '{PC} {VAR} {TRUE} {FALSE} {OPT} {CONFIG} {ENDIAN} {CODESIZE} {CPU} {FPU} {ARCHITECTURE} {PCSTOREOFFSET} {ARMASM_VERSION} {INTER} {ROPI} {RWPI} {SWST} {NOSWST} . @' 51 }, 52 contains: [ 53 { 54 className: 'keyword', 55 begin: '\\b('+ //mnemonics 56 'adc|'+ 57 '(qd?|sh?|u[qh]?)?add(8|16)?|usada?8|(q|sh?|u[qh]?)?(as|sa)x|'+ 58 'and|adrl?|sbc|rs[bc]|asr|b[lx]?|blx|bxj|cbn?z|tb[bh]|bic|'+ 59 'bfc|bfi|[su]bfx|bkpt|cdp2?|clz|clrex|cmp|cmn|cpsi[ed]|cps|'+ 60 'setend|dbg|dmb|dsb|eor|isb|it[te]{0,3}|lsl|lsr|ror|rrx|'+ 61 'ldm(([id][ab])|f[ds])?|ldr((s|ex)?[bhd])?|movt?|mvn|mra|mar|'+ 62 'mul|[us]mull|smul[bwt][bt]|smu[as]d|smmul|smmla|'+ 63 'mla|umlaal|smlal?([wbt][bt]|d)|mls|smlsl?[ds]|smc|svc|sev|'+ 64 'mia([bt]{2}|ph)?|mrr?c2?|mcrr2?|mrs|msr|orr|orn|pkh(tb|bt)|rbit|'+ 65 'rev(16|sh)?|sel|[su]sat(16)?|nop|pop|push|rfe([id][ab])?|'+ 66 'stm([id][ab])?|str(ex)?[bhd]?|(qd?)?sub|(sh?|q|u[qh]?)?sub(8|16)|'+ 67 '[su]xt(a?h|a?b(16)?)|srs([id][ab])?|swpb?|swi|smi|tst|teq|'+ 68 'wfe|wfi|yield'+ 69 ')'+ 70 '(eq|ne|cs|cc|mi|pl|vs|vc|hi|ls|ge|lt|gt|le|al|hs|lo)?'+ //condition codes 71 '[sptrx]?' + //legal postfixes 72 '(?=\\s)' // followed by space 73 }, 74 COMMENT, 75 hljs.QUOTE_STRING_MODE, 76 { 77 className: 'string', 78 begin: '\'', 79 end: '[^\\\\]\'', 80 relevance: 0 81 }, 82 { 83 className: 'title', 84 begin: '\\|', end: '\\|', 85 illegal: '\\n', 86 relevance: 0 87 }, 88 { 89 className: 'number', 90 variants: [ 91 {begin: '[#$=]?0x[0-9a-f]+'}, //hex 92 {begin: '[#$=]?0b[01]+'}, //bin 93 {begin: '[#$=]\\d+'}, //literal 94 {begin: '\\b\\d+'} //bare number 95 ], 96 relevance: 0 97 }, 98 { 99 className: 'symbol', 100 variants: [ 101 {begin: '^[ \\t]*[a-z_\\.\\$][a-z0-9_\\.\\$]+:'}, //GNU ARM syntax 102 {begin: '^[a-z_\\.\\$][a-z0-9_\\.\\$]+'}, //ARM syntax 103 {begin: '[=#]\\w+' } //label reference 104 ], 105 relevance: 0 106 } 107 ] 108 }; 109 } 110 111 module.exports = armasm;