Skip to content

Commit b5a70e4

Browse files
cerkitRunDevelopment
andauthoredOct 5, 2021
Added support for Atmel AVR Assembly (#2078)
Co-authored-by: RunDevelopment <[email protected]>
1 parent 2c63efa commit b5a70e4

15 files changed

+334
-2
lines changed
 

‎components.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎components.json

+4
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@
153153
"title": "6502 Assembly",
154154
"owner": "kzurawel"
155155
},
156+
"asmatmel": {
157+
"title": "Atmel AVR Assembly",
158+
"owner": "cerkit"
159+
},
156160
"autohotkey": {
157161
"title": "AutoHotkey",
158162
"owner": "aviaryan"

‎components/prism-asmatmel.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Prism.languages.asmatmel = {
2+
'comment': {
3+
pattern: /;.*/,
4+
greedy: true
5+
},
6+
'string': {
7+
pattern: /(["'`])(?:\\.|(?!\1)[^\\\r\n])*\1/,
8+
greedy: true
9+
},
10+
11+
'constant': /\b(?:PORT[A-Z]|DDR[A-Z]|(?:DD|P)[A-Z](?:\d|[0-2]\d|3[0-1]))\b/,
12+
13+
'directive': {
14+
pattern: /\.\w+(?= )/,
15+
alias: 'property'
16+
},
17+
'r-register': {
18+
pattern: /\br(?:\d|[1-2]\d|3[0-1])\b/,
19+
alias: 'variable'
20+
},
21+
'op-code': {
22+
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/,
23+
alias: 'keyword'
24+
},
25+
'hex-number': {
26+
pattern: /#?\$[\da-f]{2,4}\b/i,
27+
alias: 'number'
28+
},
29+
'binary-number': {
30+
pattern: /#?%[01]+\b/,
31+
alias: 'number'
32+
},
33+
'decimal-number': {
34+
pattern: /#?\b\d+\b/,
35+
alias: 'number'
36+
},
37+
'register': {
38+
pattern: /\b[acznvshtixy]\b/i,
39+
alias: 'variable'
40+
},
41+
'operator': />>=?|<<=?|&&?|\|\|?|[-+*/%&|^!=<>?]=?/,
42+
'punctuation': /[(),:]/
43+
};

‎components/prism-asmatmel.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎examples/prism-asmatmel.html

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<h2>Comments</h2>
2+
<pre><code>; This is a comment</code></pre>
3+
4+
<h2>Labels</h2>
5+
<pre><code>label1: ; a label</code></pre>
6+
7+
<h2>Opcodes</h2>
8+
<pre><code>LD
9+
OUT
10+
11+
; lowercase
12+
ldi
13+
jmp label1
14+
</code></pre>
15+
16+
<h2>Assembler directives</h2>
17+
<pre><code>.segment CODE
18+
.word $07d3
19+
</code></pre>
20+
21+
<h2>Registers</h2>
22+
<pre><code>LD A ; "A"
23+
LDA label1,x ; "x"
24+
</code></pre>
25+
26+
<h2>Strings</h2>
27+
<pre><code>.include "header.asm"
28+
</code></pre>
29+
30+
<h2>Numbers</h2>
31+
<pre><code>ldi r24,#127
32+
ldi r24,$80f0
33+
ldi r24,#%01011000
34+
</code></pre>
35+
36+
<h2>Constants</h2>
37+
<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>
38+
39+
<h2>Example program to light up LEDs</h2>
40+
<h3>Attach an LED (through a 220 ohm resistor) to any of the pins 0-12</h3>
41+
<pre><code>; Pin Constant Values (Tested on Arduino UNO)
42+
; PD0 - 0
43+
; PD1 - 1
44+
; PD2 - 2
45+
; PD3 - 3
46+
; PD4 - 4
47+
; PD5 - 5
48+
; PD6 - 6
49+
; PD7 - 7
50+
51+
; PB0 - 8
52+
; PB1 - 9
53+
; PB2 - 10
54+
; PB3 - 11
55+
; PB4 - 12
56+
; PB5 - 13 - System LED
57+
58+
start:
59+
60+
; Set pins 0-7 to high
61+
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)
62+
out PORTD, r17
63+
64+
; Set pins 8-13 to high
65+
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)
66+
out PORTB, r16
67+
68+
; Set pins 0-7 to output mode
69+
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)
70+
out DDRD, r18
71+
72+
; Set pins 8-13 to output mode
73+
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)
74+
out DDRB, r19
75+
76+
loop:
77+
rjmp loop ; loop forever
78+
</code></pre>

‎plugins/show-language/prism-show-language.js

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"adoc": "AsciiDoc",
4343
"aspnet": "ASP.NET (C#)",
4444
"asm6502": "6502 Assembly",
45+
"asmatmel": "Atmel AVR Assembly",
4546
"autohotkey": "AutoHotkey",
4647
"autoit": "AutoIt",
4748
"avisynth": "AviSynth",

