Skip to the selected question
ASIC.FYI

ASIC Question Bank

1,000+ hardware interview questions
DescriptionQ534
Q534FWASIC interview problem

Measure the final UART command token

TechniquesFWBufferBackward scanBoundsUART
DifficultyEasy
TopicFirmware Algorithms
LanguageSystemVerilog
Requirements4 checkpoints
01

Problem

Measure the last token in an explicitly sized UART command buffer after ignoring trailing ASCII space bytes.

Type declarationSystemVerilog
typedef enum { TOKEN_OK, TOKEN_EINVAL } token_rc_t;
token_rc_t last_token_len(const uint8_t *buf,
                          size_t len,
                          size_t *token_len);
// len <= 128; only 0x20 separates tokens.

Example input and output

Use this case to check your interpretation
Input
buffer bytes="run test   ", explicit_length=11
Output
last_token_length=4 ("test")
Explanation

Trailing ASCII spaces are skipped, then the scan stops at the separator before test without relying on a terminator.

02

Requirements (4)

  • Treat only byte 0x20 as a separator; embedded zero and nonprinting bytes remain token data.
  • Return zero for an empty or all-space input.
  • Scan with unsigned indexes without decrementing below zero, calling strlen, allocating, or mutating the buffer.
  • Reject a null output, length above 128, or null nonempty input without changing the caller's old length.