DescriptionQ719
Q719FWASIC interview problem
Parse a bounded Roman board revision
TechniquesFWParserBoundsError handlingFixed memory
DifficultyEasy
TopicFirmware Algorithms
LanguageSystemVerilog
Requirements4 checkpoints
01
Problem
Parse an explicitly sized electrically erasable programmable read-only memory (EEPROM) field as a canonical Roman numeral from I through MMMCMXCIX without allocation or out-of-range reads.
Type declarationSystemVerilog
typedef enum { ROMAN_OK, ROMAN_EINVAL, ROMAN_ERANGE } roman_rc_t;
roman_rc_t roman_to_u16(const uint8_t *buf,
size_t len,
uint16_t *value);
// len is 1..15; a successful value is 1..3999.Example input and output
Use this case to check your interpretationInput
bytes="MCMXCIV", length=7Output
success; revision=1994Explanation
The subtractive pairs CM, XC, and IV are legal, and re-encoding 1994 reproduces the exact input, proving canonical spelling.
02
Requirements (4)
- Accept only uppercase I, V, X, L, C, D, and M and the six standard subtractive pairs.
- Return invalid-input errors before range errors, except that a fully parsed value above 3999 returns the range error.
- Reject noncanonical spellings by re-encoding the parsed value and comparing every input byte.
- Do not call strlen or modify the caller's output until the complete parse succeeds.
