(Solved) : Return Values Subroutines Scalars Integers Addresses Etc Types Fixed Small Size Scalar Ret Q42748715 . . .

Most return values of subroutines are “scalars”, such asintegers, addresses and etc. These types have a fixed and smallsize. As such, scalar return values are usually passed to thecaller of a subroutine via a register. Most compilers have aconvention of which register to use to specify the return value ofa subroutine.

For TTP in CISP310, we use the convention of using reg A as thereturn value. As an example, observe the following C code:

uint8_t five(){ return 5;}

The TTP assembly code would look like the following:

five: ldi a,5 ld b,(d) inc d jmp b

It is important to understand that a single return statement inC/C++ has two operations. First, it specifies the return value.Second, it actually returns to the caller.

Given that this is how a return value is specified, what is thevalue of reg B after the following code executes, assuming “five”is defined as above? Try to answer this question byanalyzing the code not running it through the simulator.

main: ldi d,0 ldi a,retL1 dec d st (d),a jmpi fiveretL1: dec d st (d),a ldi a,retL2 dec d st (d),a jmpi fiveretL2: ld b,(d) add b,a halt

Flag this Question

Question 21 pts

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.

Expert Answer

Answer to Most return values of subroutines are “scalars”, such as integers, addresses and etc. These types have a fixed and small…

Leave a Comment


We are the best freelance writing portal. Looking for online writing, editing or proofreading jobs? We have plenty of writing assignments to handle.

Quick Links

Browse Solutions

Place Order

About Us