Updated DS refs

This commit is contained in:
Kevin Thomas
2026-04-15 17:23:21 -04:00
parent 6d01ea5f24
commit 38b5b1bcb5
220 changed files with 33267 additions and 0 deletions
+186
View File
@@ -0,0 +1,186 @@
# Week 5 Quiz: Integers, Floats, Doubles, and IEEE 754
## Instructions
Choose the best answer for each question. There is only one correct answer per question.
---
## Questions
### Question 1
What is the valid value range of `int8_t` (a signed 8-bit integer)?
A) 0 to 255
B) 0 to 127
C) -128 to 127
D) -256 to 255
> 📖 **Reference:** Week 5, Part 1 "Signed vs Unsigned Integers" (table: `int8_t` range is -128 to 127)
**Correct Answer: C**
---
### Question 2
How is the value `-42` stored in a single byte using two's complement?
A) `0x2A` — the sign is tracked separately by the CPU
B) `0xD6` — the CPU flips all bits of `42` (`0x2A`) and adds `1`
C) `0xAA` — negative values always have the pattern `1010...` in binary
D) `0x42` — the value is stored identically to positive `42`
> 📖 **Reference:** Week 5, Part 1 "The Integer Variables" (two's complement: flip bits of `0x2A` and add 1 = `0xD6`)
**Correct Answer: B**
---
### Question 3
In IEEE 754 single-precision (32-bit float), how are the 32 bits divided among sign, exponent, and mantissa?
A) 1 sign bit, 11 exponent bits, 20 mantissa bits
B) 1 sign bit, 8 exponent bits, 23 mantissa bits
C) 2 sign bits, 8 exponent bits, 22 mantissa bits
D) 1 sign bit, 10 exponent bits, 21 mantissa bits
> 📖 **Reference:** Week 5, Part 2 "What is a Float?" (IEEE 754 Single-Precision diagram: 1 sign, 8 exponent, 23 mantissa)
**Correct Answer: B**
---
### Question 4
Why does `printf` receive a 64-bit `double` even when the source code declares a `float` variable?
A) The Pico 2's ARM Cortex-M33 does not have a floating-point unit
B) Ghidra automatically converts floats to doubles during analysis
C) The C standard requires `float` arguments to variadic functions like `printf` to be promoted to `double`
D) The `%f` format specifier forces the compiler to use 64-bit precision
> 📖 **Reference:** Week 5, Part 2.7, Step 14 "Understand the Float Encoding" (C standard requires float arguments to variadic functions are promoted to double)
**Correct Answer: C**
---
### Question 5
What is the exponent bias for IEEE 754 double-precision, and why is it 1023?
A) 127 — because the exponent field is 8 bits and $(2^8 / 2) - 1 = 127$
B) 1023 — because the exponent field is 11 bits and $(2^{11} / 2) - 1 = 1023$
C) 1024 — because $2^{10} = 1024$ and the exponent uses 10 bits
D) 2047 — because $2^{11} - 1 = 2047$ is the maximum 11-bit value
> 📖 **Reference:** Week 5, Part 2.7, Step 15 "Why 1023?" callout (exponent is 11 bits, $2^{11} = 2048$, midpoint = $(2048 / 2) - 1 = 1023$)
**Correct Answer: B**
---
### Question 6
On the ARM Cortex-M33, how is a 64-bit double passed to a function like `printf`?
A) In a single 64-bit register `r0`
B) On the stack as an 8-byte value
C) In two 32-bit registers: `r2` (low 32 bits) and `r3` (high 32 bits)
D) In the floating-point register `d0`
> 📖 **Reference:** Week 5, Part 2.7, Step 14 "A 64-bit double is passed in two 32-bit registers" (table: r2 = low, r3 = high)
**Correct Answer: C**
---
### Question 7
What does the `mcrr p0, #4, r4, r5, c0` instruction do on the RP2350?
A) It reads the current GPIO pin state into registers r4 and r5
B) It writes to the GPIO coprocessor to set a pin's output value (r4 = pin, r5 = value)
C) It configures the GPIO function select register for SIO mode
D) It copies data between two ARM general-purpose registers
> 📖 **Reference:** Week 5, Part 1 "The Blink Loop with Inline Assembly" (coprocessor register `c0` controls output value, r5 = 1 drives HIGH, r5 = 0 drives LOW)
**Correct Answer: B**
---
### Question 8
When configuring a GPIO pin with inline assembly, what value is written to the FUNCSEL field to select SIO (Single-cycle I/O) mode?
A) `0` — default reset value
B) `3` — UART function
C) `5` — SIO function
D) `31` — null function (disabled)
> 📖 **Reference:** Week 5, Part 1 "GPIO Initialization with Inline Assembly" (Step 2: clears FUNCSEL bits and sets to `5` for SIO)
**Correct Answer: C**
---
### Question 9
What is the key difference between a `float` (32-bit) and a `double` (64-bit) in terms of decimal precision?
A) A float has ~15 digits precision; a double has ~7 digits precision
B) A float has ~7 digits precision; a double has ~15 digits precision
C) Both have the same precision; doubles just have a larger range
D) A float has exact precision; a double introduces rounding errors
> 📖 **Reference:** Week 5, Part 3 "Float vs Double - Key Differences" (table: float ~7 decimal digits, double ~15 decimal digits)
**Correct Answer: B**
---
### Question 10
When patching the double `42.5` to `99.0` in Ghidra, only the high word (`r3`) needed to change. When patching `42.52525` to `99.99`, **both** words needed to change. Why?
A) The value `99.99` is larger than `99.0`, so it needs more bits to store
B) The value `99.0` has a clean fractional part (`.0`) so the low word is all zeros, but `99.99` has a repeating binary fraction that requires non-zero bits in the low 32 bits
C) Ghidra encodes doubles differently depending on the number of decimal places
D) The compiler uses a different instruction format for values with more decimal digits
> 📖 **Reference:** Week 5, Part 3.95 "Key takeaway" (clean values like 42.5 only need one patch; messy fractions like 42.52525 need two)
**Correct Answer: B**
---
## Answer Key
1. C - `int8_t` is a signed 8-bit integer with range -128 to 127
2. B - Two's complement: flip all bits of `0x2A` (42) and add 1 → `0xD6`
3. B - IEEE 754 single-precision: 1 sign bit, 8 exponent bits, 23 mantissa bits
4. C - The C standard requires `float` arguments to variadic functions (`printf`) to be promoted to `double`
5. B - The 11-bit exponent gives 2048 values; the midpoint $(2^{11} / 2) - 1 = 1023$ is the bias
6. C - 64-bit doubles are split across `r2` (low 32 bits) and `r3` (high 32 bits) on ARM Cortex-M33
7. B - `mcrr p0, #4, r4, r5, c0` writes to the GPIO coprocessor's output register (c0), setting pin r4 to value r5
8. C - FUNCSEL = 5 selects SIO mode for software-controlled GPIO
9. B - Float has ~7 decimal digits precision; double has ~15 decimal digits precision
10. B - Clean fractions (like `.0`) produce a zero low word; repeating binary fractions (like `.99`) need all 52 mantissa bits, making both words non-zero
---
## Scoring Guide
- **10 correct**: Excellent! You have a strong grasp of Week 5 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 5 material again and try the practice exercises
---
## Topics Covered
This quiz tests your understanding of:
- Signed vs unsigned integers: `uint8_t` and `int8_t` ranges
- Two's complement encoding of negative numbers
- IEEE 754 single-precision (32-bit) field layout
- Float-to-double promotion in C variadic functions
- IEEE 754 double-precision exponent bias (1023) and its derivation
- ARM Cortex-M33 register pairs (`r2:r3`) for 64-bit doubles
- GPIO coprocessor instruction `mcrr` for pin output control
- FUNCSEL field and SIO mode selection
- Float vs double precision differences
- Patching strategy: clean fractions (one word) vs repeating fractions (two words)