Codiode

Power of Two Alignment

MediumVerilog / SystemVerilogBuild

DMA engines and memory controllers often need an address rounded down to a burst boundary. For a power-of-two boundary that is just clearing the low bits.

This module calculates the 8-byte aligned base address for any given 32-bit input address. It computes the largest address that is less than or equal to the input address and is a perfect multiple of eight.

This is a purely combinational circuit. Changes on the input immediately reflect on the output with no clock or reset dependencies.

Signal Direction Width Description
addr_in input 32 Unaligned 32-bit memory address
addr_out output 32 32-bit memory address rounded down to the nearest multiple of 8

Constraints

  • The output addr_out must be purely combinational.
  • The module must round down to the nearest multiple of 8.
  • You must not use arithmetic division or modulo operators; synthesize the logic using only bitwise operations or concatenation.

Topics

ArithmeticCombinational LogicBitwise Operations

Solve this problem

Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against the problem's testbench. You get the waveform back, not a stored answer.

This problem is part of Codiode Pro. The statement above is free to read.

The circuit builder and code editor need a desktop screen. On a phone, read the problem here and open it on a laptop to solve.

Part of Synthesis Intuition

Problem 11 of 25 in the Synthesis Intuition track.

Related problems

Browse all problems · Verilog practice problems · Learning tracks

Solve this on a laptopSend yourself the link and continue there.