‎plugins/show-language/prism-show-language.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
;
2+
; foo bar baz
3+
4+
----------------------------------------------------
5+
6+
[
7+
["comment", ";"],
8+
["comment", "; foo bar baz"]
9+
]
10+
11+
----------------------------------------------------
12+
13+
Check for comments
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
OUT PORTD,x
2+
ldi r17,PD06
3+
ldi r19,(1<<DDB31)
4+
ldi r19,(1<<DDA30)
5+
ldi r19,(1<<DDL10)
6+
ldi r19,(1<<DDZ05)
7+
ldi r19,(1<<PD7)
8+
9+
----------------------------------------------------
10+
11+
[
12+
["op-code", "OUT"],
13+
["constant", "PORTD"],
14+
["punctuation", ","],
15+
["register", "x"],
16+
17+
["op-code", "ldi"],
18+
["r-register", "r17"],
19+
["punctuation", ","],
20+
["constant", "PD06"],
21+
22+
["op-code", "ldi"],
23+
["r-register", "r19"],
24+
["punctuation", ","],
25+
["punctuation", "("],
26+
["decimal-number", "1"],
27+
["operator", "<<"],
28+
["constant", "DDB31"],
29+
["punctuation", ")"],
30+
31+
["op-code", "ldi"],
32+
["r-register", "r19"],
33+
["punctuation", ","],
34+
["punctuation", "("],
35+
["decimal-number", "1"],
36+
["operator", "<<"],
37+
["constant", "DDA30"],
38+
["punctuation", ")"],
39+
40+
["op-code", "ldi"],
41+
["r-register", "r19"],
42+
["punctuation", ","],
43+
["punctuation", "("],
44+
["decimal-number", "1"],
45+
["operator", "<<"],
46+
["constant", "DDL10"],
47+
["punctuation", ")"],
48+
49+
["op-code", "ldi"],
50+
["r-register", "r19"],
51+
["punctuation", ","],
52+
["punctuation", "("],
53+
["decimal-number", "1"],
54+
["operator", "<<"],
55+
["constant", "DDZ05"],
56+
["punctuation", ")"],
57+
58+
["op-code", "ldi"],
59+
["r-register", "r19"],
60+
["punctuation", ","],
61+
["punctuation", "("],
62+
["decimal-number", "1"],
63+
["operator", "<<"],
64+
["constant", "PD7"],
65+
["punctuation", ")"]
66+
]
67+
68+
----------------------------------------------------
69+
70+
Check for constants
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.segment CODE
2+
3+
----------------------------------------------------
4+
5+
[
6+
["directive", ".segment"],
7+
" CODE"
8+
]
9+
10+
----------------------------------------------------
11+
12+
Check for directives
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
LD #127
2+
ST $8000
3+
LD #%10001010
4+
5+
----------------------------------------------------
6+
7+
[
8+
["op-code", "LD"], ["decimal-number", "#127"],
9+
["op-code", "ST"], ["hex-number", "$8000"],
10+
["op-code", "LD"], ["binary-number", "#%10001010"]
11+
]
12+
13+
----------------------------------------------------
14+
15+
Check for numbers
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
LDY
2+
LDZ
3+
out
4+
ldi
5+
6+
----------------------------------------------------
7+
8+
[
9+
["op-code", "LDY"],
10+
["op-code", "LDZ"],
11+
["op-code", "out"],
12+
["op-code", "ldi"]
13+
]
14+
15+
----------------------------------------------------
16+
17+
Check for opcodes
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
OUT PORTB,x
2+
ldi r17,(1<<PD07)
3+
4+
----------------------------------------------------
5+
6+
[
7+
["op-code", "OUT"],
8+
["constant", "PORTB"],
9+
["punctuation", ","],
10+
["register", "x"],
11+
12+
["op-code", "ldi"],
13+
["r-register", "r17"],
14+
["punctuation", ","],
15+
["punctuation", "("],
16+
["decimal-number", "1"],
17+
["operator", "<<"],
18+
["constant", "PD07"],
19+
["punctuation", ")"]
20+
]
21+
22+
----------------------------------------------------
23+
24+
Check for operators
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
OUT PORTB,x
2+
ldi r17,(1<<PD07)
3+
OUT PORTD,r31
4+
OUT PORTB,A
5+
OUT PORTL,r10
6+
7+
----------------------------------------------------
8+
9+
[
10+
["op-code", "OUT"],
11+
["constant", "PORTB"],
12+
["punctuation", ","],
13+
["register", "x"],
14+
15+
["op-code", "ldi"],
16+
["r-register", "r17"],
17+
["punctuation", ","],
18+
["punctuation", "("],
19+
["decimal-number", "1"],
20+
["operator", "<<"],
21+
["constant", "PD07"],
22+
["punctuation", ")"],
23+
24+
["op-code", "OUT"],
25+
["constant", "PORTD"],
26+
["punctuation", ","],
27+
["r-register", "r31"],
28+
29+
["op-code", "OUT"],
30+
["constant", "PORTB"],
31+
["punctuation", ","],
32+
["register", "A"],
33+
34+
["op-code", "OUT"],
35+
["constant", "PORTL"],
36+
["punctuation", ","],
37+
["r-register", "r10"]
38+
]
39+
40+
----------------------------------------------------
41+
42+
Check for registers

0 commit comments

Comments
 (0)
Please sign in to comment.