Falu2

Verilog

基本語法

型態

全域變數

基本元件

多樣的寫法

指定

assign

always

initial

運算式

分枝

迴圈

模組

函數

Task

陣列

輸出入

觀察

真值表

測試程式

訊息顯示

注意事項

模擬程序

硬體工程

程式範例

Xor

Xor3

全加器

加法器

加減器

快速加法器

乘法器

ALU

閂鎖器

脈衝偵測

計數器

多工器

暫存器群

記憶體

延遲問題

浮點數

狀態機

程式計數器

CPU0-Mini

CPU0

pipeline

工具

QuartusII

Icarus

Veritek

訊息

相關網站

參考文獻

最新修改

簡體版

English

程式:falu2.v

module main;
 reg  [1:0] op;
 reg [63:0] a, b, y;

task falu(input [63:0] a1, input [63:0] b1, output [63:0] y1);
real a, b, y;
begin
  a = $bitstoreal(a1);
  b = $bitstoreal(b1);
  case (op)
    2'b00: y = a + b;
    2'b01: y = a - b;
    2'b10: y = a * b;
    2'b11: y = a / b;
  endcase
  y1 = $realtobits(y);
end endtask

 initial begin
  a = $realtobits(3.14);
  b = $realtobits(50*50);
  op = 2'b00;
 end

 always #50 begin
   op = op + 1;
   falu(a, b, y);
   $display("%dns: op=%b a=%f b=%f y=%f", $stime, op, $bitstoreal(a), $bitstoreal(b), $bitstoreal(y));
end

initial #1000 $finish;

endmodule

執行結果

D:\oc>iverilog falu2.v -o falu2

D:\oc>vvp falu2
        50ns: op=01 a=3.140000 b=2500.000000 y=-2496.860000
       100ns: op=10 a=3.140000 b=2500.000000 y=7850.000000
       150ns: op=11 a=3.140000 b=2500.000000 y=0.001256
       200ns: op=00 a=3.140000 b=2500.000000 y=2503.140000
       250ns: op=01 a=3.140000 b=2500.000000 y=-2496.860000
       300ns: op=10 a=3.140000 b=2500.000000 y=7850.000000
       350ns: op=11 a=3.140000 b=2500.000000 y=0.001256
       400ns: op=00 a=3.140000 b=2500.000000 y=2503.140000
       450ns: op=01 a=3.140000 b=2500.000000 y=-2496.860000
       500ns: op=10 a=3.140000 b=2500.000000 y=7850.000000
       550ns: op=11 a=3.140000 b=2500.000000 y=0.001256
       600ns: op=00 a=3.140000 b=2500.000000 y=2503.140000
       650ns: op=01 a=3.140000 b=2500.000000 y=-2496.860000
       700ns: op=10 a=3.140000 b=2500.000000 y=7850.000000
       750ns: op=11 a=3.140000 b=2500.000000 y=0.001256
       800ns: op=00 a=3.140000 b=2500.000000 y=2503.140000
       850ns: op=01 a=3.140000 b=2500.000000 y=-2496.860000
       900ns: op=10 a=3.140000 b=2500.000000 y=7850.000000
       950ns: op=11 a=3.140000 b=2500.000000 y=0.001256

Facebook

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License