Quote:
Originally Posted by guy lateur
but this feels unintuitive and annoying
|
Well, assembler as a whole is unintuitive and annoying. You choose assembler if you need to optimize your code down to a certain number of CPU cycles or so. But it's surely not the language of choice for coding an application.
Quote:
Heck, I should probably just leave assembler altogether and start from C..
|
Given that you are already using C-like syntax for your pseudo code this would most likely be the easiest exercise.
Your code above can easily be turned into C with very little changes:
Code:
#include <math.h>
#include <stdio.h>
int main (void)
{
int nrSamples = 256;
float deltaAngle = 2.0 * M_PI / ((float) nrSamples);
float currAngle, currSine;
int iSample;
for (iSample = 0; iSample < nrSamples; iSample++)
{
currAngle = deltaAngle * ((float) iSample);
currSine = sin(currAngle);
printf("%3d : %f : %f\n", iSample, currAngle, currSine);
}
return (0);
}
Output:
Code:
0 : 0.000000 : 0.000000
1 : 0.024544 : 0.024541
2 : 0.049087 : 0.049068
3 : 0.073631 : 0.073565
4 : 0.098175 : 0.098017
5 : 0.122718 : 0.122411
6 : 0.147262 : 0.146730
7 : 0.171806 : 0.170962
8 : 0.196350 : 0.195090
9 : 0.220893 : 0.219101
10 : 0.245437 : 0.242980
11 : 0.269981 : 0.266713
12 : 0.294524 : 0.290285
13 : 0.319068 : 0.313682
14 : 0.343612 : 0.336890
15 : 0.368155 : 0.359895
16 : 0.392699 : 0.382683
17 : 0.417243 : 0.405241
18 : 0.441786 : 0.427555
19 : 0.466330 : 0.449611
20 : 0.490874 : 0.471397
21 : 0.515418 : 0.492898
22 : 0.539961 : 0.514103
23 : 0.564505 : 0.534998
24 : 0.589049 : 0.555570
25 : 0.613592 : 0.575808
26 : 0.638136 : 0.595699
27 : 0.662680 : 0.615232
28 : 0.687223 : 0.634393
29 : 0.711767 : 0.653173
30 : 0.736311 : 0.671559
31 : 0.760854 : 0.689541
32 : 0.785398 : 0.707107
33 : 0.809942 : 0.724247
34 : 0.834486 : 0.740951
35 : 0.859029 : 0.757209
36 : 0.883573 : 0.773010
37 : 0.908117 : 0.788346
38 : 0.932660 : 0.803207
39 : 0.957204 : 0.817585
40 : 0.981748 : 0.831470
41 : 1.006291 : 0.844854
42 : 1.030835 : 0.857729
43 : 1.055379 : 0.870087
44 : 1.079922 : 0.881921
45 : 1.104466 : 0.893224
46 : 1.129010 : 0.903989
47 : 1.153553 : 0.914210
48 : 1.178097 : 0.923880
49 : 1.202641 : 0.932993
50 : 1.227185 : 0.941544
51 : 1.251728 : 0.949528
52 : 1.276272 : 0.956940
53 : 1.300816 : 0.963776
54 : 1.325359 : 0.970031
55 : 1.349903 : 0.975702
56 : 1.374447 : 0.980785
57 : 1.398990 : 0.985278
58 : 1.423534 : 0.989176
59 : 1.448078 : 0.992480
60 : 1.472621 : 0.995185
61 : 1.497165 : 0.997290
62 : 1.521709 : 0.998795
63 : 1.546253 : 0.999699
64 : 1.570796 : 1.000000
65 : 1.595340 : 0.999699
66 : 1.619884 : 0.998795
67 : 1.644427 : 0.997290
68 : 1.668971 : 0.995185
69 : 1.693515 : 0.992480
70 : 1.718058 : 0.989177
71 : 1.742602 : 0.985278
72 : 1.767146 : 0.980785
73 : 1.791690 : 0.975702
74 : 1.816233 : 0.970031
75 : 1.840777 : 0.963776
76 : 1.865321 : 0.956940
77 : 1.889864 : 0.949528
78 : 1.914408 : 0.941544
79 : 1.938952 : 0.932993
80 : 1.963495 : 0.923880
81 : 1.988039 : 0.914210
82 : 2.012583 : 0.903989
83 : 2.037126 : 0.893224
84 : 2.061670 : 0.881921
85 : 2.086214 : 0.870087
86 : 2.110757 : 0.857729
87 : 2.135301 : 0.844854
88 : 2.159845 : 0.831470
89 : 2.184389 : 0.817585
90 : 2.208932 : 0.803208
91 : 2.233476 : 0.788346
92 : 2.258020 : 0.773010
93 : 2.282563 : 0.757209
94 : 2.307107 : 0.740951
95 : 2.331651 : 0.724247
96 : 2.356194 : 0.707107
97 : 2.380738 : 0.689541
98 : 2.405282 : 0.671559
99 : 2.429826 : 0.653173
100 : 2.454369 : 0.634393
101 : 2.478913 : 0.615232
102 : 2.503457 : 0.595699
103 : 2.528000 : 0.575808
104 : 2.552544 : 0.555570
105 : 2.577088 : 0.534998
106 : 2.601631 : 0.514103
107 : 2.626175 : 0.492898
108 : 2.650719 : 0.471397
109 : 2.675262 : 0.449611
110 : 2.699806 : 0.427555
111 : 2.724350 : 0.405241
112 : 2.748893 : 0.382683
113 : 2.773437 : 0.359895
114 : 2.797981 : 0.336890
115 : 2.822525 : 0.313682
116 : 2.847068 : 0.290285
117 : 2.871612 : 0.266713
118 : 2.896156 : 0.242980
119 : 2.920699 : 0.219101
120 : 2.945243 : 0.195091
121 : 2.969787 : 0.170962
122 : 2.994330 : 0.146731
123 : 3.018874 : 0.122411
124 : 3.043418 : 0.098017
125 : 3.067961 : 0.073565
126 : 3.092505 : 0.049068
127 : 3.117049 : 0.024541
128 : 3.141593 : 0.000000
129 : 3.166136 : -0.024541
130 : 3.190680 : -0.049067
131 : 3.215224 : -0.073564
132 : 3.239767 : -0.098017
133 : 3.264311 : -0.122411
134 : 3.288855 : -0.146730
135 : 3.313398 : -0.170962
136 : 3.337942 : -0.195090
137 : 3.362486 : -0.219101
138 : 3.387029 : -0.242980
139 : 3.411573 : -0.266713
140 : 3.436117 : -0.290284
141 : 3.460660 : -0.313682
142 : 3.485204 : -0.336890
143 : 3.509748 : -0.359895
144 : 3.534292 : -0.382683
145 : 3.558835 : -0.405241
146 : 3.583379 : -0.427555
147 : 3.607923 : -0.449611
148 : 3.632466 : -0.471397
149 : 3.657010 : -0.492898
150 : 3.681554 : -0.514102
151 : 3.706097 : -0.534997
152 : 3.730641 : -0.555570
153 : 3.755185 : -0.575808
154 : 3.779728 : -0.595699
155 : 3.804272 : -0.615231
156 : 3.828816 : -0.634393
157 : 3.853359 : -0.653173
158 : 3.877903 : -0.671559
159 : 3.902447 : -0.689540
160 : 3.926991 : -0.707107
161 : 3.951534 : -0.724247
162 : 3.976078 : -0.740951
163 : 4.000622 : -0.757209
164 : 4.025166 : -0.773010
165 : 4.049709 : -0.788346
166 : 4.074253 : -0.803207
167 : 4.098796 : -0.817585
168 : 4.123340 : -0.831469
169 : 4.147884 : -0.844853
170 : 4.172428 : -0.857729
171 : 4.196971 : -0.870087
172 : 4.221515 : -0.881921
173 : 4.246058 : -0.893224
174 : 4.270602 : -0.903989
175 : 4.295146 : -0.914210
176 : 4.319690 : -0.923879
177 : 4.344234 : -0.932993
178 : 4.368777 : -0.941544
179 : 4.393321 : -0.949528
180 : 4.417864 : -0.956940
181 : 4.442408 : -0.963776
182 : 4.466952 : -0.970031
183 : 4.491496 : -0.975702
184 : 4.516039 : -0.980785
185 : 4.540583 : -0.985278
186 : 4.565126 : -0.989176
187 : 4.589670 : -0.992479
188 : 4.614214 : -0.995185
189 : 4.638758 : -0.997290
190 : 4.663301 : -0.998795
191 : 4.687845 : -0.999699
192 : 4.712389 : -1.000000
193 : 4.736932 : -0.999699
194 : 4.761476 : -0.998795
195 : 4.786020 : -0.997290
196 : 4.810564 : -0.995185
197 : 4.835107 : -0.992480
198 : 4.859651 : -0.989177
199 : 4.884194 : -0.985278
200 : 4.908738 : -0.980785
201 : 4.933282 : -0.975702
202 : 4.957826 : -0.970031
203 : 4.982369 : -0.963776
204 : 5.006913 : -0.956940
205 : 5.031457 : -0.949528
206 : 5.056000 : -0.941544
207 : 5.080544 : -0.932993
208 : 5.105088 : -0.923880
209 : 5.129632 : -0.914210
210 : 5.154175 : -0.903989
211 : 5.178719 : -0.893224
212 : 5.203263 : -0.881921
213 : 5.227806 : -0.870087
214 : 5.252350 : -0.857729
215 : 5.276894 : -0.844854
216 : 5.301437 : -0.831470
217 : 5.325981 : -0.817585
218 : 5.350525 : -0.803208
219 : 5.375068 : -0.788347
220 : 5.399612 : -0.773011
221 : 5.424156 : -0.757209
222 : 5.448699 : -0.740951
223 : 5.473243 : -0.724247
224 : 5.497787 : -0.707107
225 : 5.522331 : -0.689541
226 : 5.546874 : -0.671559
227 : 5.571418 : -0.653173
228 : 5.595962 : -0.634394
229 : 5.620505 : -0.615232
230 : 5.645049 : -0.595699
231 : 5.669593 : -0.575808
232 : 5.694137 : -0.555570
233 : 5.718680 : -0.534998
234 : 5.743224 : -0.514103
235 : 5.767767 : -0.492898
236 : 5.792311 : -0.471397
237 : 5.816855 : -0.449611
238 : 5.841399 : -0.427555
239 : 5.865942 : -0.405241
240 : 5.890486 : -0.382684
241 : 5.915030 : -0.359895
242 : 5.939573 : -0.336890
243 : 5.964117 : -0.313682
244 : 5.988661 : -0.290285
245 : 6.013205 : -0.266713
246 : 6.037748 : -0.242981
247 : 6.062292 : -0.219102
248 : 6.086835 : -0.195091
249 : 6.111379 : -0.170962
250 : 6.135923 : -0.146731
251 : 6.160467 : -0.122411
252 : 6.185010 : -0.098017
253 : 6.209554 : -0.073565
254 : 6.234097 : -0.049068
255 : 6.258641 : -0.024542
OTOH it's not my intention to put you off from using assembler. You should do whatever is fun for you. Imposing some limits on yourself can be big fun. For example I have much fun in writing applications for Kick/WB 1.3. But then I wouldn't ask for help. The fun lies in the process to work it out yourself.