Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Find the infinite series for SIN(X) in a calculus book and implement it in a sub

ID: 3683851 • Letter: F

Question

Find the infinite series for SIN(X) in a calculus book and implement it in a subroutine called SIN. Use EPOWER as an example of how to do this.

EPOWER is written for MASM and the program code I am to use is modeled after EPOWER. I am to model a new subroutine called SIN that will find the infinite series for SIN(X). The EPOWER program code is:

          .MODEL SMALL

          .DATA

X         DB     0,1,0,0,0

TEMP      DB     5 DUP(?)

ETOX      DB     5 DUP(?)

ZERO      DB     0,0,0,0,0

          .CODE

          .STARTUP

          CALL   EPOWER

          .EXIT

EPOWER    PROC   FAR

          LEA    SI,ZERO             ;predefined constant 0

          LEA    DI,ETOX

          CALL   FAR PTR COPY        ;clear result

          MOV    CX,10               ;init loop counter

NEXTERM: LEA    SI,X                ;compute numerator

          MOV    AL,CL

          CALL   FAR PTR POWER

          LEA    BX,TEMP             ;save numerator

          CALL   FAR PTR SAVE

          MOV    AL,CL               ;compute denominator

          CALL   FAR PTR FACTORIAL

          LEA    SI,TEMP             ;divide to generate term

          XCHG   BP,DI

          CALL   FAR PTR DIVIDE

          XCHG   BP,DI               ;add current term to result

          LEA    SI,ETOX

          CALL   FAR PTR ADDER

          LEA    BX,ETOX             ;save result

          CALL   FAR PTR SAVE

          LOOP   NEXTERM

          RET

EPOWER    ENDP

COPY      PROC   FAR

          RET

COPY      ENDP

POWER     PROC   FAR

          RET

POWER     ENDP

Explanation / Answer

The FPU instructions perform trigonometric operations with the value in the TOP data register ST(0).

FSIN (Sine of the angle value in ST(0))

Syntax:    fsin (no operand)

Exception flags: Stack Fault, Invalid operation, Denormalized value,

                 Underflow, Precision

This instruction computes the sine of the source angle value in ST(0) and overwrites the content of ST(0) with the result. The angle must be expressed in radians and be within the -263 to +263 range.

If the source angle value is outside the acceptable range (but not INFINITY), the C2 flag of the Status Word is set to 1 and the content of ST(0) remains unchanged, no exception being detected. (The source value can be reduced to within the acceptable range with the FPREM instruction using a divisor of 2.)

An Invalid operation exception is detected if the TOP data register ST(0) is empty, or is a NAN, or has a value of INFINITY, setting the related flag in the Status Word. The content of ST(0) would be overwritten with the INDEFINITE value.

A Stack Fault exception is also detected if ST(0) is empty, setting the related flag in the Status Word.

A Denormal exception is detected when the content of ST(0) is a denormalized number or the result is a denormalized number, setting the related flag in the Status Word.

A Precision exception will be detected if some fraction bit is lost due to rounding, setting the related flag in the Status Word.

An Underflow exception will be detected if the result exceeds the range limit of REAL10 numbers, setting the related flag in the Status Word.

The relation between degrees and radians is as follows:

180 degrees = radians

To compute the sine of an angle expressed in degrees in ST(0), the following code could be used to first convert the value in ST(0) from degrees to radians and check for errors before the FSIN instruction.

fclex        ;clear all previous exceptions

   pushd 180    ;store the integer value of 180 on the stack

   fidiv dword ptr[esp]   ;divide the angle in degrees by 180

                ;-> ST(0)=angle in degrees/180

   fldpi        ;load the hard-coded value of

                ;-> ST(0)=, ST(1)=angle in degrees/180

   fmul         ;-> ST(0)=angle in degrees*/180, => angle in radians

   fsin         ;compute the sine of the angle

                ;-> ST(0)=sin(angle) if no error

   fstsw [esp] ;store the Status Word on the stack overwriting the 180

   fwait        ;to insure the last instruction is completed

   pop   eax    ;get the Status Word in AX (which also cleans the stack)

   shr   al,1   ;transfer the Invalid op flag (bit0 of AL) to the CF flag

   jnc   @F     ;jump if no invalid operation detected

   ........     ;insert code to handle an invalid operation

                ;-> ST(0)=INDEFINITE (angle has been trashed)

@@:

   sahf         ;transfer AH to the CPU flag register

   jpo   @F     ;jump if PF=C2=0 meaning angle value is in acceptable range

   ........     ;insert code to handle angle ouside acceptable range

                ;-> ST(0)=angle in radians unchanged

@@:             ;-> ST(0)=sin(angle) -- no error

note-the above explanation can help to answer the given question,

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote