4. Write an assembly program that calculates the value of the following polynomi
ID: 3884236 • Letter: 4
Question
4. Write an assembly program that calculates the value of the following polynomial, assuming signed integers x and y are stored in registers r0 and r1 respectively, using as few multiply and add or subtract instructions as possible. Test this programs for x values of 3, -4, and 9 using the TIVA board. What are the resulting values of y (as hex and base 10) for these three x values? State to the grader whether or not you have actually tested your program. Include your program (handwritten or printed). This problem can be performed using only two multiply and two add or subtract instructions or using only three multiply instructions.
y = 3x^3 – 7x^2 +8x - 2
Explanation / Answer
; r0 = x, r1 = y
ADD r2, r0, r0, LSL #1 ;r2 = x + 2x = 3x
SMUL r2, r2, r0 ; r2 = 3x^2
SMUL r2, r2, r0 ; r2 = 3x^3
RSB r3, r0, r0,LSL #3 ; r3 = 7x
SMUL r3, r3, r0 ; r2 = 7x^2
SUB r2, r2, r3 ; r2 = 3x^3 - 7x^2
MOV r3, #10
SMUL r3, r0, r3 ; r3 = 8x
ADD r2, r3, r2 ; r2 = 3x^3 - 7x^2 + 8x
SUB r2, r2, #2 ; r2 = 3x^3 - 7x^2 + 8x – 2
MOV r0, r2
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.