/
prism-asmatmel.html
78 lines (62 loc) · 1.67 KB
/
prism-asmatmel.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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<<PB5)|(1<<PB4)|(1<<PB3)|(1<<PB2)|(1<<PB1)|(1<<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<<PD7)|(1<<PD6)|(1<<PD5)|(1<<PD4)|(1<<PD3)|(1<<PD2)|(1<<PD1)|(1<<PD0)
out PORTD, r17
; Set pins 8-13 to high
ldi r16, (1<<PB5)|(1<<PB4)|(1<<PB3)|(1<<PB2)|(1<<PB1)|(1<<PB0)
out PORTB, r16
; Set pins 0-7 to output mode
ldi r18, (1<<DDD7)|(1<<DDD6)|(1<<DDD5)|(1<<DDD4)|(1<<DDD3)|(1<<DDD2)|(1<<DDD1)|(1<<DDD0)
out DDRD, r18
; Set pins 8-13 to output mode
ldi r19, (1<<DDB5)|(1<<DDB4)|(1<<DDB3)|(1<<DDB2)|(1<<DDB1)|(1<<DDB0)
out DDRB, r19
loop:
rjmp loop ; loop forever
</code></pre>