Get the answers you need at Westonci.ca, where our expert community is always ready to help with accurate information. Our platform connects you with professionals ready to provide precise answers to all your questions in various areas of expertise. Get immediate and reliable solutions to your questions from a community of experienced professionals on our platform.

Write a function (subroutine) that inputs a data value in register r0 and returns value in r0. The function returns y 5 a 1 bx 1 cx2, where a, b, and c are parameters built into the function (i.e., they are not passed to it). The subroutine also performs clipping. If the output is greater than a value d, it is constrained to d (clipped). The input in r0 is a positive binary value in the range 0 to 0xFF. Apart from r0, no other registers may be modified by this subroutine. Write ARM code to implement the following C operation.

Int s=0;
for ( i = 0; i < 10; i++) { s = s + i*i;)


Sagot :

Solution :

  int f(int x){

      [tex]\text{return a + b*x +c*x*x}[/tex];

  }*/

  int f([tex]\text{int R0}[/tex]){

      int stack[2] = {[tex]\text{R1,R2}[/tex]};

      [tex]\text{R1 = R0}[/tex];

      [tex]\text{R1 = R1}\times \text{ R1}[/tex];

      [tex]\text{R2 = C}[/tex];

      R1 = R1 * C; /*R1 = [tex]cx^2[/tex]*/

      [tex]\text{R2 = B}[/tex];

      [tex]\text{R0 = R0}[/tex] * R2; /* R0 = bx */

      [tex]\text{R0 = R0 + R1}[/tex]; /*R0 = [tex]bx + cx^2[/tex] */

      [tex]\text{R2 = C}[/tex];

      [tex]\text{R0 = R0 + R2}[/tex]; /*R0 = a+bx+cx^2 */

      [tex]\text{R1 = stack[0];}[/tex]

     [tex]\text{ R2 = stack[1];}[/tex]

     [tex]\text{ return R0;}[/tex]

  }

  /*[tex]\text{ARM code to implement the following C operation}[/tex]

  int s=0;

  [tex]\text{for ( i = 0; i < 10; i++)}[/tex]

  { [tex]\text{s = s + i } \times i[/tex];)

  */

          AREA SumSquares, code, readWrite

          ENTRY

          [tex]\text{MOV r0, #0}[/tex]        ;loop [tex]\text{ counter i present at 0}[/tex]

          MOV r1, #0       ; s = 0

  Loop   [tex]\text{MUL r2, r0, r0}[/tex]   ;calculate i*i

          [tex]\text{ADD r1, r1, r2}[/tex]   ;s = s+ i*i

          [tex]\text{ADDS r0, r0}[/tex], #1   ; i = i+1

          [tex]\text{CMP r0}[/tex],#10       ; test for end

          [tex]\text{BNE}[/tex] Loop        ; [tex]\text{continue until all added}[/tex]

          END