Module 0306: Returning a scalar value

Tak Auyeung, Ph.D.

October 8, 2018

Contents

1 About this module
2 Pick a register!

1 About this module

2 Pick a register!

In general, most compilers for most architectures picks a register to store the scalar return value of a subroutine. For TTP, let us choose register A as the register storing the return value.

Let us consider the following C subroutine:

 
int five() 
{ 
  return 5; 
}

Its equivalent TTP assembly code is as follows:

 
1five: 
2  ldi a,5 
3  ld  b,(d)  // careful not to mess up reg A! 
4  inc d      // deallocate return address 
5  jmp b      // use reg B to return