Files
Embedded-Hacking/WEEKS/WEEK09/QUIZ09.md
T
2026-04-15 17:23:21 -04:00

8.8 KiB
Raw Blame History

Week 9 Quiz: Operators, DHT11 Sensor, IEEE-754, and Reset_Handler Navigation

Instructions

Choose the best answer for each question. There is only one correct answer per question.


Questions

Question 1

In the expression int a = x++; where x = 5, what values do a and x hold after this line executes?

A) a = 6, x = 6 — both get the incremented value
B) a = 5, x = 6 — post-increment returns the old value, then increments
C) a = 5, x = 5 — post-increment doesn't actually change x until the next statement
D) a = 6, x = 5 — pre-increment changes a but not x

📖 Reference: Week 9, Part 3 "Post-increment: a = x++ → a=5, then x becomes 6" and the variable flow table showing increment_operator = 5

Correct Answer: B


Question 2

What does the bitwise left shift 6 << 1 produce, and why?

A) 3 — left shift divides by 2
B) 7 — left shift adds 1 to the value
C) 12 — left shift by 1 doubles the value; 0b00000110 becomes 0b00001100
D) 60 — left shift multiplies by 10

📖 Reference: Week 9, Part 6 "Each left shift DOUBLES the value! 6 << 1 = 12 (same as 6 × 2)" and binary diagram showing 0b000001100b00001100

Correct Answer: C


Question 3

The DHT11 sensor communicates with the Pico 2 using how many data wires, and how many bits of data does it send per reading?

A) 2 wires (SDA + SCL), 16 bits
B) 1 wire (DATA), 40 bits (8 hum int + 8 hum dec + 8 temp int + 8 temp dec + 8 checksum)
C) 1 wire (DATA), 32 bits (16 humidity + 16 temperature)
D) 3 wires (CLK + DATA + EN), 24 bits

📖 Reference: Week 9, Part 8 "DHT11 uses a custom one-wire protocol" and "40 bits sent (8 humidity int, 8 humidity decimal, 8 temp int, 8 temp decimal, 8 checksum)"

Correct Answer: B


Question 4

In the ARM Cortex-M vector table at 0x10000000, what is stored at offset 0x04 and why is the lowest bit set to 1?

A) The initial stack pointer value; the lowest bit indicates big-endian mode
B) The Reset_Handler address; the lowest bit is the Thumb bit, indicating the processor should execute in Thumb mode
C) The NMI handler address; the lowest bit enables the interrupt
D) The flash base address; the lowest bit is a parity check

📖 Reference: Week 9, Part 14, Steps 22-23 "offset 4 contains the Reset_Handler address" and "ARM uses the THUMB bit! The lowest bit indicates Thumb mode (always set for Cortex-M)"

Correct Answer: B


Question 5

When reading the bytes 5d 01 00 10 from the vector table at offset 0x04, what is the actual Reset_Handler code address?

A) 0x5d010010 — read the bytes left to right
B) 0x1000015c — reverse for little-endian to get 0x1000015d, then subtract 1 for the Thumb bit
C) 0x1000015d — reverse for little-endian; the Thumb bit is part of the address
D) 0x0100005d — swap pairs of bytes

📖 Reference: Week 9, Part 14, Step 23 "In memory: 5d 01 00 10 → Reversed: 10 00 01 5d → 0x1000015d" then "Real address: 0x1000015d 1 = 0x1000015c"

Correct Answer: B


Question 6

The dht11_read function takes two arguments passed via registers. What are they and how does the calling code set them up?

A) r0 = humidity value, r1 = temperature value — passed by value as integers
B) r0 = address of hum on stack (sp + 0x8), r1 = address of temp on stack (sp + 0xc) — passed by reference as float pointers
C) r0 = GPIO pin number, r1 = sensor type — passed by value
D) r0 = I²C address, r1 = register offset — passed by value

📖 Reference: Week 9, Part 12, Step 14 and Part 15, Step 32 "add r0, sp, #0x8 (Address of hum variable), add r1, sp, #0xc (Address of temp variable)" and signature bool dht11_read(float *humidity, float *temperature)

Correct Answer: B


Question 7

How is the IEEE-754 float 0.1f encoded in memory on the Pico 2 (little-endian)?

A) 0a 00 00 00 — 0.1 stored as a fixed-point integer
B) cd cc cc 3d — IEEE-754 hex 0x3dcccccd stored in little-endian byte order
C) 3d cc cc cd — IEEE-754 hex stored in big-endian byte order
D) 00 00 00 01 — the value 0.1 is rounded to the nearest integer

