Skip to content

Commit 87507c9

Browse files
committed
add a compatibility 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 feb42dc commit 87507c9

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

tests/compat/expr.S

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
#test that expressions evaluate correctly for all supported operators
30+
move r3, 1+2
31+
move r3, 3-5
32+
move r3, -5
33+
move r3, 2*3
34+
move r3, 4/2
35+
move r3, 4 % 3
36+
move r3, 0xff << 2
37+
move r3, 0xff >> 1
38+
move r3, (0xabcdef | 0xff) & 0xff
39+
move r3, 0x1234 & ~2
40+
move r3, 42|4&0xf # 46 (4&0xf is evaluated first)
41+
move r3, (42|4)&0xf # 14 (42|4 is evaluated first)
42+
43+
exit:
44+
halt

0 commit comments

Comments
 (0)