(最新整理)常見面試筆試題-verilog程序庫_第1頁
(最新整理)常見面試筆試題-verilog程序庫_第2頁
(最新整理)常見面試筆試題-verilog程序庫_第3頁
(最新整理)常見面試筆試題-verilog程序庫_第4頁
已閱讀5頁,還剩10頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

1、(完整)常見面試筆試題-verilog程序庫(完整)常見面試筆試題-verilog程序庫 編輯整理:尊敬的讀者朋友們:這里是精品文檔編輯中心,本文檔內(nèi)容是由我和我的同事精心編輯整理后發(fā)布的,發(fā)布之前我們對文中內(nèi)容進行仔細校對,但是難免會有疏漏的地方,但是任然希望((完整)常見面試筆試題-verilog程序庫)的內(nèi)容能夠給您的工作和學習帶來便利。同時也真誠的希望收到您的建議和反饋,這將是我們進步的源泉,前進的動力。本文可編輯可修改,如果覺得對您有幫助請收藏以便隨時查閱,最后祝您生活愉快 業(yè)績進步,以下為(完整)常見面試筆試題-verilog程序庫的全部內(nèi)容。加減法module addsub (

2、input 7:0 dataa, input 7:0 datab, input add_sub, / if this is 1, add; else subtract input clk, output reg 8:0 result ); always (posedge clk) begin if (add_sub) result = dataa + datab; /or ”assign cout,sum=dataa+datab;” else result = dataa - datab; end endmodule 四位的 全加法器.module add4(cout,sum,a,b,cin)

3、input3:0a,b; input cin;output 3:0 sum; output cout;assign cout,sum=a+b+cin;endmodule補碼不僅可以執(zhí)行正值和負值轉換,其實補碼存在的意義,就是避免計算機去做減法的操作.1101 3 補+ 1000 8 01015 假設 -3 + 8,只要將 -3 轉為補碼形式,亦即 0011 = 1101,然后和 8,亦即 1000 相加就會得到 5,亦即 0101.至于溢出的最高位可以無視掉。乘法器module mult(outcome,a,b);parameter size=8;inputsize:1 a,b;output

