Code: Select all
; function TAN, angle in DEG
3620: mov #0002,r2
3624: br 362E
; function TAN, angle in GRA
3626: mov #0004,r2
362A: br 362E
; function TAN, angle in RAD
362C: clr r2
; the angle is trimmed to the range 0..PI/2 RAD (or 0..90 DEG, or 0..100 GRA)
362E: jsr r4,3AA8
3632: .dw 37AE ;DUP (skip the return address)
.dw 3728 ;constant PI/2 (or 90, or 100)
.dw 2CF6 ;FP modulo, remainder on the stack, qoutient in r0
.dw 374A ;save the quadrant r0 to 10(sp)
.dw 373A ;constant PI/2 (or 90, or 100)
.dw 2C7E ;FP multiply
.dw 3640
; data on the stack:
; 4 words - trimmed angle, pointed to by sp
; 1 word - return address, pointed to by 08(sp)
; 1 word - biased exponent of the absolute value of the initial angle,
; pointed to by 0A(sp)
; 1 word - pointed to by 0C(sp)
; 1 word - argument mode (0=RAD, 2=DEG, 4=GRA), pointed to by 0E(sp)
; 1 word - quadrant of the angle, pointed to by 10(sp)
3640: mov 0010(sp),r0 ;quadrant
3644: mov r0,r1
3646: bic #FFF0,r1 ;the "ones" digit of the quadrant
364A: bic #FF0F,r0 ;the "tens" digit of the quadrant
364E: asr r0
3650: add r0,r1
3652: asl r1
3654: asl r1
3656: add r1,r0 ;r0 = 40*tens + 4*ones = 4*quadrant
3658: bic #FFF0,r0
365C: asl 000A(sp) ;biased exponent of the initial angle
3660: ror r0
3662: add r0,000C(sp)
; if angle > PI/4 then angle = PI/2-angle
; TAN(PI/2 - x) = 1/TAN(x)
3666: mov #4,r0 ;up to 4 words to compare
366A: mov 000E(sp),r1 ;argument mode
366E: asl r1
3670: asl r1
3672: add #37F8,r1 ;table of FP constants PI/4, 45, 50
3676: mov sp,r2 ;r2 points to the angle
3678: cmp (r2)+,(r1)+
367A: bcs 3680
367C: bne 36CA
367E: sob r0,3678
; convert the angle to RAD
3680: mov 000E(sp),r1 ;argument mode
3684: beq 3698 ;skip if RAD mode
3686: asl r1
3688: asl r1
368A: add #3830,r1 ;table of FP constants PI/180, PI/200
368E: jsr r4,3AA8
3692: .dw 37C0 ;push a FP number pointed to by r1 on the stack
.dw 2C7E ;FP multiply
.dw 3698
;
3698: mov r3,r5
369A: add #A,r3
369E: mov 000C(sp),r0
36A2: mov (sp),r1
36A4: beq 36F8
36A6: add #F000,r1
36AA: clr (sp)
36AC: sub #10,sp
36B0: mov r0,-(sp)
36B2: mov r1,-(sp)
36B4: mov #3798,r1
36B8: jsr r4,3AA8
36BC: .dw 37C0 ;push 4 words pointed to by r1 on the stack
.dw 37C0 ;push 4 words pointed to by r1 on the stack
.dw 391E ;move the trimmed angle to another location
.dw 396E ;integer BCD multiplication by ten
.dw 394A ;initial quotient Q = 0000 0000 0000 0000
.dw 3AAC ;unconditional jump
.dw 316E ;address = first EXP(x) iteration loop
36CA: inc 000C(sp)
36CE: jsr r4,3AA8
36D2: .dw 2E18 ;change the sign of a FP number
.dw 373A ;constant PI/2 (or 90, or 100)
.dw 2B46 ;FP add
.dw 3680
; end of the TAN calculation
36DA: movb (sp),r1 ;iteration counter J
36DC: sub #0C,r1
36E0: neg r1
36E2: add #1001,r1 ;exponent bias
36E6: movb 0001(sp),r0
36EA: sub r0,r1
36EC: add 0010(sp),r1 ;offset to the table of constants
36F0: mov 0012(sp),r0
36F4: sub #10,r5 ;r5 points to the end of the quotient now
36F8: mov -(r5),-(r3) ;copy the result to the destination place
36FA: mov -(r5),-(r3)
36FC: mov -(r5),-(r3)
36FE: mov r1,-(r3) ;exponent
3700: tst -(r3) ;= sub #2,r3
3702: mov r3,sp ;sp points to the return address now
3704: bit #0300,r0
3708: bne 3726
370A: bit #0002,r0
370E: beq 371C
3710: tst r1
3712: bne 3718
3714: jmp 3AA4 ;ERR3
3718: add #8000,r0
371C: tst r0
371E: bpl 3726
3720: add #8000,0002(sp) ;result = -result
3726: rts pc
3728: bic #8000,(sp) ;absolute value of the argument
372C: mov r2,r1 ;index to the table 3744
372E: movb r1,r1 ;byte to word conversion
3730: clrb r2
3732: mov r2,000C(sp)
3736: mov r1,000E(sp)
; returns the constant PI/2 or 90 or 100 depending on the argument mode
373A: mov 000E(sp),r1 ;index to the table 3744
373E: mov 3744(r1),r1
3742: br 37C0 ;push a FP number pointed to by r1 on the stack
3744: .dw 37F8 ;points to a FP number PI/2
.dw 3818 ;points to a FP number 90.0000000000
.dw 3820 ;points to a FP number 100.000000000
; save the quadrant r0 to 10(sp)
374A: mov r0,0010(sp)
374E: jmp @(r4)+
; prepare for the third iteration: division A/B
3750: mov #3234,0006(sp) ;branch address when A < B
3756: mov #37A4,0008(sp) ;branch address when end of iteration
375C: mov 0012(sp),r0
3760: asr r0
3762: adc r0
3764: asr r0
3766: bcc 3782
; swap the coordinates A and B to calculate reciprocal of the tangent (for
; angle values in range PI/4..PI/2)
3768: mov #4,r0
376C: mov -(r5),r1
376E: mov -(r3),(r5)
3770: mov r1,(r3)
3772: sob r0,376C
3774: add #8,r5
3778: add #8,r3
377C: neg 0010(sp)
3780: negb (sp)
3782: swab (sp)
3784: jmp 38AA ;conditional branch