mirror of
https://github.com/mytechnotalent/Embedded-Hacking.git
synced 2026-05-31 11:39:35 +02:00
187 lines
6.0 KiB
Markdown
187 lines
6.0 KiB
Markdown
# Week 4 Quiz: Variables, Memory Sections, and GPIO
|
||
|
||
## Instructions
|
||
Choose the best answer for each question. There is only one correct answer per question.
|
||
|
||
---
|
||
|
||
## Questions
|
||
|
||
### Question 1
|
||
Which memory section contains initialized global variables (e.g., `int counter = 42;`)?
|
||
|
||
A) `.bss`
|
||
B) `.text`
|
||
C) `.data`
|
||
D) `.rodata`
|
||
|
||
> 📖 **Reference:** Week 4, Part 2 – "The Three Main Sections"
|
||
|
||
**Correct Answer: C**
|
||
|
||
---
|
||
|
||
### Question 2
|
||
What is the data type `uint8_t`, and what is its valid value range?
|
||
|
||
A) Signed 8-bit integer; -128 to 127
|
||
B) Unsigned 8-bit integer; 0 to 255
|
||
C) Unsigned 16-bit integer; 0 to 65,535
|
||
D) Signed 16-bit integer; -32,768 to 32,767
|
||
|
||
> 📖 **Reference:** Week 4, Part 1 – "Understanding Data Types" (data types table)
|
||
|
||
**Correct Answer: B**
|
||
|
||
---
|
||
|
||
### Question 3
|
||
In the intro-to-variables program, the original code sets `age = 42` then immediately sets `age = 43`. In the compiled binary, what value appeared and why?
|
||
|
||
A) `42`, because the first assignment always takes precedence
|
||
B) Both `42` and `43`, because the compiler keeps all assignments
|
||
C) `43` only, because the compiler optimized out the unused value `42`
|
||
D) `0`, because the variable was placed in the BSS section
|
||
|
||
> 📖 **Reference:** Week 4, Part 8, Step 15 – "Understand the Optimization"
|
||
|
||
**Correct Answer: C**
|
||
|
||
---
|
||
|
||
### Question 4
|
||
When analyzing a raw `.bin` file in Ghidra (without debug symbols), what base address must you set when importing RP2350 firmware?
|
||
|
||
A) `0x00000000`
|
||
B) `0x20000000`
|
||
C) `0x10000000`
|
||
D) `0x00100000`
|
||
|
||
> 📖 **Reference:** Week 4, Part 6, Step 7 – "Configure the Binary Format"
|
||
|
||
**Correct Answer: C**
|
||
|
||
---
|
||
|
||
### Question 5
|
||
Why do uninitialized global variables (e.g., `uint8_t age;`) always print `0` in the uninitialized-variables example?
|
||
|
||
A) The C compiler sets all uninitialized variables to 0 before generating machine code
|
||
B) The startup code (reset handler) zeros out the entire BSS section before `main()` runs
|
||
C) The Pico SDK automatically initializes all variables through `stdio_init_all()`
|
||
D) Uninitialized variables are stored in flash memory which always reads as 0
|
||
|
||
> 📖 **Reference:** Week 4, Part 2 – "What Happens to Uninitialized Variables?"
|
||
|
||
**Correct Answer: B**
|
||
|
||
---
|
||
|
||
### Question 6
|
||
What is the purpose of the `uf2conv.py` script used in Week 4?
|
||
|
||
A) It decompiles a UF2 binary back into C source code
|
||
B) It converts a raw `.bin` file into the UF2 format required to flash the Pico 2
|
||
C) It compresses the firmware binary to fit within flash memory limits
|
||
D) It strips debug symbols from an ELF file to create a raw binary
|
||
|
||
> 📖 **Reference:** Week 4, Part 10, Step 19 – "Convert to UF2 Format"
|
||
|
||
**Correct Answer: B**
|
||
|
||
---
|
||
|
||
### Question 7
|
||
Which Pico SDK function sets a GPIO pin's direction to output?
|
||
|
||
A) `gpio_init(pin)`
|
||
B) `gpio_put(pin, value)`
|
||
C) `gpio_set_dir(pin, GPIO_OUT)`
|
||
D) `gpio_enable(pin, OUTPUT)`
|
||
|
||
> 📖 **Reference:** Week 4, Part 3 – "GPIO Functions in the Pico SDK" (table)
|
||
|
||
**Correct Answer: C**
|
||
|
||
---
|
||
|
||
### Question 8
|
||
What does `gpio_put(LED_PIN, 1)` do to an LED connected to that GPIO pin?
|
||
|
||
A) It reads and returns the current voltage level of the pin
|
||
B) It initializes the GPIO pin and registers it for output use
|
||
C) It drives the pin HIGH, turning the LED on
|
||
D) It drives the pin LOW, turning the LED off
|
||
|
||
> 📖 **Reference:** Week 4, Part 3 – "GPIO Functions in the Pico SDK" and Part 11, Step 22
|
||
|
||
**Correct Answer: C**
|
||
|
||
---
|
||
|
||
### Question 9
|
||
What hexadecimal value does `0x2b` represent, and why did it appear in the compiled binary for the intro-to-variables program?
|
||
|
||
A) `0x2b` = 42; it is the first value assigned to `age`
|
||
B) `0x2b` = 43; it is the optimized constant that replaced the `age` variable
|
||
C) `0x2b` = 44; it is the address of the `age` variable in SRAM
|
||
D) `0x2b` = 27; it is a stack offset calculated by the compiler
|
||
|
||
> 📖 **Reference:** Week 4, Part 8, Step 15 – "Understand the Optimization" (0x2b = 43 decimal)
|
||
|
||
**Correct Answer: B**
|
||
|
||
---
|
||
|
||
### Question 10
|
||
What does the `--family 0xe48bff59` argument specify when running `uf2conv.py`?
|
||
|
||
A) The base address of the XIP flash region
|
||
B) The CRC checksum of the compiled binary
|
||
C) The RP2350 chip family identifier required by the UF2 format
|
||
D) The baud rate used for serial communication
|
||
|
||
> 📖 **Reference:** Week 4, Part 10, Step 19 – "Convert to UF2 Format"
|
||
|
||
**Correct Answer: C**
|
||
|
||
---
|
||
|
||
## Answer Key
|
||
|
||
1. C - Initialized global variables belong to the `.data` section
|
||
2. B - `uint8_t` is an unsigned 8-bit integer with range 0 to 255
|
||
3. C - The compiler optimized out the unused `42` assignment, keeping only `43` (0x2b)
|
||
4. C - RP2350 firmware loads at the XIP base address `0x10000000`
|
||
5. B - The reset handler's BSS clear phase zeros all uninitialized global variables before `main()` runs
|
||
6. B - `uf2conv.py` converts a raw `.bin` file to the UF2 format the Pico 2 uses for flashing
|
||
7. C - `gpio_set_dir(pin, GPIO_OUT)` configures the pin direction as output
|
||
8. C - `gpio_put(pin, 1)` drives the pin HIGH, turning the LED connected to that pin on
|
||
9. B - `0x2b` = 43; the compiler replaced the `age` variable entirely with this constant
|
||
10. C - `0xe48bff59` is the RP2350 family ID embedded in the UF2 file header
|
||
|
||
---
|
||
|
||
## Scoring Guide
|
||
|
||
- **10 correct**: Excellent! You have a strong grasp of Week 4 concepts
|
||
- **8-9 correct**: Very good! Review the topics you missed
|
||
- **6-7 correct**: Good start. Go back and review the key concepts
|
||
- **5 or fewer**: Review the Week 4 material again and try the practice exercises
|
||
|
||
---
|
||
|
||
## Topics Covered
|
||
|
||
This quiz tests your understanding of:
|
||
- Memory sections: `.data`, `.bss`, `.rodata`, and `.text`
|
||
- Data types: `uint8_t` size and range
|
||
- Compiler optimization of unused variable assignments
|
||
- Importing raw `.bin` files into Ghidra with the correct base address
|
||
- BSS zero initialization at startup
|
||
- UF2 format and the `uf2conv.py` conversion script
|
||
- GPIO functions: `gpio_init()`, `gpio_set_dir()`, `gpio_put()`
|
||
- GPIO control: `gpio_put()` behavior (HIGH/LOW)
|
||
- Hexadecimal to decimal conversion in context
|
||
- UF2 family IDs for chip identification
|