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

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

ID: 3348705 • Letter: V

Question

VII. After execution of the following instructions what value will be in register r2? Trace the program and write the value of the registers at each line to receive full credit.

LDR r12, =0xA4000000

LDR r0, =0x2D
STR r0, [r12, #-4]!
LDR r0, =0x5E

STR r0, [r12, #-4]!

LDR r0, =0xD5

STR r0, [r12, #-4]!

LDMIA r12!, {r0-r2}

SUB r2, #0x68

VIII. Write a simple ARM assembly program to divide a 32 bit positive number stored in r0 by a constant 23. The quotient should be stored in r1 and the remainder should be stored in r2. Note that this is an integer division.

Explanation / Answer

Answer :- The code has been commeted with register values-

LDR r12, =0xA4000000 ;r12 = 0xA4000000

LDR r0, =0x2D ;r0 = 0x2D

STR r0, [r12, #-4]! ;r12 = 0xAFFFFFFC, and value at address 0xAFFFFFFC = 0x2D

LDR r0, =0x5E ;r0 = 0x5E

STR r0, [r12, #-4]! ;r12 = 0xAFFFFFF8, and value at address 0xAFFFFFF8 = 0x5E

LDR r0, =0xD5 ;r0 = 0xD5

STR r0, [r12, #-4]! ;r12 = 0xAFFFFFF4, and value at address 0xAFFFFFF4 = 0xD5

LDMIA r12!, {r0-r2} ;r0 = 0xD5, r1 = 0x5E, r2 = 0x2D and r12 = 0xA4000000

SUB r2, #0x68 ;r2 = 0x2D - 0x68 = 0xFFFFFFC5

Answer :- The assembly code is witten below-

LDR r3, =0x17 ;r3 = 23

UDIV r1, r0, r3 ;r1 = (r0 / r3)

MLS r2, r1, r3, r0 ;r2 = r0 - (r1 x r3)