2.9 [10] <§§2.2, 2.3> Translate the following LEGv8 code to C. Assume that the v
ID: 2078308 • Letter: 2
Question
2.9 [10] <§§2.2, 2.3> Translate the following LEGv8 code to C. Assume that
the variables f, g, h, i, and j are assigned to registers X0,X1,X2,X3, and X4,
respectively. Assume that the base address of the arrays A and B are in registers X6
and X7, respectively.
ADDI X9, X6, #8
ADD X10, X6, XZR
STUR X10, [X9, #0]
LDUR X9, [X9, #0]
ADD X0, X9, X10
2.10 [20] <§§2.2, 2.5> For each LEGv8 instruction in Exercise 2.9, show the value
of the opcode (Op), source register (Rn), and target register (Rd or Rt) fields. For
the I-type instructions, show the value of the immediate field, and for the R-type
instructions, show the value of the second source register (Rm).
2.13 [5] <§§2.2, 2.5> Provide the instruction type and assembly language
instruction for the following binary value:
1000 1011 0000 0000 0000 0000 0000 0000two (the two at the end is a subscript)
Hint: Figure 2.20 may be helpful.
Explanation / Answer
2.9)
The program is reading the contents of the array A and then adding the numbers individually by storing the value of the array in registers x9 and x10.
The simple c code will be
int f,g,h,i,j
int A[2]
f=A[0]+A[1]+A[2]
The code is summing up all the numbers in the array A and then adding all the numbers and the final result is stored in register X9
Here in the assembly code we are using add instructions to basically add all the elements in the array A. the first add instructions does exactly the same. Then we are moving the value of the sum to the register x10. Next we are doing a store and a load to basically retrieve the value of the sum from the x9 register and then we are returning the final output to the register X0.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.