-
Notifications
You must be signed in to change notification settings - Fork 0
/
demod.s
77 lines (69 loc) · 1.92 KB
/
demod.s
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
/ $Header: /home/karn/ace_rcs/RCS/demod.s,v 1.3 2000/01/04 07:53:40 karn Exp $
/ Demodulate buffer containing biphase-encoded data with square-wave carrier
/ C declaration:
/ void demod(signed short samples[], /* Input samples, 16-bit signed ints */
/ unsigned long endsync,/* Sample index containing the end-of-frame sync */
/ long symbols[], /* Demodulated output symbols */
/ long clock, /* Starting clock phase (2^32 counts/symbol) */
/ long cstep); /* Clock phase increment per input sample */
.file "demod.s"
.text
.align 16
.globl demod
.type demod,@function
demod:
pushl %ebp
movl %esp,%ebp
pushl %edi
pushl %esi
pushl %ebx
pushl %ecx
/ 8(%ebp) = samples
/ 12(%ebp) = endsync
/ 16(%ebp) = symbols
/ 20(%ebp) = clock
/ 24(%ebp) = cstep
movl 8(%ebp),%esi /esi = samples
movl 16(%ebp),%edi /edi = symbols
movl 20(%ebp),%ebx /ebx = clock
xorl %ecx,%ecx /ecx = i = 0
xorl %edx,%edx
movl 24(%ebp),%edi / edi = cstep
test %ebx,%ebx
.skip: jns .pos / clock already zero or positive
incl %ecx / skip leading samples on neg offset
addl %edi,%ebx
jmp .skip
.nextsym:
xorl %edx,%edx / edx = symbol = 0
movl 24(%ebp),%edi / edi = cstep
/ first half of symbol
.pos: movswl (%esi,%ecx,2),%eax / eax = symbols[i]
incl %ecx
addl %eax,%edx
addl %edi,%ebx / clock += cstep
jns .pos / until the clock sign bit sets
/ second half of symbol
.neg: movswl (%esi,%ecx,2),%eax / eax = symbols[i]
incl %ecx
subl %eax,%edx
addl %edi,%ebx / clock += cstep
jnc .neg / until the clock wraps
/ clock has wrapped, end of symbol
/ we test ecx here rather than in the sample loop to save time
/ it's possible to overrun the end of the sample buffer slightly,
/ but this seems like no big deal
cmpl 12(%ebp),%ecx
jg .done
movl 16(%ebp),%edi / edi = symbols
movl %edx,(%edi) / *symbols++ = symbol
addl $4,%edi
movl %edi,16(%ebp)
jmp .nextsym
.done: popl %ecx
popl %ebx
popl %esi
popl %edi
movl %ebp,%esp
popl %ebp
ret