Read a hex register dump by hand: whole values, bit fields, the count of 1 bits and the range of a register.
Hardware context: A hex register dump of a motor controller and a table of fractional gain settings. Read whole values, bit fields and ranges from a hex register dump by hand.
A motor controller stops at the wrong speed. The only evidence is a register dump that a debug probe printed in hex. Before anyone changes the firmware, somebody has to read the dump correctly.
This is an Implement problem with no logic to write. Work out each answer by hand and write it into the answer module as a constant. The first three constants are worked examples and are already correct.
The check compares every constant with the right value and names the first one that is wrong.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
question | 8 | input of each check |
Full specification
name width (bits) dump
STATUS 8 10
LIMIT 8 64
SPEED 16 0250
CTRL 16 B3C5
TEMP 12 1F4
COUNT 10 (not read)
| Constant | What to write |
|---|---|
| STATUS_VALUE | The value of STATUS as a decimal number (hex 10 is 1 x 16 + 0). |
| CTRL_GAIN | The field GAIN, bits 11 to 8 of CTRL (the hex digit 3 is 0011). |
| TEMP_MAX | The largest value the 12-bit register TEMP can hold (2^12 - 1). |
| LIMIT_VALUE | The value of LIMIT as a decimal number. |
| SPEED_VALUE | The value of SPEED as a decimal number. |
| TEMP_VALUE | The value of TEMP as a decimal number. |
| CTRL_MODE | The field MODE, bits 6 to 4 of CTRL, as a decimal number. |
| CTRL_RATE | The field RATE, bits 13 to 10 of CTRL, as a decimal number. |
| CTRL_ONES | How many bits of CTRL are 1. |
| COUNT_MAX | The largest value the 10-bit register COUNT can hold. |
| COUNT_DIGITS | How many hex digits a full dump of the 10-bit COUNT shows. |
Bit 0 is the rightmost bit of a register. A field such as bits 6 to 4 is read as its own small number, with bit 4 as its lowest bit.
Write each answer as one plain decimal number, such as 42 or 16'd42, in place of the 0. The check refuses hex, octal or binary literals, operators and function calls: the conversion is the exercise. Keep the module name and the constant names.
Examples
Example 1
Worked Example: A Whole Value- Input
the value of STATUS as a decimal number (hex 10 is 1 x 16 + 0)
- Output
status_value = 16
STATUS dumps as 10 in hex. The left digit has the weight 16 and the right digit is 0, so the value is 16. This constant is already filled in.
Example 2
Worked Example: A Field- Input
the field GAIN, bits 11 to 8 of CTRL (the hex digit 3 is 0011)
- Output
ctrl_gain = 3
Bits 11 to 8 of CTRL are its second hex digit from the left, the digit 3. A field that starts at a multiple of four is one whole hex digit. This constant is already filled in.
Example 3
Worked Example: A Range- Input
the largest value the 12-bit register TEMP can hold (2^12 - 1)
- Output
temp_max = 4095
TEMP has 12 bits, so it holds 4,096 values. They start at 0, so the largest is 4,095. This constant is already filled in.
Constraints and Contract
- Keep the module name answer and the names of the constants.
- Every answer is a whole number from 0 to 65,535.
Hints
Hint 1
Write each hex digit as four bits first. The dump of CTRL becomes sixteen bits, and every question about CTRL is then a matter of counting.
Hint 2
Number the bits from 0 on the right. For a field, copy only its bits and read them as a small binary number of their own.
Hint 3
For a whole value, multiply each hex digit by its weight: 1, 16, 256 and 4,096 from the right. For a width of N bits, the largest value is one less than 2 to the power N.
What the grader checks: The check reads eleven constants and compares each with a value computed from the dump text. Before that, a source rule refuses any answer that is not one decimal literal.
11 checks on Icarus · browser samples / server checks. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 2 steps and the final capstone