Skip to content

Commit b5a70e4

Browse files
Added support for Atmel AVR Assembly (#2078)
Co-authored-by: RunDevelopment <mitchi5000.ms@googlemail.com>
1 parent 2c63efa commit b5a70e4

15 files changed

+334
-2
lines changed

components.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components.json

Lines changed: 4 additions & 0 deletions
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

Lines changed: 43 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prism-asmatmel.html

Lines changed: 78 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 13 additions & 0 deletions
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
Lines changed: 70 additions & 0 deletions
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
Lines changed: 12 additions & 0 deletions
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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy