-
Notifications
You must be signed in to change notification settings - Fork 0
/
msp430_assm
211 lines (158 loc) · 6.22 KB
/
msp430_assm
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
MSP430 ASSM Instruction
Instruction Description
rrc <dst> Rotate right through carry.
rra <dst> Rotate right arithmetic.
swpb <dst> Swap upper / lower bytes.
sxt <dst> Sign extend 8 bit value to 16 bit.
push <dst> Push value to stack.
call <dst> Call a function.
reti Return from interrupt.
mov <src>, <dst> Copy value from src to dst.
add <src>, <dst> dst = dst + src.
addc <src>, <dst> dst = dst + src + c.
subc <src>, <dst> dst = dst - src.
sub <src>, <dst> dst = dst - src + c.
cmp <src>, <dst> dst - src (don't store result, but set flags)
dadd <src>, <dst> dst = dst + src (BCD mode).
bit <src>, <dst> dst & src (don't store result, but set flags)
bic <src>, <dst> dst = dst & ~src (clear bits)
bis <src>, <dst> dst = dst | src (set bits)
xor <src>, <dst> dst = dst ^ src
and <src>, <dst> dst = dst & src
jne / jnz <address> Jump if not equal / zero.
jeq / jz <address> Jump if equal / zero.
jnc / jlo <address> Jump if no carry / lower (unsigned).
jc / jhs <address> Jump if carry / higher or same (unsigned).
jn <address> Jump if negative flag set.
jge <address> Jump if greater than or equal (signed).
jl <address> Jump if less (signed).
jmp <address> Jump always.
pseudo instruction
Alias Actual Instruction Description
clrc bic.b #1, SR Clear carry flag.
clrn bic.b #4, SR Clear negative flag.
clrz bic.b #2, SR Clear zero flag.
setc bis.b #1, SR Set carry flag.
setn bis.b #4, SR Set negative flag.
setz bis.b #2, SR Set zero flag.
dint bic.b #8, SR Disable interrupts.
eint bis.b #8, SR Enable interrupts.
nop mov.w #0, r3 No operation.
ret mov @SP+, PC Return from function (opposite of call).
pop <dst> mov @SP+, <dst> Pop from stack (opposite of push).
clr.x <dst> mov.w #0, <dst> Clear destination.
adc.x <dst> addc.w #<dst> Add carry to destination.
br <dst> mov <dst>, PC Branch to destination.
dadc.x <dst> dadd.w #0, <dst> Decimal add carry destination.
dec.x <dst> sub.w #1, <dst> Decrement.
decd.x <dst> sub.w #2, <dst> Decrement by 2.
inc.x <dst> add.w #1, <dst> Increment.
incd.x <dst> add.w #2, <dst> Increment by 2.
inv.x <dst> .x #-1, <dst> Invert.
rla.x <dst> add.w <dst>, <dst> Rotate left arithmetic.
rlc.x <dst> addc.w <dst>, <dst> Rotate left through carry.
sbc.x <dst> subc.w #0, <dst> Subtract borrow from destination.
tst.x <dst> cmp.w #0, <dst> Test if destination is 0.
examples
mov.w r8, r9 ;(copy register r8 to r9)
mov.w @r8, r9 ;(copy 16 bits from address r8 points to to r9)
mov.w @r8+, r9 ;(copy 16 bits from address r8 points to to r9r8 = r8 + 2)
mov.b @r8+, r9 ;(copy 8 bits from address r8 points to r9 r8 = r8 + 1)
mov.w 0x80(r8), r9 ;(copy 16 bits from address r8 points to plus 80 to r9.
;So if r8 = 0x200, copy address 0x200 and 0x201 as little endian
mov.w &0x200, r9 ;(copy 16 bits from 0x200 / 0x201 little endian into r9)
mov.b &0x200, r9 ;(copy 8 bits from 0x200 to r9)
mov.b 0x200, r9 ;(copy 8 bits from 0x200 to r9)
mov.w r8, &0x200 ;(copy 16 bits from r8 to memory address 0x200 / 0x201 little endian)
mov.w r8, 0x80(r9) ;(copy 16 bits from r8 to memory address r9 + 0x80 (and r9 + 0x81) little endian)
mov.w #5, r9 ;(copy 5 to r9)
mov.b #5, r9 ;(copy 5 to r9)
********************************************
mov.b #0x41, &P1DIR
mov.b #0x40, &P1OUT
P1.7 P1.6 P1.5 P1.4 P1.3 P1.2 P1.1 P1.0
P1DIR 0 1 0 0 0 0 0 1 = 0x41
P1OUT 0 1 0 0 0 0 0 0 = 0x40
*******************************************************
P1.7 P1.6 P1.5 P1.4 P1.3 P1.2 P1.1 P1.0
P1IN 0 0 0 0 0 0 1 0 = 0x02
mov.b &P1IN, r8
*****************************************************
blink.asm
.msp430
.include "msp430x2xx.inc"
.org 0xf800
start:
;; Turn off watchdog timer.
mov.w #WDTPW|WDTHOLD, &WDTCTL
;; Set P1.0 and P1.6 as outputs.
mov.b #0x41, &P1DIR
main:
;; Initial value for LEDs turns on the P1.0 LED and
;; keeps P1.6 turned off.
mov.w #0x01, r8
while_1:
;; Set LEDs to current value of r8 and toggle P1.0 and P1.6.
mov.b r8, &P1OUT
xor.b #0x41, r8
;; Delay by decrementing r9 60000 times.
mov.w #60000, r9
delay_loop:
dec r9
jnz delay_loop
;; Repeat loop.
jmp while_1
.org 0xfffe
dw start ; set reset vector to 'init' label
*****************************************************
timers
;; Set up Timer A
;; 8,000,000 / 256 = 31250
mov.w #256, &TACCR0
mov.w #0, &TACCR1
mov.w #TASSEL_2|MC_1, &TACTL ; SMCLK, DIV1, COUNT to TACCR0
mov.w #0, &TACCTL0
mov.w #0, &TACCTL1
;; Set up Timer B.
;; 32768 / 8000 = 4.096
mov.w #4, &TBCCR0 ; 32768 ticks = 1 second
mov.w #TBSSEL_1|MC_1, &TBCTL ; ACLK, DIV1, COUNT to TBCCR0
mov.w #CCIE, &TBCCTL0
mov.w #0, &TBCCTL1
mov.w #0, &TBCCTL2
;; 38.768kHz crystal interrupt
timer_interrupt_b:
cmp.w #sound_end, r4
jz timer_interrupt_b_skip
add.w #1, r12
mov.b @r4+, r5
mov.w r5, &TACCR1
timer_interrupt_b_skip:
reti
.org 0xfffa
dw timer_interrupt_b ; Timer1_A3 TBCCR0, CCIFG
.org 0xfffe
dw start ; Reset
*******************************************
UART
;; Setup UART (9600 @ 2 MHz)
mov.b #UCSSEL_2|UCSWRST, &UCA0CTL1
mov.b #0, &UCA0CTL0
mov.b #UCBRS_2, &UCA0MCTL
mov.b #220, &UCA0BR0
mov.b #0, &UCA0BR1
bic.b #UCSWRST, &UCA0CTL1
;special sections name
.text ;used for programm code ROM // FLASH
.data ;used for initialized non-const objects (global variables) EEPROM
.bss ;used for initialized objects (global variables) RAM
.const ;used for initialized const objects (string constants, variables declared const)
.cinit ;used for initialize C global variables at startup
.stack ;used for the function call stack
.sysmem ;used for the dynamic memory allocation pool
;*********************** status register ************************
15 / 9 8 7 6 5 4 3 2 1 0
** reserved ** V SCG1 SCG0 OSCoff CPUoff GIE N Z C
SCG1 ;system clock generator1 enable/disable functions in clock system
SCG0 ;system clock generator0 enable/disable functions in clock system
OSCoff ;oscillator off. when set, it turns of LFXT1 crystal oscillator