Skip to question
ASIC.FYI
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
ASIC.FYI/Interview questions/Allocate on a power-of-two boundary

Q262·Free·SystemVerilog

Allocate on a power-of-two boundary

Difficulty
Medium
Topic
Memory Systems
Language
SV
Interview prompt

Question

Return a block whose starting address is aligned to a requested power-of-two boundary while preserving every unused fragment.

Starting point

Question code

function bit alloc_aligned(
  int unsigned size,
  int unsigned align,
  output int unsigned addr
);
Reviewed example

Trace one case

Input
free=[[0x1003,0x10FF]]; size=0x20; alignment=0x40
Expected output
base=0x1040; remaining=[[0x1003,0x103F],[0x1060,0x10FF]]

Rounding 0x1003 upward selects the first 64-byte boundary, and both unused fragments remain available.

What to cover

Requirements

  1. Reject zero or non-power-of-two alignment.
  2. Round each candidate range start upward without signed arithmetic.
  3. Verify that the complete request fits after alignment.
  4. Preserve leading and trailing free fragments.
Exact question handoffPractice Q262

Solve it in the question bank, keep your progress, and reveal the reviewed solution when your access allows.

Open in question bank →
Solution accessA Free account unlocks the complete reviewed solution.
Continue learning

SystemVerilog

  • Memory Systems
  • Allocator
  • Alignment
  • Bit mask
Interview preparation guide →
Continue practicing

Related questions

Q212 · Memory SystemsBuild a first-fit range allocator→Q276 · Memory SystemsRandomize free-range allocation→Q290 · Memory SystemsImplement best-fit allocation→
ASIC.FYI · Learn silicon end to end.info@asic.fyi