1) Translate the following C code to LEGv8. Assume the variables f, g, h, i, and j are assigned to registers X0, X1, X2, X3, and X4. Assume the base address of arrays A and B are in X6 and X7, and that each element in the arrays takes up 8 bytes.
A) j = f - (h - i) + 5;
B) Same as above, but translate this statement: B[8] = A[i] + A[j];
C) Same as above, but now translate from LEGv8 into C:
ADDI X9, X6, #8
ADD X10, X6, XZR
STUR X10, [X9, #0]
LDUR X9, [X9, #0]
ADD X0, X9, X10
X0 = f
X1 = g
X2 = h
X3 = i
X4 = j
X6 = base address of array A
X7 = base address of array B
(A)j = f - (h-i) + 5
SUB X8, X2, X3 //X8 = h-i
SUB X8, X0, X8 //X8 = f-(h-i)
ADDI X4, X8, #5 //j = f-(h-i) + 5
(B)B[8] = A[i] + A[j];
SLL X9, X3, 3 //x9 = 8*i
ADD X9, X6, X9 //x9 = address of A[i]
LDUR X9, [X9,#0] //x9 = A[i]
SLL X10, X3, 3 //x10 = 8*j
ADD X10, X6, X10 //x10 = address of A[j]
LDUR X10, [X10,#0] //x10 = A[j]
ADD X9, X9, X10 //X9 = A[i] + A[j]
STUR X9, [X7, #8] //B[8] = A[i] + A[j]
(C)
ADDI X9, X6, #8 //X9 = address of A[1]
ADD X10, X6, XZR //X10 = address of A[0]
STUR X10, [X9, #0] //A[1] = address of A[0]
LDUR X9, [X9, #0] //X9 = A[1]
ADD X0, X9, X10 // f = 2* address of A[0]
C code
f = 2* &A[0];
1) Translate the following C code to LEGv8. Assume the variables f, g, h, i, and...