Question 2
While most return values are scalar and there is only one perinvocation of a function, the number of parameters varies wildlydepending on what subroutine is called. As a result, it is not agood idea to use registers to pass parameters. Most compilers usethe stack to pass parameters.
Because a parameter should be specified before calling asubroutine, it is pushed on stack before the return address is.After a subroutine returns, its parameters are still using stackspace. It is up to the caller to deallocate space used by asubroutine that has returned.
Consider the following function call:
extern void xyz(uint8_t x);xyz(5);
The corresponding code in TTP assembly is as follows:
ldi a,5dec dst (d),a // push 5ldi a,retL1dec dst (d),a // push return addressjmpi xyz // continues execution at xyzretL1:inc d // deallocates stack space used by param
Note that the return address is “consumed” (popped and used) bythe called subroutine, so the caller does not deallocatethe return address.
In the previous code, at the entry point of subroutine xyz,where is the argument 5 relative to the location pointed to byregister D? Indicate the offset in bytes of where argument 5 iscompared to where D points to.
question 3
Arguments are pushed on stack by the caller, how does asubroutine being called access them?
The relative position of parameters compared to the locationpointed to by the SP stays constant. In other words, the SP is howwe get back to the parameters.
Let us consider the example from the previous question. Thecaller code is as follows:
ldi a,5dec dst (d),a // push 5ldi a,retL1dec dst (d),a // push return addressjmpi xyz // continues execution at xyzretL1:inc d // deallocates stack space used by param
In the subroutine xyz, right at the entry point of thesubroutine, what does the SP (reg D) point to?
Group of answer choices
a) the beginning of the whole stack
b) the return address
c) the stack pointer
d) the end of the whole stack
none of the other answer is correct
e) 5
Expert Answer
Answer to Question 2 While most return values are scalar and there is only one per invocation of a function, the number of parame…