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

what register(s) holds the return value in the following functions (3) STMIA sp,

ID: 2291645 • Letter: W

Question

what register(s) holds the return value in the following functions

(3) STMIA sp, (r1-r5 (4) STMIB sp, (r1-r5) (5) STMDA sp!, (ri-r5) (6) STMDB sp!, (r1-r5) (7) STMIA sp!, fr1-r5) (8) STMIB sp!, fr1-r5 Memory Addressabcda bd 0x20008008 0x20008004 0x20008000 0x2000800C 0x20008808 8x20008004 0x20008000 0x20007FFC 0x20007FF8 0x20007FF4 0x20007FF0 0x20087FE8 0x20007FE4 4. How many bytes does the stack need to pass the arguments when each of the following function is called? (1) int32_t fun1(uint8_t a, uint16_t b, uint8t c, int32 t d) (2) int32_t fun2 (uint8_t a, uint16_t b, uint8 t c, int32_t d, (3) int32_t fun3(uint8_t a, int32 t b, int64_t c, (4) int32_t fun4(uint8_t a, int64_t b, int64_t c, uint8_t e, int32_t f, uint8_t g) uint8_t d, int32_t e) uint8_t d, int32_t e) 5. Which register(s) holds the return value in the following functions? (1)int16_t fun1() (2)int8 t fun2() (3) int32_t fun3() (4) int64_t fun4() (5) int64 t fun5() 6. Why does a recursive assembly function have to preserve the link 7. Give two different assembly instructions to make a subroutine return.

Explanation / Answer

Answer :- 4)1) For function fun1(), we have four arguments here as, a, b, c and d.
So for variable a = uint8_t = 1 byte
b = uint16_t = 2 byte
c = uint8_t = 1 byte and for d = uint32_t = 4 byte.

Thus for fun1(), stack need to pass 8 byte as argument of the functiion.

2) For fun2(), number of byte to be passed = 1 + 2 +1 +4 + 1 + 4 + 1 = 14 byte.

3) For fun3(), number of byte to be passed = 1 + 4 + 8 + 1 + 4 = 18 byte

4) For fun4(), number of byte to be passed = 1 + 8 + 8 + 1 + 4 = 22 byte.

Answer :- 6) Link Register(LR, R14 of register set) holds the return address i.e. it holds the address where program must return after completion of subroutine. In case of recursion, a function calls itself, hence LR value must be preserved so that when condition for recursion is over, the controller can come back to the main program.

Note that, an unconditioned recursion causes infinite code run.

Answer :- 7) BX instruction and MOV instruction can be used.

BX LR will cause return from the subroutine, or
MOV PC, LR loading Program Counter with Link Register value will cause return from the subroutine.

Note :- Answer for question number five will be given soon. As per my knowledge, register R0 keeps the return value. I am just veryfying this and will update as soon as possible. Thank You.