Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

III. After execution of the following instructions what value will be in registe

ID: 3348720 • Letter: I

Question

III. After execution of the following instructions what value will be in register r0?

LDR                 r12, =0xA4000000

LDR                 r0, =0x75

LDR                 r1, =0xD2

LDR                 r2, =0x9C

LDR                 r5, =0xC

STMDB           r12!, {r0-r2, r5}

LDR                 r0, [r12, #8]

SUB                 r0, #0x77

IV. 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 B are in registers r6 and r7, respectively. Translate the following C code fragment to ARM assembly instructions.

f = –g + h + B[1];

f = A[B[g]+1];

f = –g + h + B[1];

f = A[B[g]+1];

Explanation / Answer

Answer iii) :- The register values after each instruction has been written below as comment-

LDR r12, =0xA4000000 ;r12 = 0xA4000000

LDR r0, =0x75 ;r0 = 0x75

LDR r1, =0xD2 ;r1 = 0xD2

LDR r2, =0x9C ;r2 = 0x9C

LDR r5, =0xC ;r5 = 0xC

STMDB r12!, {r0-r2, r5} ;at memory 0xA3FFFFC, 0x75 is stored
--------------------------------------- ;at memory 0xA3FFFF8, 0xD2 is stored
---------------------------------------;at memory 0xA3FFFF4, 0x9C is stored
--------------------------------------;at memory 0x3AFFFF0, 0xC is stored

LDR r0, [r12, #8] ;So from memory (0xA3FFFF0 + 0x8) i.e. 0xD2 is kept in r0

SUB r0, #0x77 ;r0 = (0xD2 - 0x77) = 0x5B

So final value in register r0 is 0x5B.