Description
The goals for the assignment this week:
- To explore the IAR IDE and the different debug views.
- Get a better understanding of machine instructions, addresses, variables and pointers.
Setup:
- Create a new project in IAR following the steps from the slide deck
- Create a counter local variable and increment the counter several times.
- Run the program in the simulator environment and answer the following questions:
Observe and answer:
- Inject 0x1FFFFFFF for the “counter” value in the variable window, then step thru the program only once to increment “counter”.
- What is the value of the “counter” from the “Locals” window?
- What is the value of the “counter” in the “Register” window?
- Which flags are set in the APSR register? Explain why?
- If your write all Fs (0XFFFFFFFF) in the Register value for “counter” then step thru the program once to increment “counter”
- What happens to the value of “counter” in the “Locals” window?
- What flags, if any, are set in the APSR?
- Change the “counter” variable type in your code to “unsigned”. Inject the values “0x1FFFFFFF” then step thru the program to increment the “counter” once:
- What is the value of “counter” in the “Locals” window after incrementing for each value?
- What flags, if any, are set in the APSR? Explain why?
- Change the “counter” variable type in your code to “unsigned”. Inject the values “0xFFFFFFFF” then step thru the program to increment the “counter” once:
- What is the value of “counter” in the “Locals” window after incrementing for each value?
- What flags, if any, are set in the APSR? Explain why?
- Move the “counter’ variable outside of main (at the top of the file):
- What is the scope of the variable “counter”?
- Is it still visible in the “Locals” view?
- In which window view can we track “counter” now?
- What is the address of the “counter” variable in memory?
- Change the source code to the following, then run the program still in the simulator:
int counter = 0x0; int main() { int *p_int = (int *)0x20000000; ++(*p_int); ++(*p_int); ++(*p_int); counter ++; return 0; } |
- What is the value of “counter” at the end of the program (halting at the return 0 statement)
- Explain why the counter value has changed?
- Change the setting of IAR to run the same program on the evaluation board:
Setup: 1. Connect evaluation board to your computer through ST Link cable. 2. Set the IAR to using STLink: 3. Project -> Options -> Debugger -> Device: ST-Link 4. Download setting is flash loader 5. Make sure ST-Link Interface is set to SWD 6. Run the same code described in the simulator.
|
- What is the address where “counter” is stored?
- Is the “counter” variable stored in RAM or ROM?
- What is the value of “counter” at the end of the program (halting at the return 0 statement).