ARM assembly language answer could use RSB, SUBS, ADD, MUL, LSL, LSR instruction
ID: 2085812 • Letter: A
Question
ARM assembly language
answer could use RSB, SUBS, ADD, MUL, LSL, LSR instructions and PLEASE TAKE NOT THAT THE PROBLEM SAYS TO USE ONLY 2 MULTIPLY AND 2 SUBTRACT OR ADD INSTRUCTIONS FOR A TOTAL OF 4 INSTRUCTIONS
4. Write an assembly program that calculates the value of the following polynomial, assuming signed integers x and y are stored in registers rO and rl 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. y 3x3-7x2 +8-2Explanation / Answer
#include<stdio.h>
int main()
{
int a,b,c,d,x,fx,gx;
scanf("%d%d%d%d%d",&a,&b,&c,&d,&x);
fx=a*x*x*x-b*x*x+c*x-d;
__asm
{
mov EAX,0
mov gx,EAX
mov EAX,x
mul x
mul x
mul a
add gx,EAX
mov EAX,x
mul x
mul b
add gx,EAX
mov EAX,c
mul x
add gx,EAX
mov EAX,d
add gx,EAX
}
printf("%d n %d n",gx,fx);
}
The first part of the code until the __asm code block should make sense. Now the assembly part implements basic concepts of assembly language programming. At first, we are working with the EAX register. We set its value to zero in order to clean up some possible leftovers (if there are any).