Home / Learn Verilog / Signed Arithmetic Rules

Signed Arithmetic Rules

Keep every operand signed.

The gistKeep every operand signed.

The idea, explained simply

Signed result-3 * 2 signed-6mixedwrong large number
Signed result

The basic idea

All operands must be signed for signed arithmetic; unsized literals are signed 32-bit.

Why this comes up

Wrong signedness changes comparisons and shifts.

The mechanics

Use $signed and declare signed regs.

Where it is used

  • Everyday RTL design
  • FPGA and ASIC projects
  • Testbenches and debugging

Try it

Signed multiplyVerilog: edit and run

Prefixing a zero bit makes 0xFF a positive 9-bit value (255).

Quick check

1. Signed math requires...