CodiodeCodiode
Home
Problem Solving
Skill Tracks
My Assignments
Contests
Leaderboard
Community
Settings
Codiode/Problems/Combinational Logic

Power of Two Alignment

MediumVerilog / SystemVerilogBuild

Memory controllers and direct memory access (DMA) engines frequently require memory addresses to be aligned to specific data burst boundaries. When a processor issues an unaligned memory request, the hardware must calculate the nearest aligned base address to initiate the fetch. Aligning an address to a power of two boundary requires truncating the least significant bits of the address bus.

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 a real testbench — you get the waveform back, not a stored answer.

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

Sign in to solveSee what Pro unlocks

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.

Related problems

  • Single Continuous AssignmentEasy
  • Basic Vector ConcatenationEasy
  • Ternary Operator MuxEasy
  • Underscores for ReadabilityEasy
  • Left Hand Side ConcatenationEasy
  • Inout Port MechanicsEasy
  • Explicit Binary LiteralsEasy
  • Vector Port EndiannessEasy

Browse all problems · Learning tracks