; rx are registers ; "add r0,r1,r2" means add r2 to r1 and keep the result in r0 ; "mov r0,r1,asr 02h" means move r1 to r0 after doing an arithmetic shift right by 2 ; mul is multiply ; mov is move ; rsb is reverse subtraction, i.e.: "rsb r0,r1,r2" means r0 = r2-r1 ("sub r0,r1,r2" would be r0 = r1-r2) ; add is addition ; bx r14 is the return instruction ; r0 = arctan(r0>>0Eh)*8000h/pi ; The parameter is in r0, it's 16-bits in the format: sidddddddddddddd where s is the sign, i is the integral part, d is the decimal part ; The return value is r0, its range is C000h-4000h, where C000 is equivalent to -4000h, 4000h is equivalent to pi/2 radians (90 degrees) and C000h is equivalent to -pi/2 radians (-90 degrees) mul r1,r0,r0 ;\ mov r1,r1,asr 0Eh ;} r1 = -r0²/4000h rsb r1,r1,0h ;/ mov r3,0A9h ;\ mul r3,r1,r3 ;} r3 = 169r1/4000h mov r3,r3,asr 0Eh ;/ add r3,r3,390h ;\ mul r3,r1,r3 ;} r3 = (912 + r3)r1/4000h mov r3,r3,asr 0Eh ;/ add r3,r3,900h ;\ add r3,r3,1Ch ;| mul r3,r1,r3 ;} r3 = (2332 + r3)r1/4000h mov r3,r3,asr 0Eh ;/ add r3,r3,0F00h ;\ add r3,r3,0B6h ;| mul r3,r1,r3 ;} r3 = (4022 + r3)r1/4000h mov r3,r3,asr 0Eh ;/ add r3,r3,1600h ;\ add r3,r3,0AAh ;| mul r3,r1,r3 ;} r3 = (5802 + r3)r1/4000h mov r3,r3,asr 0Eh ;/ add r3,r3,2000h ;\ add r3,r3,81h ;| mul r3,r1,r3 ;} r3 = (8321 + r3)r1/4000h mov r3,r3,asr 0Eh ;/ add r3,r3,3600h ;\ add r3,r3,51h ;| mul r3,r1,r3 ;} r3 = (13905 + r3)r1/4000h mov r3,r3,asr 0Eh ;/ add r3,r3,0A200h ;\ add r3,r3,0F9h ;| mul r0,r3,r0 ;} r0 = (41721 + r3)r0/10000h mov r0,r0,asr 10h ;/ bx r14 ; r0 = (41721 - (13905 - (8321 - (5802 - (4022 - (2332 - (912 - 169 r0²/4000h²)r0²/4000h²)r0²/4000h²)r0²/4000h²)r0²/4000h²)r0²/4000h²)r0²/4000h²)r0/10000h ; r0 = 41721/2^16 r0 - 13905/2^44 r0^3 + 8321/2^72 r0^5 - 5802/2^100 r0^7 + 4022/2^128 r0^9 - 2332/2^156 r0^11 + 912/2^184 r0^13 - 169/2^212 r0^15 ; r0 = 0.637 r0 - 7.90/10^10 r0^3 + 1.76/10^18 r0^5 - 4.58/10^27 r0^7 + 1.18/10^35 r0^9 - 2.55/10^44 r0^11 + 3.72/10^53 r0^13 - 2.57/10^62 r0^15 ; Conversion from output to radians: r0 pi/8000h ; r0_radians = 6.10/10^5 r0 - 7.58/10^14 r0^3 + 1.69/10^22 r0^5 - 4.39/10^31 r0^7 + 1.13/10^39 r0^9 - 2.45/10^48 r0^11 + 3.57/10^57 r0^13 - 2.46/10^66 r0^15 ; Real Taylor series: arctan(x/4000h) ~= 6.10/10^5 x - 7.58/10^14 x^3 + 1.69/10^22 x^5 - 4.51/10^31 x^7 + 1.31/10^39 x^9 - 3.98/10^48 x^11 + 1.25/10^56 x^13 - 4.05/10^65 x^15