Skip to content

Commit

Permalink
Added support for Atmel AVR Assembly (#2078)
Browse files Browse the repository at this point in the history
Co-authored-by: RunDevelopment <mitchi5000.ms@googlemail.com>
  • Loading branch information
cerkit and RunDevelopment authored Oct 5, 2021
1 parent 2c63efa commit b5a70e4
Show file tree
Hide file tree
Showing 15 changed files with 334 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@
"title": "6502 Assembly",
"owner": "kzurawel"
},
"asmatmel": {
"title": "Atmel AVR Assembly",
"owner": "cerkit"
},
"autohotkey": {
"title": "AutoHotkey",
"owner": "aviaryan"
Expand Down
43 changes: 43 additions & 0 deletions components/prism-asmatmel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Prism.languages.asmatmel = {
'comment': {
pattern: /;.*/,
greedy: true
},
'string': {
pattern: /(["'`])(?:\\.|(?!\1)[^\\\r\n])*\1/,
greedy: true
},

'constant': /\b(?:PORT[A-Z]|DDR[A-Z]|(?:DD|P)[A-Z](?:\d|[0-2]\d|3[0-1]))\b/,

'directive': {
pattern: /\.\w+(?= )/,
alias: 'property'
},
'r-register': {
pattern: /\br(?:\d|[1-2]\d|3[0-1])\b/,
alias: 'variable'
},
'op-code': {
pattern: /\b(?:ADC|ADD|ADIW|AND|ANDI|ASR|BCLR|BLD|BRBC|BRBS|BRCC|BRCS|BREAK|BREQ|BRGE|BRHC|BRHS|BRID|BRIE|BRLO|BRLT|BRMI|BRNE|BRPL|BRSH|BRTC|BRTS|BRVC|BRVS|BSET|BST|CALL|CBI|CBR|CLC|CLH|CLI|CLN|CLR|CLS|CLT|CLV|CLZ|COM|CP|CPC|CPI|CPSE|DEC|DES|EICALL|EIJMP|ELPM|EOR|FMUL|FMULS|FMULSU|ICALL|IJMP|IN|INC|JMP|LAC|LAS|LAT|LD|LD[A-Za-z0-9]|LPM|LSL|LSR|MOV|MOVW|MUL|MULS|MULSU|NEG|NOP|OR|ORI|OUT|POP|PUSH|RCALL|RET|RETI|RJMP|ROL|ROR|SBC|SBCI|SBI|SBIC|SBIS|SBIW|SBR|SBRC|SBRS|SEC|SEH|SEI|SEN|SER|SES|SET|SEV|SEZ|SLEEP|SPM|ST|ST[A-Z0-9]|SUB|SUBI|SWAP|TST|WDR|XCH|adc|add|adiw|and|andi|asr|bclr|bld|brbc|brbs|brcc|brcs|break|breq|brge|brhc|brhs|brid|brie|brlo|brlt|brmi|brne|brpl|brsh|brtc|brts|brvc|brvs|bset|bst|call|cbi|cbr|clc|clh|cli|cln|clr|cls|clt|clv|clz|com|cp|cpc|cpi|cpse|dec|des|eicall|eijmp|elpm|eor|fmul|fmuls|fmulsu|icall|ijmp|in|inc|jmp|lac|las|lat|ld|ld[a-z0-9]|lpm|lsl|lsr|mov|movw|mul|muls|mulsu|neg|nop|or|ori|out|pop|push|rcall|ret|reti|rjmp|rol|ror|sbc|sbci|sbi|sbic|sbis|sbiw|sbr|sbrc|sbrs|sec|seh|sei|sen|ser|ses|set|sev|sez|sleep|spm|st|st[a-zA-Z0-9]|sub|subi|swap|tst|wdr|xch)\b/,
alias: 'keyword'
},
'hex-number': {
pattern: /#?\$[\da-f]{2,4}\b/i,
alias: 'number'
},
'binary-number': {
pattern: /#?%[01]+\b/,
alias: 'number'
},
'decimal-number': {
pattern: /#?\b\d+\b/,
alias: 'number'
},
'register': {
pattern: /\b[acznvshtixy]\b/i,
alias: 'variable'
},
'operator': />>=?|<<=?|&&?|\|\|?|[-+*/%&|^!=<>?]=?/,
'punctuation': /[(),:]/
};
1 change: 1 addition & 0 deletions components/prism-asmatmel.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 78 additions & 0 deletions examples/prism-asmatmel.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<h2>Comments</h2>
<pre><code>; This is a comment</code></pre>

<h2>Labels</h2>
<pre><code>label1: ; a label</code></pre>

<h2>Opcodes</h2>
<pre><code>LD
OUT

; lowercase
ldi
jmp label1
</code></pre>

<h2>Assembler directives</h2>
<pre><code>.segment CODE
.word $07d3
</code></pre>

<h2>Registers</h2>
<pre><code>LD A ; "A"
LDA label1,x ; "x"
</code></pre>

<h2>Strings</h2>
<pre><code>.include "header.asm"
</code></pre>

<h2>Numbers</h2>
<pre><code>ldi r24,#127
ldi r24,$80f0
ldi r24,#%01011000
</code></pre>

<h2>Constants</h2>
<pre><code>ldi r16, (0&lt;&lt;PB5)|(1&lt;&lt;PB4)|(1&lt;&lt;PB3)|(1&lt;&lt;PB2)|(1&lt;&lt;PB1)|(1&lt;&lt;PB0)</code></pre>

<h2>Example program to light up LEDs</h2>
<h3>Attach an LED (through a 220 ohm resistor) to any of the pins 0-12</h3>
<pre><code>; Pin Constant Values (Tested on Arduino UNO)
; PD0 - 0
; PD1 - 1
; PD2 - 2
; PD3 - 3
; PD4 - 4
; PD5 - 5
; PD6 - 6
; PD7 - 7

; PB0 - 8
; PB1 - 9
; PB2 - 10
; PB3 - 11
; PB4 - 12
; PB5 - 13 - System LED

start:

; Set pins 0-7 to high
ldi r17, (1&lt;&lt;PD7)|(1&lt;&lt;PD6)|(1&lt;&lt;PD5)|(1&lt;&lt;PD4)|(1&lt;&lt;PD3)|(1&lt;&lt;PD2)|(1&lt;&lt;PD1)|(1&lt;&lt;PD0)
out PORTD, r17

; Set pins 8-13 to high
ldi r16, (1&lt;&lt;PB5)|(1&lt;&lt;PB4)|(1&lt;&lt;PB3)|(1&lt;&lt;PB2)|(1&lt;&lt;PB1)|(1&lt;&lt;PB0)
out PORTB, r16

; Set pins 0-7 to output mode
ldi r18, (1&lt;&lt;DDD7)|(1&lt;&lt;DDD6)|(1&lt;&lt;DDD5)|(1&lt;&lt;DDD4)|(1&lt;&lt;DDD3)|(1&lt;&lt;DDD2)|(1&lt;&lt;DDD1)|(1&lt;&lt;DDD0)
out DDRD, r18

; Set pins 8-13 to output mode
ldi r19, (1&lt;&lt;DDB5)|(1&lt;&lt;DDB4)|(1&lt;&lt;DDB3)|(1&lt;&lt;DDB2)|(1&lt;&lt;DDB1)|(1&lt;&lt;DDB0)
out DDRB, r19

loop:
rjmp loop ; loop forever
</code></pre>
1 change: 1 addition & 0 deletions plugins/show-language/prism-show-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"adoc": "AsciiDoc",
"aspnet": "ASP.NET (C#)",
"asm6502": "6502 Assembly",
"asmatmel": "Atmel AVR Assembly",
"autohotkey": "AutoHotkey",
"autoit": "AutoIt",
"avisynth": "AviSynth",
Expand Down
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions tests/languages/asmatmel/comment_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
;
; foo bar baz

----------------------------------------------------

[
["comment", ";"],
["comment", "; foo bar baz"]
]

----------------------------------------------------

Check for comments
70 changes: 70 additions & 0 deletions tests/languages/asmatmel/constant_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
OUT PORTD,x
ldi r17,PD06
ldi r19,(1<<DDB31)
ldi r19,(1<<DDA30)
ldi r19,(1<<DDL10)
ldi r19,(1<<DDZ05)
ldi r19,(1<<PD7)

----------------------------------------------------

[
["op-code", "OUT"],
["constant", "PORTD"],
["punctuation", ","],
["register", "x"],

["op-code", "ldi"],
["r-register", "r17"],
["punctuation", ","],
["constant", "PD06"],

["op-code", "ldi"],
["r-register", "r19"],
["punctuation", ","],
["punctuation", "("],
["decimal-number", "1"],
["operator", "<<"],
["constant", "DDB31"],
["punctuation", ")"],

["op-code", "ldi"],
["r-register", "r19"],
["punctuation", ","],
["punctuation", "("],
["decimal-number", "1"],
["operator", "<<"],
["constant", "DDA30"],
["punctuation", ")"],

["op-code", "ldi"],
["r-register", "r19"],
["punctuation", ","],
["punctuation", "("],
["decimal-number", "1"],
["operator", "<<"],
["constant", "DDL10"],
["punctuation", ")"],

["op-code", "ldi"],
["r-register", "r19"],
["punctuation", ","],
["punctuation", "("],
["decimal-number", "1"],
["operator", "<<"],
["constant", "DDZ05"],
["punctuation", ")"],

["op-code", "ldi"],
["r-register", "r19"],
["punctuation", ","],
["punctuation", "("],
["decimal-number", "1"],
["operator", "<<"],
["constant", "PD7"],
["punctuation", ")"]
]

----------------------------------------------------

Check for constants
12 changes: 12 additions & 0 deletions tests/languages/asmatmel/directive_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.segment CODE

----------------------------------------------------

[
["directive", ".segment"],
" CODE"
]

----------------------------------------------------

Check for directives
15 changes: 15 additions & 0 deletions tests/languages/asmatmel/number_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
LD #127
ST $8000
LD #%10001010

----------------------------------------------------

[
["op-code", "LD"], ["decimal-number", "#127"],
["op-code", "ST"], ["hex-number", "$8000"],
["op-code", "LD"], ["binary-number", "#%10001010"]
]

----------------------------------------------------

Check for numbers
17 changes: 17 additions & 0 deletions tests/languages/asmatmel/opcode_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
LDY
LDZ
out
ldi

----------------------------------------------------

[
["op-code", "LDY"],
["op-code", "LDZ"],
["op-code", "out"],
["op-code", "ldi"]
]

----------------------------------------------------

Check for opcodes
24 changes: 24 additions & 0 deletions tests/languages/asmatmel/operator_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
OUT PORTB,x
ldi r17,(1<<PD07)

----------------------------------------------------

[
["op-code", "OUT"],
["constant", "PORTB"],
["punctuation", ","],
["register", "x"],

["op-code", "ldi"],
["r-register", "r17"],
["punctuation", ","],
["punctuation", "("],
["decimal-number", "1"],
["operator", "<<"],
["constant", "PD07"],
["punctuation", ")"]
]

----------------------------------------------------

Check for operators
42 changes: 42 additions & 0 deletions tests/languages/asmatmel/register_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
OUT PORTB,x
ldi r17,(1<<PD07)
OUT PORTD,r31
OUT PORTB,A
OUT PORTL,r10

----------------------------------------------------

[
["op-code", "OUT"],
["constant", "PORTB"],
["punctuation", ","],
["register", "x"],

["op-code", "ldi"],
["r-register", "r17"],
["punctuation", ","],
["punctuation", "("],
["decimal-number", "1"],
["operator", "<<"],
["constant", "PD07"],
["punctuation", ")"],

["op-code", "OUT"],
["constant", "PORTD"],
["punctuation", ","],
["r-register", "r31"],

["op-code", "OUT"],
["constant", "PORTB"],
["punctuation", ","],
["register", "A"],

["op-code", "OUT"],
["constant", "PORTL"],
["punctuation", ","],
["r-register", "r10"]
]

----------------------------------------------------

Check for registers
Loading

0 comments on commit b5a70e4

Please sign in to comment.