Examining Object Code Lab Exercise

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

P a g e |1

LAB EXERCISE:
EXAMINING OBJECT CODE
OVERVIEW

In this lab you will examine the object code created by the compiler for an RTOS-based program for the KL25Z Freedom
board and expansion shield which uses many of the system’s components. You will not run the code, so you do not need an
expansion shield to complete this lab.

PROCEDURE

Obtain the project source code and project files from GitHub at agdean/ESO-21/Lab1/. You will use Moodle to submit your
answers to the questions in two ways:

• Submit the plaintext file Lab1_Responses.csv with your numerical and text data added:
o If we can’t load the file into a spreadsheet for analysis, then you may lose points.
o Replace only the “x” cells as needed.
o Do not change the formatting.
o When entering hexadecimal numbers:
▪ Use 0x prefix and uppercase letters (A-F)
▪ Enter the correct number of digits based on the data size. For example, use 0x12 for a byte,
0x1234 for a half-word, and 0x12345678 for a word.
▪ Enter a value for each hex digit, padding with zeros as needed, e.g. word 0x00000088.
• Submit images (scans, diagrams, screenshots) in a single PDF file.

0. Enter your unity id (e.g. agdean) in the row labeled 0.a in Lab1_Responses.csv.

GETTING STARTED

• Open the MDK project Module 1 Lab directory.


• Select Project->Options for Target.
• Choose the Target tab. In the Code Generation section, verify the ARM Compiler selected is “Use default compiler
version 5” and that “Use Microlib” is checked as shown below. Do not use the ARM version 6 compiler (ARM
CLANG) as it does not support the version 5 C language extensions.

NCSU ECE 461/561 – Embedded System Optimization


A.G. Dean [email protected] 2/11/2021
P a g e |2

• Choose the Listing tab to configure the linker to generate a map file. Verify the Linker Listing section has all boxes
checked.
• On the C/C++ tab, make sure the Language / Code Generation options are set as shown here. Then click OK.

• Build the program.


• Open the map file: Select File->Open, then open the Listings directory. To make the map file visible, select “All Files
(*.*)”as shown here.

• Select the file with the .map extension and click Open.

MEMORY REQUIREMENTS

• The map file has the following sections:


o Section Cross References
o Removing Unused input sections from the image.
o Image Symbol Table
▪ Local Symbols
▪ Global Symbols
o Memory Map of the image

NCSU ECE 461/561 – Embedded System Optimization


A.G. Dean [email protected] 2/11/2021
P a g e |3

o Image component sizes


▪ Objects
▪ Library Members
▪ Libraries
o Summary information (not labeled)
1. Scroll down to the last two sections in the map file to determine the following values.
a. What is the Total ROM Size in bytes?
b. What is the Total RW Size in bytes? This is the total RAM required.
c. What is the size of RW Data in RAM in bytes? Note this is uncompressed RW Data (in Grand Totals).
d. What is the size of RW Data in ROM in bytes? Note this is compressed RW Data.
e. How much ROM space in bytes is used for code (and data included in the function, listed as “.inc data”)?
2. Examine the Local Symbols section.
a. Which is the largest symbol of type “Thumb Code”, and how large is it in bytes?
b. Which is the largest symbol of type “Data”, and how large is it in bytes?
3. Examine the Global Symbols section.
a. Which is the largest symbol of type “Thumb Code”, and how large is it in bytes?
b. Which is the largest symbol of type “Data”, and how large is it in bytes?
4. Examine the first part of the Image component sizes section to determine the memory requirements of the program
objects.
a. Which object member has the largest component of type “Code (inc. Data)” (first column), and how large is
that component?
b. Which object member has the largest component of type “RO Data”, and how large is that component?
c. Which object member has the largest component of type “RW Data”, and how large is that component?
d. Which object member has the largest component of type “ZI Data”, and how large is that component?
5. Examine the third part of the Image component sizes section to determine the memory requirements of the library
member objects.
a. Which library member has the largest component of type “Code” (first column), and how large is that
component?
b. Which library member has the largest component of type “RO Data”, and how large is that component?
c. Which library member has the largest component of type “RW Data”, and how large is that component?
d. Which library member has the largest component of type “ZI Data”, and how large is that component?
6. Open the project’s Objects directory, and double-click on the <project_name>.htm file to open it with a web browser.
What is the tool’s estimated maximum stack depth for each listed function or thread? Hint: use your browser’s search
function.
a. main
b. Thread_Slideshow
c. osRtxIdleThread
d. disk_initialize
7. List the names and maximum stack depth estimates of functions ending in Handler (these are exception and
interrupt handlers) with an estimate of maximum stack depth (Max Depth) which is greater than zero. Hint: use your
browser’s search function. Leave any extra spreadsheet rows unchanged.

