PATH: //opt/alt/python311/share/doc/alt-python311-pyparsing-doc/examples/verilog
FILE_BARU
CREATE
FOLDER_BARU
MKDIR
UPLOAD_FILE
GO
[ .. KEMBALI ]
📄 Ctr3sr.v
↓
X
📄 INIT
↓
X
📄 RANDOM_GATE
↓
X
📄 RANDOM_INTERCONNECT
↓
X
📄 SEED
↓
X
📄 TestCtr3sr.v
↓
X
📄 addacc.v
↓
X
📄 addacc1_dro.v
↓
X
📄 addacc1_t1ff.v
↓
X
📄 addacc_conf.v
↓
X
📄 addacc_dro.v
↓
X
📄 addacc_t1ff.v
↓
X
📄 allParseOutput.zip
↓
X
📄 and.v
↓
X
📄 and_gate.v
↓
X
📄 conf.v
↓
X
📄 core_test.v
↓
X
📄 count2bit.v
↓
X
📄 count_all_prims_test.v
↓
X
📄 count_loads_test.v
↓
X
📄 dds.v
↓
X
📄 diff_udp.v
↓
X
📄 display_all_nets_test.v
↓
X
📄 div16.v
↓
X
📄 dro.v
↓
X
📄 dro1_cell.v
↓
X
📄 dro_cell.v
↓
X
📄 dump_and_fill_mem_test.v
↓
X
📄 exprinfo_test.v
↓
X
📄 fetch_values_test.v
↓
X
📄 ff.v
↓
X
📄 ff_test.v
↓
X
📄 fifo.v
↓
X
📄 find_driver.tcl.gz
↓
X
📄 framer.v
↓
X
📄 func_72bit_test.v
↓
X
📄 gen.v
↓
X
📄 gencrc.v
↓
X
📄 gzip.exe
↓
X
📄 hadd.v
↓
X
📁 hasCompilerDirectives/
X
📄 hello_test.v
↓
X
📄 in_port.v
↓
X
📄 inv.v
↓
X
📄 inv_cell.v
↓
X
📄 invoke_commands_test.v
↓
X
📄 invoke_options_test.v
↓
X
📄 jtl2.v
↓
X
📄 jutzi
↓
X
📄 list_cells_test.v
↓
X
📄 list_nets_test.v
↓
X
📄 list_parameters_test.v
↓
X
📄 list_path_delays_test.v
↓
X
📄 list_pathout_ports_test.v
↓
X
📄 list_prim_delays_test.v
↓
X
📄 load_in.v
↓
X
📄 load_out.v
↓
X
📄 mem_arb.v
↓
X
📄 mipd_delays_test.v
↓
X
📄 mult16.v
↓
X
📄 multi21_udp.v
↓
X
📄 my_monitor1_test.v
↓
X
📄 my_monitor2_test.v
↓
X
📄 my_monitor_test.v
↓
X
📄 my_strobe_test.v
↓
X
📄 myram64x16.v
↓
X
📄 nco.v
↓
X
📄 ndro.v
↓
X
📁 new/
X
📁 new2/
X
📁 new3/
X
📄 nodeinfo_test.v
↓
X
📄 onehot.v
↓
X
📄 or.v
↓
X
📄 out_port.v
↓
X
📁 parseOutput/
X
📄 pic.v
↓
X
📄 pipe1.v
↓
X
📄 pipe2.v
↓
X
📄 pl.v
↓
X
📄 pli_handbook_examples_pc.zip
↓
X
📄 port_info_test.v
↓
X
📄 pow_test.v
↓
X
📄 primitives.v
↓
X
📄 propagatep_test.v
↓
X
📄 psr1.v
↓
X
📄 psr1_conf.v
↓
X
📄 psr1_dro.v
↓
X
📄 psr1_split.v
↓
X
📄 psr2.v
↓
X
📄 psr2_and.v
↓
X
📄 psr2_split.v
↓
X
📄 read_4state_value_test.v
↓
X
📄 read_attribute_test.v
↓
X
📄 read_delays_test.v
↓
X
📄 read_stimulus_short_test.v
↓
X
📄 read_stimulus_test.v
↓
X
📄 read_strengthval_test.v
↓
X
📄 read_test_vector_test.v
↓
X
📄 read_timeval_test.v
↓
X
📄 read_vector_test.v
↓
X
📄 read_vecval_test.v
↓
X
📄 realpow_test.v
↓
X
📄 rf.v
↓
X
📄 sci_alu_comb_calltf_shell.v
↓
X
📄 sci_alu_comb_calltf_test.v
↓
X
📄 sci_alu_comb_misctf_shell.v
↓
X
📄 sci_alu_comb_misctf_test.v
↓
X
📄 sci_alu_combinational_shell.v
↓
X
📄 sci_alu_combinational_test.v
↓
X
📄 sci_alu_latched_shell.v
↓
X
📄 sci_alu_latched_test.v
↓
X
📄 sci_alu_sequential_shell.v
↓
X
📄 sci_alu_sequential_test.v
↓
X
📄 sci_alu_synchronized_shell.v
↓
X
📄 sci_alu_synchronized_test.v
↓
X
📄 sci_alu_with_delays_shell.v
↓
X
📄 sci_alu_with_delays_test.v
↓
X
📄 set_mipd_delays_test.v
↓
X
📄 show_all_nets_test.v
↓
X
📄 show_all_signals1_test.v
↓
X
📄 show_all_signals2_test.v
↓
X
📄 show_all_signals3_test.v
↓
X
📄 show_all_signals_1_test.v
↓
X
📄 show_all_signals_2_test.v
↓
X
📄 show_all_signals_3_test.v
↓
X
📄 show_value_test.v
↓
X
📄 sig_gen.v
↓
X
📄 simple_core.v
↓
X
📄 splitter.v
↓
X
📄 sqrt32.v
↓
X
📄 sqrt8m.v
↓
X
📄 sr_nv_ctf.v
↓
X
📄 srcnt.v
↓
X
📄 string.v
↓
X
📄 t1ff.v
↓
X
📄 testcase.v
↓
X
📄 testcase2.v
↓
X
📄 testcase3.v
↓
X
📄 testcase4.v
↓
X
📄 testcase5.v
↓
X
📄 tff.v
↓
X
📄 timescale_info_test.v
↓
X
📄 usb.v
↓
X
📄 use_workarea_test.v
↓
X
📄 utmi_if.v
↓
X
📄 vpi_utilities_test.v
↓
X
📄 wb.v
↓
X
📄 wpulse.v
↓
X
📄 xor.v
↓
X
📄 zzzexample.v
↓
X
SAVING...
BERHASIL DIUBAH!
EDITING: div16.v
// // Integer Multicycle Divide circuit (divide a 16-bit number by a 16-bit number in 16 cycles). // // a / b = q with remainder r // // Where a is 16-bits, // Where b is 16 bits // // Module is actually parameterized if you want other widths. // // *** Test the ranges of values for which you'll use this. For example, you // can't divide FFFF by FF without underflow (overflow?). Mess with // the testbench. You may need to widen some thing. *** // // The answer is 16-bits and the remainder is also 16-bits. // After the start pulse, the module requires 16 cycles to complete. // The q/r outputs stay the same until next start pulse. // Start pulse should be a single cycle. // Division by zero results in a quotient equal to FFFF and remainder equal to 'a'. // // // Written by tom coonan. // // Notes: // - This ain't fancy. I wanted something straight-forward quickly. Go study // more elaborate algorithms if you want to optimize area or speed. If you // have an isolated divide and can spare N cycles for N bits; this may meet your needs. // - You might want to think more about the sizes of things. I wanted a basic estimate // of gates plus I specifically needed to divide 16-bits (not even full range) // by 8-bits. // - Handle divide by zero at higher level.. // - I needed a remainder so I could easily to truncate and rounding stuff, // but remove this to save gates if you don't need a remainder. // - This is about 800 asic gates (0.25um, Standard Cell, 27Mhz). 27Mhz // is my system clock and NOT the maximum it can go.. // - I tried to keep everything parameterized by N, but I only worked through // the N=16 case because that's what I needed... // module div16 (clk, resetb, start, a, b, q, r, done); parameter N = 16; // a/b = q remainder r, where all operands are N wide. input clk; input resetb; // Asynchronous, active low reset. input start; // Pulse this to start the division. input [N-1:0] a; // This is the number we are dividing (the dividend) input [N-1:0] b; // This is the 'divisor' output [N-1:0] q; // This is the 'quotient' output [N-1:0] r; // Here is the remainder. output done; // Will be asserted when q and r are available. // Registered q reg [N-1:0] q; reg done; // Power is the current 2^n bit we are considering. Power is a shifting // '1' that starts at the highest power of 2 and goes all the way down // to ...00001 Shift this until it is zero at which point we stop. // reg [N-1:0] power; // This is the accumulator. We are start with the accumulator set to 'a' (the dividend). // For each (divisor*2^N) term, we see if we can subtract (divisor*2^N) from the accumulator. // We subtract these terms as long as adding in the term doesn't cause the accumulator // to exceed a. When we are done, whatever is left in the accumulator is the remainder. // reg [N-1:0] accum; // This is the divisor*2^N term. Essentually, we are taking the divisor ('b'), initially // shifting it all the way to the left, and shifting it 1 bit at a time to the right. // reg [(2*N-1):0] bpower; // Remainder will be whatever is left in the accumulator. assign r = accum; // Do this addition here for resource sharing. // ** Note that 'accum' is N bits wide, but bpower is 2*N-1 bits wide ** // wire [2*N-1:0] accum_minus_bpower = accum - bpower; always @(posedge clk or negedge resetb) begin if (~resetb) begin q <= 0; accum <= 0; power <= 0; bpower <= 0; done <= 0; end else begin if (start) begin // Reinitialize the divide circuit. q <= 0; accum <= a; // Accumulator initially gets the dividend. power[N-1] <= 1'b1; // We start with highest power of 2 (which is a '1' in MSB) bpower <= b << N-1; // Start with highest bpower, which is (divisor * 2^(N-1)) done <= 0; end else begin // Go until power is zero. // if (power != 0) begin // // Can we add this divisor*2^(power) to the accumulator without going negative? // Just test the MSB of the subtraction. If it is '1', then it must be negative. // if ( ~accum_minus_bpower[2*N-1]) begin // Yes! Set this power of 2 in the quotieny and // then actually comitt to the subtraction from our accumulator. // q <= q | power; accum <= accum_minus_bpower; end // Regardless, always go to next lower power of 2. // power <= power >> 1; bpower <= bpower >> 1; end else begin // We're done. Set done flag. done <= 1; end end end end endmodule // synopsys translate_off module test_div16; reg clk; reg resetb; reg start; reg [15:0] a; reg [15:0] b; wire [15:0] q; wire [15:0] r; wire done; integer num_errors; div16 div16 ( .clk(clk), .resetb(resetb), .start(start), .a(a), .b(b), .q(q), .r(r), .done(done) ); initial begin num_errors = 0; start = 0; // Wait till reset is completely over. #200; // Do some divisions where divisor is constrained to 8-bits and dividend is 16-bits $display ("16-bit Dividend, 8-bit divisor"); repeat (25) begin do_divide ($random, $random & 255); end // Do some divisions where divisor is constrained to 12-bits and dividend is 16-bits $display ("\n16-bit Dividend, 12-bit divisor"); repeat (25) begin do_divide ($random, $random & 4095); end // Do some divisions where both divisor and dividend is 16-bits $display ("\n16-bit Dividend, 16-bit divisor"); repeat (25) begin do_divide ($random, $random); end // Special cases $display ("\nSpecial Cases:"); do_divide (16'hFFFF, 16'hFFFF); // largest possible quotient do_divide (312, 1); // divide by 1 do_divide ( 0, 42); // divide 0 by something else do_divide (312, 0); // divide by zero // That's all. Summarize the test. if (num_errors === 0) begin $display ("\n\nSUCCESS. There were %0d Errors.", num_errors); end else begin $display ("\n\nFAILURE!! There were %0d Errors.", num_errors); end $finish; end task do_divide; input [15:0] arga; input [15:0] argb; begin a = arga; b = argb; @(posedge clk); #1 start = 1; @(posedge clk); #1 start = 0; while (~done) @(posedge clk); #1; $display ("Circuit: %0d / %0d = %0d, rem = %0d \t\t......... Reality: %0d, rem = %0d", arga, argb, q, r, a/b, a%b); if (b !== 0) begin if (q !== a/b) begin $display (" Error! Unexpected Quotient\n\n"); num_errors = num_errors + 1; end if (r !== a % b) begin $display (" Error! Unexpected Remainder\n\n"); num_errors = num_errors + 1; end end end endtask initial begin clk = 0; forever begin #10 clk = 1; #10 clk = 0; end end initial begin resetb = 0; #133 resetb = 1; end initial begin $dumpfile ("test_div16.vcd"); $dumpvars (0,test_div16); end endmodule
SIMPAN PERUBAHAN