Skip to the selected question
ASIC.FYI

ASIC Interview Question Bank

1,000+ hardware interview questions.Curated and reviewed by industry engineers.1,000+ hardware questions1,000+ questionsEngineer-reviewed
DescriptionQ262
Page ↗
Q262ArchFollow-up to Q212ASIC interview problem

Allocate on a power-of-two boundary

TechniquesAllocatorAlignmentBit mask
DifficultyMedium
TopicMemory Systems
LanguageSystemVerilog
Requirements4 checkpoints
01

Problem

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

Function headerSystemVerilog
function bit alloc_aligned(
  int unsigned size,
  int unsigned align,
  output int unsigned addr
);

Example input and output

Use this case to check your interpretation
Input
free=[[0x1003,0x10FF]]; size=0x20; alignment=0x40
Output
base=0x1040; remaining=[[0x1003,0x103F],[0x1060,0x10FF]]
Explanation

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

02

Requirements (4)

  • Reject zero or non-power-of-two alignment.
  • Round each candidate range start upward without signed arithmetic.
  • Verify that the complete request fits after alignment.
  • Preserve leading and trailing free fragments.