Please Solve the following problem by using ARMv8 2.26 [10] <§2.7> Translate the
ID: 3851270 • Letter: P
Question
Please Solve the following problem by using ARMv8
2.26 [10] <§2.7> Translate the following C code to LEGv8 assembly code. Use a minimum number of instructions. Assume that the values of a, b, i, and j are in registers X0,X1,X10, and X11, respectively. Also, assume that register X2 holds the base address of the array D.
2.27 [5] <§2.7> How many LEGv8 instructions does it take to implement the C code from Exercise 2.26? If the variables a and b are initialized to 10 and 1 and all elements of D are initially 0, what is the total number of LEGv8 instructions executed to complete the loop?
Explanation / Answer
2.26 solution:
given c code
For (i = 0; i < a; i++)
For (j = 0; j < b; j++)
D[4*i] = i + j;
translated legv8 code
Instruction *
SUBI X10,XZR,1
ADD X10, X10, 1
SUB X3, X10, X0 CBZ X3,
exit
SUBI X11, XZR, 1 L2:
ADD X11, X11, 1
SUB X4, X11, X1 CBZ X4, L1
ADD X5, X10, X10 ADD X6, X11, X11
ADD X6, X6, X11
ADD X5, X5, X6 LSL X6, X10, #3
ADD X6, X6, X2 STUR X5, [X6, #0] B L2
exit
L1: Comment * i = -1
L1: i = i + 1
temp1 = i - a
if temp1==0,
exit
j=-1 L2:
j = j+1
temp2 = j - b
if temp2==0,
L1 temp3 = i + i
temp4 = j + j
temp4 = temp4 + j
temp3 = temp3 + temp4 lsl temp4, i, #3
temp4 = temp4 + X2 stur temp3,
[temp4, #0] goto L2
exit
2.27 solution:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.