请解释这些Verilog代码? [英] Please Explain these verilog code?

查看:162
本文介绍了请解释这些Verilog代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

展位乘数的代码是:-

module ni(prod, a, b, busy, mc, mp, clk, start);
output [15:0] prod;
output [7:0] a, b;
output busy;
input [7:0] mc, mp;
input clk, start;
reg [7:0] A, Q, M;
reg Q_1;
reg [3:0] count;
wire [7:0] sum, difference;
always @(posedge clk)
begin
if (start) begin

A <= 8'b0;
M <= mc;
Q <= mp;
Q_1 <= 1'b0;

count <= 4'b0;
end
else begin

case ({Q[0], Q_1})
         2'b0_1 : {A, Q, Q_1} <= {sum[7], sum, Q};
         2'b1_0 : {A, Q, Q_1} <= {difference[7], difference, Q};
         default: {A, Q, Q_1} <= {A[7], A, Q};
      endcase




count <= count + 1'b1;
end
end
alu adder (sum, A, M, 1'b0);
alu subtracter (difference, A, ~M, 1'b1);
assign prod = {A, Q};
assign a = A;
assign b = Q ;
assign busy = (count < 8);
initial 
  begin 
    $monitor($time,"prod=%b, A=%b, Q=%b, Q_1=%b, M=%d, sum=%d, difference=%d, busy==%b, mc=%b, mp=%b, clk=%b, start=%b",
                      prod, A, Q, Q_1, M, sum,difference, busy, mc, mp, clk, start);
  end
endmodule
//The following is an alu.
//It is an adder, but capable of subtraction:
//Recall that subtraction means adding the two's complement--
//a - b = a + (-b) = a + (inverted b + 1)
//The 1 will be coming in as cin (carry-in)
module alu(out, a, b, cin);
output [7:0] out;
input [7:0] a;
input [7:0] b;
input cin;

assign out = a + b + cin;

endmodule

我想知道以下几行代码:-

i want to know how these lines of codes:-

case ({Q[0], Q_1})
             2'b0_1 : {A, Q, Q_1} <= {sum[7], sum, Q};
             2'b1_0 : {A, Q, Q_1} <= {difference[7], difference, Q};
             default: {A, Q, Q_1} <= {A[7], A, Q};
          endcase

解释以下逻辑:-

乘数和被乘数放在Q和 分别为M个寄存器.还有一个1位寄存器 逻辑上在 Q寄存器的最低有效位(Q0),指定为Q-1;它的 用法将简要说明. 乘法结果将出现在A和Q中 寄存器. A和Q-1是 初始化为0.与以前一样,控制逻辑扫描 一次乘一. 现在,在检查每个位时,也要检查其右边的位. 如果两位是 相同(1-1或0-0),则A,Q和Q-1寄存器的所有位 移到右边 1位.如果两个位不同,则将被乘数加到或 从A减去 寄存器,取决于这两位是0-1还是1-0.下列的 加法或 减法,发生右移.无论哪种情况,右移 使得最左边的位 A的An-1,即An-1,不仅转移到An-2,而且还保留在 An-1.这是必需的 保留A和Q中数字的符号.它被称为 算术移位,因为 它保留了符号位.

the multiplier and multiplicand are placed in the Q and M registers, respectively. There is also a 1-bit register placed logically to the right of the least significant bit (Q0) of the Q register and designated Q-1; its use is explained shortly. The results of the multiplication will appear in the A and Q registers. A and Q-1 are initialized to 0. As before, control logic scans the bits of the multiplier one at a time. Now, as each bit is examined, the bit to its right is also examined. If the two bits are the same (1-1 or 0-0), then all of the bits of the A, Q, and Q-1 registers are shifted to the right 1 bit. If the two bits differ, then the multiplicand is added to or subtracted from the A register, depending on whether the two bits are 0-1 or 1-0. Following the addition or subtraction, the right shift occurs. In either case, the right shift is such that the leftmost bit of A, namely An-1, not only is shifted into An-2, but also remains in An-1. This is required to preserve the sign of the number in A and Q. It is known as an arithmetic shift, because it preserves the sign bit.

推荐答案

实际上{}运算符将sum [7],sum和Q组合在一起,并按指定的顺序将其分配给左侧变量,即A,Q,Q- 1.A的左位保持不变.

actually {} operator combines the sum[7],sum and Q and assign it to the left side variables in the order specified i.e A,Q,Q-1.So the left bit of A remains as it is.

这篇关于请解释这些Verilog代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