ARM汇编代写代做代考 CS1021 Tutorial 8 Stacks and Subroutines

CS1021 Tutorial 8 Stacks and Subroutines
Q1 If SP = 0x40010000, R4 = 4, R5 =5 and R6 = 6 (1) draw a diagram of the stack after the following instructions are executed and (2) what are the contents of R4, R5, and R6?
{R4} POP {R6}
(ii) PUSH
POP {R4, R5}
(iii) PUSH
POP {R5, R4}
{R4, R5}
{R4, R5}
CS1021 Tutorial 8  2018 jones@scss.tcd.ie
(i) PUSH
PUSH {R5}
(iv) PUSH
POP {R6}
POP {R5} POP {R4}
(v) PUSH
POP {R6, R4}
{R4, R5, R6}
{R4, R5, R6} POP {R5}
Q2 If SP = 0x40010000 and R4 = 0, what do the following instructions do?
PUSH {R4} POP {PC}
Q3 Write suitable entry and exit code for a leaf subroutine XXXX which modifies R4, R5, R6 and R7.
Q4 Write suitable entry and exit code for a non-leaf subroutine YYYY which modifies R4, R5, and R7.
Q5 Write a subroutine STRLEN which returns the length of NUL terminated ASCII string in R0. The address of the string is passed to the subroutine in R0.
Q6 Write a subroutine LEN that computes √𝑥2 + 𝑦2 . Assume x is passed to the subroutine in R0, y in R1 and that the result is returned in R0. Assume also that you can call a subroutine SQRT which the returns the integer square root of R0 in R0.
If a is stored @ 0x40000000, b @ 0x40000004 and c @ 0x40000008 respectively, write code, using subroutine LEN, to compute 𝑐 = √𝑎2 + 𝑏2.
1