NCSU ECE 461/561 – Embedded System Optimization


A.G. Dean [email protected] 2/11/2021
P a g e |4

OBJECT CODE VIEW

• Configure MDK-ARM’s target options to use the Debug Simulator rather the actual KL25Z MCU, as shown below.

• Start a debug session (using Control-F5) to examine the dissassembly. Do not start the program running.
• Open the file LCD_JPEG.c in the source code window. Place the cursor on the line status =
jpeg_decode_init(…), which should be at or near line 90. This will bring up the corresponding object code in the
disassembly window. If that window is not visible, open it with View->Disassembly Window.
8. Look in the disassembly window to see the object code which implements the argument preparation and function call.
Copy the assembly instruction(s) (opcode and operands) used to perform each action listed below. Do not copy the
instruction address, machine code or comments. Copy the first instruction into column C and any remaining
instructions for that action into columns E, G, I, etc.
a. Prepare argument 1:
b. Prepare argument 2:
c. Prepare argument 3:
d. Prepare argument 4:
e. Call the function:
• Select the definition of function pjpeg_load_from_file in LCD_JPEG.c and examine the corresponding code in
the disassembly window.
9. Assume that the stack pointer (sp) has a value of 0x20002000 immediately before it executes the first instruction
(PUSH …) of pjpeg_load_from_file.
a. What is the value of sp immediately after executing that instruction?
b. What is the value of sp immediately after executing the instructions implementing if (pScan_type)?
10. What is the address used to store the LSB of each value below? Express it as an offset from the current stack pointer,
e.g. sp+0x00000004.
a. the variable pScan_type?
b. the pointer comps?

NCSU ECE 461/561 – Embedded System Optimization


A.G. Dean [email protected] 2/11/2021
P a g e |5

FUNCTION STRUCTURE – CONTROL FLOW BEHAVIOR

• In the source code window, click on the function LCD_Controller_Init in ST7789.c. This will bring up the object
code in the disassembly window. If that window is not visible, open it with View->Disassembly Window.
11. Identify each basic block in the function, listing them in order of increasing address. You may need to add or remove
rows from the spreadsheet. Describe each basic block with:
• the starting address of its first instruction,
• the starting address of its last instruction,
• whether the last instruction can change the control flow (no, branch, return). Classify subroutine calls with no.
• the addresses of possible successor basic blocks in increasing order (if not a subroutine return).
a. Basic Block 1
b. Basic Block 2
c. (etc.)
12. Draw the control flow graph, labeling each basic block with its number and starting address (from part b.) and marking
the control-flow edges as T, F, or A (for true, false and always). You can draw by hand or use a program (e.g. gvedit in
the graphviz package (https://graphviz.gitlab.io/download/)). Submit this diagram in your PDF.

PROGRAM STRUCTURE – CALLING BEHAVIOR

• Use the IDE’s debugger and disassembler to answer these questions. List the function names in order of appearance in
code, including duplicates. Enter one function name per cell.
13. Which functions can follow_path (in pff.c) call directly according to the C source code?
14. Which functions can follow_path call directly according to the disassembly (object) code?
15. Which functions can transformBlock (in picojpeg.c) call directly according to the C source code?
16. Which functions can transformBlock call directly according to the disassembly (object) code?

• Open the <project_name>.map file in the Listings directory and look for Section Cross References. This section shows
which objects refer to symbols in other files.
17. Which objects refer to __aeabi_dmul (double-precision floating-point multiply)? Enter one name (e.g.
file.o(i.function) per cell, adding cells to the right.
18. Examine the second part of the Image Symbol Table, which is marked Global Symbols (not Local Symbols). How many
global symbols of type “Data” are listed?

• Use a web browser to open the <project_name>.htm file in the Objects directory. This shows a text representation of
the function call graph.
19. Find the entry for the LCD_Start_Rectangle function.
a. Which functions can it call directly?
b. Which functions can call it directly?
20. Draw a call graph to show which functions huffDecode can call either directly or indirectly (through another
function). You can draw by hand or use a program (e.g. gvedit in the graphviz package). Submit this diagram in your
PDF.

NCSU ECE 461/561 – Embedded System Optimization


A.G. Dean [email protected] 2/11/2021

You might also like