Omnimaga

Calculator Community => TI Calculators => ASM => Topic started by: ralphdspam on August 07, 2011, 05:30:32 pm

Title: Trig in ASM
Post by: ralphdspam on August 07, 2011, 05:30:32 pm
Does anyone have fast 8.8 Fixed-Point tan and sin routines?  (Period of $FF.FF)
It does not have to be exact, but it has to be relatively fast. 

Or would a look up table be better suited? 
Title: Re: Trig in ASM
Post by: ben_g on August 07, 2011, 05:34:29 pm
I use this routine for a sin in my z80 project:
Quote from: Z80 Assembly
SinA:
  ;calculates the sine of a as a fixed point number
  ;IN: a
  ;OUT: hl = sin(a)
    LD     h, 0
    LD     l, a
    add hl, hl
    LD     DE, sine_table
    ADD    HL, DE
    LD     A, (HL)
    INC    HL
    LD     H, (HL)
    LD     L, A
    RET
sine_table:
.dw    0, 6, 13, 19, 25, 31, 38, 44, 50, 56, 62, 68, 74, 80, 86, 92, 98, 104, 109, 115, 121, 126, 132, 137, 142
.dw    147, 152, 157, 162, 167, 172, 177, 181, 185, 190, 194, 198, 202, 206, 209, 213, 216, 220, 223, 226, 229, 231, 234
.dw    237, 239, 241, 243, 245, 247, 248, 250, 251, 252, 253, 254, 255, 255, 256, 256, 256, 256, 256, 255, 255, 254, 253
.dw    252, 251, 250, 248, 247, 245, 243, 241, 239, 237, 234, 231, 229, 226, 223, 220, 216, 213, 209, 206, 202, 198, 194
.dw    190, 185, 181, 177, 172, 167, 162, 157, 152, 147, 142, 137, 132, 126, 121, 115, 109, 104, 98, 92, 86, 80, 74, 68
.dw    62, 56, 50, 44, 38, 31, 25, 19, 13, 6, 0, -6, -13, -19, -25, -31, -38, -44, -50, -56, -62, -68, -74, -80, -86, -92
.dw    -98, -104, -109, -115, -121, -126, -132, -137, -142, -147, -152, -157, -162, -167, -172, -177, -181, -185, -190,
.dw    -194, -198, -202, -206, -209, -213, -216, -220, -223, -226, -229, -231, -234, -237, -239, -241, -243, -245, -247
.dw    -248, -250, -251, -252, -253, -254, -255, -255, -256, -256, -256, -256, -256, -255, -255, -254, -253, -252, -251
.dw    -250, -248, -247, -245, -243, -241, -239, -237, -234, -231, -229, -226, -223, -220, -216, -213, -209, -206, -202
.dw    -198, -194, -190, -185, -181, -177, -172, -167, -162, -157, -152, -147, -142, -137, -132, -126, -121, -115, -109
.dw    -104, -98, -92, -86, -80, -74, -68, -62, -56, -50, -44, -38, -31, -25, -19, -13, -6

Generated by the BBify'r (http://clrhome.tk/resources/bbify/ (http://clrhome.tk/resources/bbify/))

and for tan, I use sin(x)/sin(x+90°), which has the same result

I hope this is what you are looking for.

BTW: look up tables are big, so i would only reccomend them when you really need the speed.
Title: Re: Trig in ASM
Post by: Ashbad on August 07, 2011, 05:34:36 pm
Does anyone have fast 8.8 Fixed-Point tan and sin routines?  (Period of $FF.FF)
It does not have to be exact, but it has to be relatively fast. 

Or would a look up table be better suited? 

Just rip from Axe
Title: Re: Trig in ASM
Post by: ralphdspam on August 09, 2011, 11:46:46 am
Just rip from Axe
Quote from: Axe Commands: Sin
Returns the sine of the expression. One Period is [0,256] and the value returned ranges from -127 to 127.
I can probably modify the code, though.