Skip to content

Commit be27cdc

Browse files
committed
add a compatibilty test for evaluating expressions
This is a common example, where the ADC is read multiple times (oversampled) and the oversampling factor is calculated by a shift-left, which makes calculating the average of samples as easy as shifting their sum right by the same amount of bits. Using .set directives with expressions makes the oversampling factor easily configurable.
1 parent 4962139 commit be27cdc

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/compat/expr.S

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
.set adc_channel, 6
2+
3+
.set adc_oversampling_factor_log, 2
4+
.set adc_oversampling_factor, (1 << adc_oversampling_factor_log)
5+
6+
.data
7+
8+
result:
9+
.long 0
10+
11+
.text
12+
.global entry
13+
entry:
14+
move r0, 0
15+
stage_rst
16+
17+
measure:
18+
adc r1, 0, adc_channel + 1
19+
add r0, r0, r1
20+
21+
stage_inc 1
22+
jumps measure, adc_oversampling_factor, lt
23+
24+
rsh r0, r0, adc_oversampling_factor_log
25+
26+
move r3, result
27+
st r0, r3, 0
28+
29+
exit:
30+
halt

0 commit comments

Comments
 (0)