Question 261 The following problems deal with translating fr
Question #2.6.1
The following problems deal with translating from C to ARM. Assume that the variables f, g, h, i, and j are assigned to registers r0 r1, r2, r3, and r4, respectively. Assume that the base address of the arrays A and Beta are in registers r6 and r7, respectively. [10] For the C statements above, what is the corresponding ARM assembly code? [5] For the C statements above, how many ARM assembly instructions are needed to perform the C statement?Solution
Answer to Question #2.6.1
For C code -a
MOV R5,#1 ; Move Constrant 1 into R5
MOV R8,[R7,R5] ; Move to R8 , the content of R7[R5] I,e B[1]
ADD R5,R2,R8 ;R5=R2+R8 I,e h+B[1]
SUB R0,R5,R1 ; R0=R5-R1 , I,e f=h+B[1]-g
For C code –b
MOV R5,#1 ; Move Constrant 1 into R5
MOV R9,[R7,R1] ; Move TO R9 ,THE Valueof B[g]
ADD R9,R9,R5 ; R9=R9+R5 ,I,e R9= B[g]+1
MOV R0,[R6,R9] ;R0=R6[R9] ,I,e R0=A[B[g]+1]
