Microsoft Word - Digital Logic Design v_4_6a

(lily) #1

7.9. Code Modularization


As the code gets more complex and size increases, it is important to modularize the code by developing
the code as multiple modules. This approach improves code reusability, improved debugging/reliability
and simpler design.


Here is example of how multiple modules are used:


// Modularized code
// First write the module you plan to use latter
module mod_base(inA,inB,outA);
input inA,inB;
wire inA, inB
output outA;
reg outA;
assign outA=(inA)?inB:1’b0;
endmodule

// now write the main circuit that uses our selector
module main(a,b);
input a,;
wire a;
output b;
reg b;
// now used mod_base
mod_base U1(1’b0,1’b1, temp); // this is where the mod-base is instantiated and used.
endmodule
Free download pdf