📖 Reference: Week 9, Part 16, Step 35 and the IEEE-754 Float Quick Reference table "0.1 → 0x3dcccccd → cd cc cc 3d (LE)" and the scaling constant at offset 0x42C shown as cc cc cc 3d

Correct Answer: B


Question 8

The compiler computed x * y (5 × 10 = 50) at compile time and stored the result as an immediate #0x32. What does this tell you about the compiler's behavior?

A) The compiler stores all multiplication results in the .data section
B) The compiler performs constant folding — since both operands are known at compile time, it precomputes the result and embeds it as an immediate instruction operand
C) The Thumb instruction set has a special mul instruction that always produces immediates
D) The value 0x32 is loaded from the literal pool, not encoded in the instruction

📖 Reference: Week 9, Part 12, Step 11 "The compiler likely optimized many of these calculations at compile time. Look for immediate values: #0x32 (50) for arithmetic_operator"

Correct Answer: B


Question 9

In the Reset_Handler, three function calls appear in sequence. How do you identify which one is main()?

A) The first function call is always main() in ARM Cortex-M
B) The last function call is main() because it never returns
C) The middle function call is main() — the order is: hardware init, main(), exit()
D) You cannot tell — you must use symbol tables to find main()

📖 Reference: Week 9, Part 14, Step 26 "Reset_Handler: 1. Call some_init() → Initialize hardware, 2. Call main() → THIS IS WHAT WE WANT!, 3. Call exit() → Never returns. The MIDDLE function is main!"

Correct Answer: C


Question 10

The vfma.f32 s15, s13, s11 instruction at offset 0x414 computes s15 = s15 + (s13 × s11) where s11 holds the constant 0.1f. In the context of DHT11 temperature processing, what does this fused multiply-add accomplish?

A) It converts the temperature from Fahrenheit to Celsius
B) It combines the integer and decimal parts of the temperature — result = integer + (decimal × 0.1), turning raw parts like 23 and 8 into 23.8°C
C) It applies a calibration offset to correct sensor drift
D) It scales the temperature from millidegrees to degrees

📖 Reference: Week 9, Part 17, Step 35 "Formula: result = integer + (decimal × 0.1), Example: 23.8 = 23 + (8 × 0.1)" and "The vfma.f32 instruction does: s15 = s13 + (s11 × something) Where s11 = 0.1f"

Correct Answer: B


Answer Key

  1. B - Post-increment x++ returns the value of x before incrementing; a gets 5, then x becomes 6
  2. C - Left shift by 1 doubles the value; 6 in binary 0b0110 shifted left becomes 0b1100 = 12
  3. B - DHT11 uses one data wire and sends 40 bits (5 bytes: hum int, hum dec, temp int, temp dec, checksum)
  4. B - Offset 0x04 holds the Reset_Handler address; the lowest bit is the Thumb bit for Cortex-M Thumb mode
  5. B - Reverse little-endian bytes to get 0x1000015d, subtract 1 for the Thumb bit → 0x1000015c
  6. B - Stack addresses of hum and temp are passed in r0 and r1 as float pointers (pass by reference)
  7. B - IEEE-754 encodes 0.1f as 0x3dcccccd; little-endian storage reverses to cd cc cc 3d
  8. B - The compiler performs constant folding, computing 5 × 10 = 50 at compile time and embedding it as immediate #0x32
  9. C - In the Reset_Handler's three-call sequence (init, main, exit), main is the middle call
  10. B - The vfma.f32 combines integer and decimal sensor parts using the 0.1f multiplier: 23 + (8 × 0.1) = 23.8

Scoring Guide

  • 10 correct: Excellent! You have a strong grasp of Week 9 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 9 material again and try the practice exercises

Topics Covered

This quiz tests your understanding of:

  • Post-increment vs pre-increment operator behavior and return values
  • Bitwise left shift as multiplication by powers of 2
  • DHT11 single-wire protocol and 40-bit data frame structure
  • ARM Cortex-M vector table layout and Reset_Handler at offset 0x04
  • Thumb bit in ARM addresses and little-endian byte order reversal
  • Function argument passing via registers (r0-r3) and pass-by-reference with stack addresses
  • IEEE-754 single-precision float encoding and little-endian memory layout
  • Compiler constant folding optimization for compile-time-known expressions
  • Reset_Handler three-call pattern: init → main → exit
  • ARM floating-point vfma.f32 fused multiply-add for sensor data processing