Menu
Coddy logo textTech

Preserving Carry Bits

Part of the RTL Design & Verification section of Coddy's Verilog journey. Lesson 6 of 38.

Signal width determines which bits can be represented. Make arithmetic intent explicit by extending operands before an operation. Adding two unsigned 8-bit values can require nine result bits; assigning only eight bits keeps the low eight and loses carry.

Relevant excerpt; surrounding declarations and connections are supplied in the challenge.

wire [8:0] total;
assign total = {1'b0,a} + {1'b0,b};

Each operand is explicitly nine bits wide, matching the complete sum.

Choose the required result width and extend operands before arithmetic.

challenge icon

Challenge

Medium

Add unsigned 8-bit a and b without losing carry. Return the complete 9-bit sum in total. Explicitly extend both operands to nine bits. Output columns: total. All stimulus values are known binary values.

Complete design.v and preserve its module names and ports. The locked testbench.v supplies input changes and prints the outputs after they settle. It chooses a scenario using a simulator argument such as +CASE=1; no standard input is required. Do not add printing, delays or simulation termination to the design. Expected output is one row of decimal values per observation, separated by one space and ending with a newline.

Try it yourself

module dut (input [7:0] a, input [7:0] b, output [8:0] total);
    // Replace this placeholder with your design.
    assign total = 0;
endmodule
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in RTL Design & Verification

Practice on your own: Online Verilog compiler