Examining Object Code Lab Exercise
Examining Object Code Lab Exercise
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
• 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.
• Select the file with the .map extension and click Open.
MEMORY REQUIREMENTS
• 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?
• 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.
• 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.