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

Suppose you need to evaluate the polynomial 5. of X. If this is done in the obvi

ID: 3701325 • Letter: S

Question

Suppose you need to evaluate the polynomial 5. of X. If this is done in the obvious way, as for some value 5XX"X-7"x"x+ 3"X-10 there are six multiplications and three additions/subtractions. An equivalent form, based on Horner's scheme for evaluation of polynomials, is ((5%-7)% + 3)%-10 This has only three multiplications. Suppose that the value of x is in the EAX register lal Write 80x86 assembly language statements that will evaluate ploj the "obvious" way, putting the result in EAX. putting the result in EAX. (b) above. (b) Write 80x86 assembly language statements that will evaluate p(x) using Horner's scheme, again (c) Compare the number of bytes of object code required for the code fragments in (a) and in

Explanation / Answer

a. normal method

    DATA SEGMENT

    a DB 05H

    b DB 07H

    d DB 03H

    e DB 10H

CODE SEGMENT

ASSUME CS:CODE, DS:DATA

     START:

     MOV AX,DATA

      MOV AH,1H        keyboard input subprogram

      INT 21H                read input and stored in AL

      MOV C,AL          copy AL to C

      MUL C,C           multiply values in C and C and store result in AL

    MUL AL,C          multiply values in C and AL and store result in AL

      MUL AL,a          multiply with value of a here done is that 5*x*x*x

     MOV a,AL          move result in AL to a

     MUL C,C             multiply c and c c*c and store to AL

     MUL AL,b           multiply b with AL 7*x*x

     MOV b,AL          move value of AL into b

     MUL c,d             multiply c and d   3*x and store

     MOV d,AL         move result to d

     SUB a,b             substract b from a and store in AL   5*x*x*x - 7*x*x

     SUB e substarct    5*x*x*x - 7*x*x -10

     ADD d              add value in e    5*x*x*x - 7*x*x - 10 + 3*x

   CODE ENDS

    END START

b. Horner's scheme

     DATA SEGMENT

    a DB 05H

    b DB 07H

    d DB 03H

    e DB 10H

CODE SEGMENT

ASSUME CS:CODE, DS:DATA

     START:

     MOV AX,DATA

      MOV AH,1H        keyboard input subprogram

      INT 21H                read input and stored in AL

      MOV C,AL          copy AL to C

      MUL c,a              multiply values in c and a and store into AL        5*x

      SUB   b               substract b from value in AL store into AL          5*x-7

      MUL   c              multiply value in AL with c and store in AL         (5*x-7)*x

      ADD d             add d with value in AL and store in AL                (5*x-7)*x+3

      MUL c              multiply value in AL with c and store in AL          ((5*x-7)*x+3)*x

      SUB   e            substract value in e from AL   and store in AL       ((5*x-7)*x+3)*x-10

     CODE ENDS

    END START

c. in a we use 6 multiplication 2 substraction and 1 addition

    in b we use 3 multiplication 2 substracton and 1 addition

   

    

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