home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 September
/
Simtel20_Sept92.cdr
/
msdos
/
ddjmag
/
ddj8612.arc
/
CAMPLST.DEC
< prev
next >
Wrap
Text File
|
1986-12-31
|
2KB
|
95 lines
«TS10,18,38»
; Listing One: Computing sine, cosine, and tangent
; NS-320XX assembler
; Sine, cosine, & tangent routines
RadScl MOVF PIO2,R2 ;Divide by pi/2 = 1.57079635
BR.S DoScal
DegScl MOVBF 90,R2 ;Scale for degrees
; Scale for sin cos, tan
DoScal DIVF R2,R3 ;Now 90 degrees = 1.00
DQuadr MOVBF 4,R4 ;4 = 360 degrees
MOVBF 1,R1 ;1 = 90 degrees
MOVBF 2,R2 ;2 = 180
MOVBF 3,R5 ;3 = 270
SnScl1 CMPF R3,R4 ;Is angle > 360 degrees?
BLT.S SnScl3 ;go if less than 360
SUBF R4,R3 ;else subtract 360
BR.S SnScl1 ;do it again
SnScl3 CMPF R3,R5 ;>270?
BLE.S SnScl5 ;no, go
SUBF R4,R3 ;make minus: ang=ang-360
SnScl5 CMPF R3,R1 ;>90?
BLE.S ScnCl7
SUBF R3,R2
MOVF R2,R3 ;ang=180-ang
ScnCl7 RET ;scaled value in R3
ACos MOVBF 90,R2 ;angle, degrees in R3
DIVF R2,R3 ;divide by 90
MOVBF 1,R2
ADDF R2,R3 ;make angle plus 90
BSR DQuadr ;figure quadrant
BR.S DoSin ;go do sine, return from it
ASin BSR DegScl ;Angle in degrees
;Fall through to...
; Compute Sine(x)
; Sine = 0 + 1.570795*X -0.645921*X^3
; + 0.07946765*X^5 - 0.004362469*X^7
DoSin ADDR SNTAB,R0 ;get address of table
MOVQ.D 4,R6 ;init R6
; Enter with table addrs in R0, # terms in R6
MOVF R3,R1 ;save angle in R1
MOVF R1,R5 ;and in R5
MOVBF 0,R3 ;sine starts at zero
SinLp MOV.D 0(R0)[R6:D],SNTAB ;get multiplier
MULF R5,SNTAB ;mult angle
ADDF SNTAB,R3 ;add to sine
MULF R1,R5 ;angle ^ n+2
MULF R1,R5
ACB.BS -1,R6,SinLp ;do again till done
RET
; Compute Tan(x)
; Tan(x) = Sin(x)/Cos(x)
ATan MOVBF 90,R2 ;scale for degrees
DIVF R2,R3
MOVF R3,SNTEMP ;save scaled angle
BSR DQuadr ;figure quadrant
BSR DoSin ;compute sin
MOVF R3,TOS ;save sine on stack
MOVBF 1,R3
ADDFF SNTEMP,R3 ;add for cosine
BSR DQuadr ;figure quadrant
BSR DoSin ;compute cosine
MOVF R3,R2 ;move cosine to R2
MOVF TOS,R3 ;recover sine
; R0 now = 0
CMPF R0,R2 ;have zero?
BNE.S ATanDv ;no, divide
MOVF FNSM,R3 ;else use big number
RET
ATanDv DIVF R2,R3 ;Tan = Sin/Cos
RET
FNSM BYTE 0,0C0h,0DAh,45h ;7000
PIO2 BYTE 0DBh,0Fh,0C9h,3Fh ;pi/2 = 1.57079635
SNTEMP BLK.D 1 ;temporary storage
SNTAB BLK.D 1 ;temp
; these are in reverse order of use
BYTE 0Bh,0F3h,8Eh,0BBh ;-0.004362469
BYTE 6Ch,0CAh,0A2h,03Dh ;0.07948765
BYTE 14h,5Bh,25h,0BFh ;-0.645921
BYTE 0D0h,0Fh,0C9h,3Fh ;1.570795