4、reg2size:1 outcome;integer i;always (a or b) begin outcome=0; for(i=0,i=size;i=i+1) if(bi) outcome=outcome+(a(i-1); endendmodule另一種乘法器。在初始化之際,取乘數(shù)和被乘數(shù)的正負關系,然后取被乘數(shù)和乘數(shù)的正值。輸出結果根據(jù)正負關系取得。else if( start_sig ) case( i ) 0: begin isneg = multiplicand7 multiplier7; mcand = multiplicand7 ? ( multiplicand + 1b1

5、 ) : multiplicand; mer = multiplier7 ? ( multiplier + 1b1 ) : multiplier; temp = 16d0; i = i + 1b1; end 1: / multipling if( mer = 0 ) i = i + 1b1; else begin temp = temp + mcand; mer = mer 1b1; end 2: begin isdone = 1b1; i = i + 1b1; end 3: begin isdone = 1b0; i = 2d0; end endcase assign done_sig =

6、isdone; assign product = isneg ? ( temp + 1b1 ) : temp; endmodule booth乘法器 module booth_multiplier_module( input clk, input rstn, input start_sig, input 7:0a, input 7:0b, output done_sig, output 15:0product, output 7:0sq_a, output 7:0sq_s, output 16:0sq_p); reg 3:0i; reg 7:0a; / result of a reg 7:0s

7、; / reverse result of a reg 16:0p; / p空間,16+1位 reg 3:0x;/指示n次循環(huán) reg isdone;always ( posedge clk or negedge rstn ) if( !rstn ) begin i = 4d0; a = 8d0; s = 8d0; p = 17d0; x = 4d0; isdone = 1b0;end else if( start_sig ) case( i )0: begin a = a; s = ( a + 1b1 ); p = 8d0 , b , 1b0 ; i = i + 1b1; end1: if(

8、 x = 8 ) begin x = 4d0; i = i + 4d2; endelse if( p1:0 = 2b01 ) begin p = p16:9 + a , p8:0 ; i = i + 1b1; endelse if( p1:0 = 2b10 ) begin p = p16:9 + s , p8:0 ; i = i + 1b1; endelse i = i + 1b1;/00和11,無操作2:begin p = p16 , p16:1 ; x = x + 1b1; i = i - 1b1; end /右移,最高位補0 or 1。3:begin isdone = 1b1; i =

9、i + 1b1; end4:begin isdone = 1b0; i = 4d0; endendcase assign done_sig = isdone; assign product = p16:1;endmodule 除法器module divider_module( input clk, input rstn, input start_sig, input 7:0dividend, input 7:0divisor, output done_sig, output 7:0quotient, output 7:0reminder, ); reg 3:0i; reg 7:0dend; r

10、eg 7:0dsor;reg 7:0q;reg 7:0r; reg isneg; reg isdone; always ( posedge clk or negedge rstn ) if( !rstn ) begin i = 4d0; dend = 8d0; dsor = 8d0; q = 8d0; isneg = 1b0; isdone = 1b0; end else if( start_sig ) case( i ) 0: begin dend = dividend7 ? dividend + 1b1 : dividend; dsor = divisor7 ? divisor : ( d

11、ivisor + 1b1 ); isneg = dividend7 divisor7; i = i + 1b1; end 1: if( divisor dend ) begin q = isneg ? ( q + 1b1 ) : q; i = i + 1b1; endelse begin dend = dend + dsor; q = q + 1b1; end2: begin isdone = 1b1; i = i + 1b1; end3: begin isdone = 1b0; i = 4d0; end endcase assign done_sig = isdone; assign quo

12、tient = q;assign reminder = dend;endmodule 除法器2module div(a,b,clk,result,yu) input3:0a,b; output reg3:0 result,yu; input clk; reg1:0 state;reg3:0 m,n; parameter s0=2b00,s1=2b01,s2=2b10; always(posedge clk) begin case(state) s0: begin if(ab) begin n=a-b;m=4b0001; state=s1; end else begin m=4b0000;n=a

13、; state=b) begin m=m+1;n=n-b;state=s1;end else begin state=s2;end end s2: begin result=m;yu=n;state=s0;end defule:state=s0; endcase endendmodule13、一個可預置初值的7進制循環(huán)計數(shù)器verilogmodule count(clk,reset,load,date,out);input load,clk,reset;input3:0 date;output reg3:0 out;parameter width=4d7;always(clk or reset

14、)beginif(reset) out=4d0;else if(load)out=date;else if(out=width-1) out=4d0;else out=out+1;endendmodulejohnson計數(shù)器約翰遜(johnson)計數(shù)器又稱扭環(huán)計數(shù)器,是一種用n位觸發(fā)器來表示2n個狀態(tài)的計數(shù)器。它與環(huán)形計數(shù)器不同,后者用n位觸發(fā)器僅可表示n個狀態(tài)。n位二進制計數(shù)器(n為觸發(fā)器的個數(shù))有2n個狀態(tài)。若以四位二進制計數(shù)器為例,它可表示16個狀態(tài)?!?000-1000-1100-111011110111001100010000-1000”module johnson(input c

15、lk,input clr,output regn1:0 q);always(posedge clk or negedge clr)if(!clr)q=n1b0else if(!q0)q=1b1,qn1:1;elseq=1b0,qn-1:1;endmodule任意分頻,占空比不為50always(clk)beginif(count=x1) count=0;elsecount=count+1;endassign clkout=county/y一般用count的最高位偶數(shù)分頻(8分頻,占空比50)(計數(shù)至n1,翻轉)module count5(reset,clk,out)input clk,rese

16、t;output out;reg1:0 count;always(clk)if(reset) begin count=0; out=0; endelse if(count=3)begin count=0;out=!out: endelse count=count+1;endmodule奇數(shù)分頻電路(占空比50)。module count5(reset,clk,out)input clk,reset;output out;reg2:0 m,n;reg count1;reg count2;always(posedge clk)beginif(reset) beginm=0;count1=0;end

17、elsebegin if(m=4) m=0; else m=m+1; /“4”為分頻數(shù)num-1,num=5if(m2) count1=1; else count1=0;endendalways(negedge clk)beginif(reset) beginn=0;count2=0;endelsebegin if(n=4) n=0; else n=n+1;if(n2) count2=1; else count2=0;endendassign out=count1|count2;半整數(shù)分頻module fdiv5_5(clkin,clr,clkout)input clkin,clr;outpu

18、t reg clkout;reg clk1; wire clk2; integer count;xor xor1(clk2,clkin,clk1)always(posedge clkout or negedge clr)beginif(clr) begin clk1=1b0; endelse clk1=clk1;endalways( posedge clk2 or negedge clr)beginif(clr)begin count=0; clkout=1b0; endelse if(count=5)begin count=0; clkout=1b1; endelse begin count

19、=count+1; clkout=1b0; endend endmodule 小數(shù)分頻n=m/p。 n為分配比,m為分頻器輸入脈沖數(shù),p為分頻器輸出脈沖數(shù)。n=(89+91)/(9+1)=8。1 先做9次8分頻再做1次9分頻.module fdiv8_1(clkin,rst,clkout) input clkin,rst; output reg clkout; reg3:0 cnt1,cnt2; always(posedge clkin or posedge rst) begin if(rst) begin cnt1=0;cnt2=0;clkout=0; end else if(cnt19)

20、/cnt1, 08 begin if(cnt27) begin cnt2=cnt2+1;clkout=0; end else begin cnt2=0;cnt1=cnt1+1;clkout=1; end end else begin /cnt1, 9 if(cnt28) begin cnt2=cnt2+1;clkout=0; end else begin cnt2=0;cnt1=0;clkout=1;end end endendmodule串并轉換module p2s(clk,clr,load,pi,so)input clk,clr,load;input 3:0 pi;output so;re

21、g3:0 r;always(posedge clk or negedge clr)if(clr)r=4h0;else if(load)r=pi;elser=r, 1b0; / or r1;assign so=r3;endmodulemodule s2p(clk,clr,en,si,po)input clk,clr,en,si;output3:0 po;always(posedge clk or negedge clr)if(clr)r=8ho;else r=r,si;assign po=(en) ? r : 4h0;endmoduleb) 試用vhdl或verilog、able描述8位d觸發(fā)器

22、邏輯.module dff(q,qn,d,clk,set,reset)input7:0 d,set;input clk,reset;output reg7:0 q,qn;always (posedge clk) beginif(reset) beginq=8h00; qn=8hff;endelse if(set) beginq=8hff; qn=8h00;endelse begin q=d; qn=d; endendendmodule序列檢測“101”module xulie101(clk,clr,x,z);input clk,clr,x;output reg z;reg1:0 state,n

23、ext_state;parameter s0=2b00,s1=2b01,s2=2b11,s3=2b10;always (posedge clk or posedge clr)begin if(clr) state=s0;else state=next_state;endalways (state or x)begincase(state)s0:begin if(x)next_state=s1; elsenext_state=s0;ends1:begin if(x)next_state=s1; elsenext_state=s2;ends2:begin if(x)next_state=s3; e

24、lsenext_state=s0;ends3:begin if(x)next_state=s1; elsenext_state=s2;enddefault: next_state=s0;endcaseendalways (state)begincase(state)s3:z=1;default:z=0;endcaseendendmodule按鍵消抖1. 采用一個頻率較低的時鐘,對輸入進行采樣,消除抖動。module switch(clk,keyin,keyout)parameter countwidth=8;input clk,keyin;output reg keyout; regcount

25、width-1:0 counter;wire clk_use;/頻率較低的時鐘assign clk_use=countercountwidth1;always(posegde clk)counter=counter+1b1;always(posedge clk_use)keyout=keyin;endmodule2。 module switch(clk,keyin,keyout)parameter countwidth=8;input clk,keyin;output reg keyout; regcountwidth-1:0 counter;initial counter=0,keyout=

26、0,keyin=0;always(posegde clk)if(keyin=1) begin key_m=keyin, counter=counter+1;endelse counter=0;if(keyin&counterm) keyout=1;/m定義時延endmodule數(shù)碼管顯示module number_mod_module /分別取得數(shù)字的十位和個位(clk, rstn, number_data, ten_data, one_data); input clk; input rstn; input 7:0number_data; output 3:0ten_data; output

27、3:0one_data; reg 31:0rten; reg 31:0rone; always ( posedge clk or negedge rstn ) if( !rstn ) begin rten = 32d0; rone = 32d0;endelse begin rten = number_data / 10; rone = number_data 10; end assign ten_data = rten3:0; assign one_data = rone3:0;endmodulemodule led(clk, ten_data, one_data,led0, led1); /

28、數(shù)碼管顯示input 3:0 ten_data, one_data;input clk;output 7:0 led0, led1;reg7:0 led0, led1;always ( posedge cp_50)begincasez (one_data)4d0 : led0 = 8b1100_0000;4d1 : led0 = 8b1111_1001;4d2 : led0 = 8b1010_0100;4d3 : led0 = 8b1011_0000;4d4 : led0 = 8b1001_1001;4d5 : led0 = 8b1001_0010;4d6 : led0 = 8b1000_00

29、10;4d7 : led0 = 8b1111_1000;4d8 : led0 = 8b1000_0000;4d9 : led0 = 8b1001_0000;default: led0 = 8b1111_1111;endcasecasez (ten_data)4d0 : led1 = 8b1100_0000;4d1 : led1 = 8b1111_1001;4d2 : led1 = 8b1010_0100;4d3 : led1 = 8b1011_0000;4d4 : led1 = 8b1001_1001;4d5 : led1 = 8b1001_0010;4d6 : led1 = 8b1000_0

30、010;4d7 : led1 = 8b1111_1000;4d8 : led1 = 8b1000_0000;4d9 : led1 = 8b1001_0000;default: led0 = 8b1111_1111;endcaseendendmodule5. fifo控制器。fifo存儲器 fifo是英文first in first out 的縮寫,是一種先進先出的數(shù)據(jù)緩存器,他與普通存儲器的區(qū)別是沒有外部讀寫地址線,這樣使用起來非常簡單,但缺點就是只能順序寫入數(shù)據(jù),順序的讀出數(shù)據(jù),其數(shù)據(jù)地址由內(nèi)部讀寫指針自動加1完成,不能像普通存儲器那樣可以由地址線決定讀取或寫入某個指定的地址。 在系統(tǒng)設計中

31、,以增加數(shù)據(jù)傳輸率、處理大量數(shù)據(jù)流、匹配具有不同傳輸率的系統(tǒng)為目的而廣泛使用fifo存儲器,從而提高了系統(tǒng)性能.fifo參數(shù):fifo的寬度,the width,指fifo一次讀寫操作的數(shù)據(jù)位;fifo深度,the deepth,指fifo可以存儲多少個n位的數(shù)據(jù);滿標志,fifo已滿或將要滿時送出的一個信號,以阻止fifo的血操作繼續(xù)向fifo中寫數(shù)據(jù)而造成溢出(overflow);空標志,阻止fifio的讀操作;module fifo_module( input clk, input rstn, input write_req, input 7:0fifo_write_data, inpu

32、t read_req, output 7:0fifo_read_data, output full_sig, output empty_sig, /*/ output 7:0sq_rs1, output 7:0sq_rs2, output 7:0sq_rs3, output 7:0sq_rs4, output 2:0sq_count /*/); /*/ parameter deep = 3d4; /*/ reg 7:0rshift deep:0; reg 2:0count; reg 7:0data; always ( posedge clk or negedge rstn ) if( !rst

33、n ) begin rshift0 = 8d0; rshift1 = 8d0; rshift2 = 8d0; rshift3 = 8d0; rshift4 = 8d0; count = 3d0; data = 8d0; end else if( read_req & write_req & count deep & count 0 ) begin rshift1 = fifo_write_data; rshift2 = rshift1; rshift3 = rshift2; rshift4 = rshift3; data = rshift count ; end else if( write_

34、req & count deep ) begin rshift1 = fifo_write_data; rshift2 = rshift1; rshift3 = rshift2; rshift4 0 ) begin data = rshiftcount; count = count 1b1; end /*/ assign fifo_read_data = data; assign full_sig = ( count = deep ) ? 1b1 : 1b0; assign empty_sig = ( count = 0 ) ? 1b1 : 1b0; /*/ assign sq_rs1 = r

35、shift1; assign sq_rs2 = rshift2; assign sq_rs3 = rshift3; assign sq_rs4 = rshift4; assign sq_count = count; /*/endmodulefifi 2 (指針控制)module fifo(date,q,clr,clk,we,re,ff,ef);parameter width=8,deepth=8,addr=3;input clk,clr;input we,re;inputwidth-1:0 date;output ff,ef;output regwidth1:0 q;regwidth1:0 m

36、em_datedeepth1:0;regaddr1:0 waddr,raddr;reg ff,ef;always(posedge clk or negedge clr)/寫地址begin if(!clr) waddr=0;else if(we=1ff=0) waddr=waddr+1;else if(we=1&ff=0&waddr=7) waddr=0;endalways(posedge clk)begin if(we&!ff) mem_datewaddr=date;endalways(posedge clk or negedge clr)/讀地址begin if(!clr) raddr=0;

37、else if(re=1&ef=0) raddr=waddr+1;else if(re=1&ef=0raddr=7) raddr=0;endalways(posedge clk)begin if(re&!ef) q=mem_dateraddr;endalways(posedge clk or negedge clr)begin if(!clr) ff=1b0;else if((we !re) & (waddr=raddr-1) ((waddr=deepth-1) (raddr=1b0)))ff=1b1;else ff=1b0;endalways(posedge clk or negedge clr)begin if(!clr) ef

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論