Docsity

Best Practices and Verilog Assignments for Digital Design, Exercises of Computer Science

Toggle sidebar
bg1
Please Note: To receive full credit, you should use the following best practices in your homework
assignments:
Use meaningful names for modules, ports, and wires when possible.
Use underscores to break up long binary and hex numbers into groups of 4 digits to make
them more readable. Ex: 12’b1001_0011_1101
Show your work if you wish to receive partial credit.
Make port connections by name unless using gate primitives.
Explicitly declare any nets you use.
All figures & graphs should include a number and caption (handwritten is OK).
When printing waveforms, ensure that the relevant signal transitions are clearly visible.
All code should be typed. Please do not submit handwritten code.
You must always turn in a printout of all Verilog code used with each problem unless
explicitly told not to do so.
You must also submit a copy of all Verilog code to the Drop Box on the course
website by the time the homework is due.
[1] (20pts) – How Do You Compare?
(a) (16pts) Using Structural Verilog, design a combinational 2-bit magnitude comparator with the
following module interface:
module mag_comp(input [1:0] A, B, output A_eq_B, A_lt_B, A_gt_B);
The corresponding outputs should be set to 1’b1 iff A = B, A < B, or A > B, respectively. Treat both
A and B as signed values.
Show the work to derive the logic gates used in your Verilog code (truth tables, K-maps, and
Boolean equations).
(b) (4pts) Neatly draw a schematic of the circuit from part (a).
Docsity.com
pf3

Partial preview of the text

Download Best Practices and Verilog Assignments for Digital Design and more Exercises Computer Science in PDF only on Docsity!

Please Note: To receive full credit, you should use the following best practices in your homework assignments :

 Use meaningful names for modules, ports, and wires when possible.  Use underscores to break up long binary and hex numbers into groups of 4 digits to make them more readable. Ex: 12’b1001_0011_  Show your work if you wish to receive partial credit.  Make port connections by name unless using gate primitives.  Explicitly declare any nets you use.  All figures & graphs should include a number and caption (handwritten is OK).  When printing waveforms, ensure that the relevant signal transitions are clearly visible.  All code should be typed. Please do not submit handwritten code.  You must always turn in a printout of all Verilog code used with each problem unless explicitly told not to do so.You must also submit a copy of all Verilog code to the Drop Box on the course website by the time the homework is due.

[1] (20pts) – How Do You Compare?

(a) (16pts) Using Structural Verilog , design a combinational 2-bit magnitude comparator with the following module interface:

module mag_comp(input [1:0] A, B, output A_eq_B, A_lt_B, A_gt_B);

The corresponding outputs should be set to 1’b1 iff A = B, A < B, or A > B, respectively. Treat both A and B as signed values.

Show the work to derive the logic gates used in your Verilog code ( truth tables, K-maps, and Boolean equations ).

(b) (4pts) Neatly draw a schematic of the circuit from part (a).

[2] (20pts) – You Can Lead a Zero to Water, but …

Use RTL Verilog (continuous assignments) and bitwise logical operators (e.g., &, |, ^, ~) to model a combinational 8-bit leading zero detector. Your module should have the following interface:

module leading_zero_detector( output [2:0] count, input [7:0] A);

Your leading zero detector should output a count of the number of consecutive bits in A that are zero, starting from the leftmost bit. For example, if A = 8’b0101_0000 then count = 3’b001, and if A = 8’b0001_0011 then count = 3’b011. When A = 8’b0000_0000, your module should output count = 3’b000. Write a testbench that demonstrates correct operation of your leading zero detector for all possible inputs. Your testbench should include a monitor statement that neatly prints the current simulation time and all inputs and outputs when any input or output changes. Turn in the Verilog code for your leading zero detector and its test bench. You do NOT have to turn in your simulation output.

[3] (20pts) – Operator, Operator…

Give the result of the following operations in Verilog binary number format, with the proper bitwidth:

a) ~^7’b110_ b) 4’d7 * 3’h c) 4’d7 + 3’h d) 8’hC7 ^ 8’h e) {{2{1’b1, {3{2’b01}}}}, 2’b1} f) 6 ’b10_0000 | 6’b10_ g) 6’b10_0000 || 6’b10_ h) !8’d i) 5’b11010 << 2 j) – (12’hAAA)

[4] (20pts) – ALU Design with RTL

(a) (14pts) Use RTL (continuous assignments) to create an ALU that operates on 4-bit 2's-complement numbers. The op input specifies the ALU operation as follows; 2'b00 ; Y = A + B + cin 2'b01 : Y = A - B 2'b10 : Y = A XOR B 2'b11 : Y = -A Outputs also include carry-out ( cout ), overflow detection ( overflow ), and zero detection ( zero ). If the outputs are not pertinent to the operation being performed, they can be considered don’t-cares.

The module interface shall be module ALU (output [3:0] Y, output cout, overflow, zero, input [3:0] A, B, input cin, input [1:0] op);