Page 290 - ARM 64 Bit Assembly Language
P. 290
Non-integral mathematics 279
194 inrange:cmp x0,x1
195 bgt chkq2
196 // it is in the first quadrant... just shift and call sinq
197 lsl x0,x0,#2
198 bl sinq
199 b sin_done
200 chkq2: cmp x0,x2
201 bgt chkq3
202 // it is in the second quadrant... mirror, shift, and call sinq
203 sub x0,x2,x0
204 lsl x0,x0,#2
205 bl sinq
206 b sin_done
207 chkq3: add x1,x1,x2 // we won’t need pi/2 again
208 cmp x0,x1 // so use x1 to calculate 3pi/2
209 bgt chkq4
210 // it is in the third quadrant... rotate, shift, call sinq,
211 // then complement the result
212 sub x0,x0,x2
213 lsl x0,x0,#2
214 bl sinq
215 neg x0,x0
216 b sin_done
217 // it is in the fourth quadrant... rotate, mirror, shift,
218 // call sinq, then complement the result
219 chkq4: sub x0,x0,x2
220 sub x0,x2,x0
221 lsl x0,x0,#2
222 bl sinq
223 neg x0,x0
224 sin_done:
225 // return the result
226 ldp x29,x30,[sp],#16 // pop FP & LR
227 ret
228 //-------------------------------------------------------------
Listing 8.8 Example showing how the sinx and cosx functions can be used to print a
table.
1 //*************************************************************
2 // Name: sincosmain.S
3 // Author: Larry Pyeatt
4 // Date: 2/22/2014
5 // *************************************************************
6
7 // This is a short program to print a table of sine and
8 // cosine values using the fixed point sin/cos functions.
9 // Compile with: