$25
Programming Lab #2a
Functions and Parameters
Topics: Passing parameters, function return values, nested functions, preserving and restoring registers across function calls, calling C functions from assembly.
Prerequisite Reading: Chapters 1-3
Revised: August 28, 2019
Create an assembly language source code file containing four functions. If the functions were written in C, they would look like the following. (Functions Square and SquareRoot are provided in the main program.)
int32_t Add(int32_t a, int32_t b)
{
return a + b ;
}
int32_t Less1(int32_t a)
{
return a - 1 ;
}
int32_t Square2x(int32_t x)
{
return Square(x + x) ;
}
int32_t Last(int32_t x)
{
return x + SquareRoot(x) ;
}
Test your functions using the main program downloaded from here. If you code works correctly, the display should look like the image on the right. Press the blue pushbutton to cycle through all the test cases to verify that everything is correct. Color is used to indicate the status of a function:
Gray
Yellow
Orange
Green
Red
IMPORTANT – The .thumb_func directive: The ".thumb_func" assembler directive specifies that the next label is the entry point of a function that contains instructions from the Thumb subset of the ARM processor and causes the binary representation of instructions that branch to that label to be generated somewhat differently. Thus in a source code file that contains more than one function, it is imperative that you place a .thumb_func directive immediately before the entry point label of every function.
Function never called. Function given in main program. Function never returns.
Function returning correct value. Function returning incorrect value.