4 位 ALU SLT 运算

问题描述 投票:0回答:1

我不明白如何在由 1 位 ALU 组成的 4 位纹波 ALU 中创建 SLT 指令。我不知道在 1 位 ALU 的 2'b11 中放入什么以及如何在我的 4 位 ALU 中将它们连接在一起。如果我无法判断是否是 < b till the MSB ALU. Here's my code, any help at all would be appreciated.

,我该如何设置 LSB

全加器:


module FullAdder(a, b, cin, sum, cout);
  input a, b, cin;
  output sum, cout;
  
  assign sum = a ^ b ^ cin;
  assign cout = (a & b) | ((a ^ b) & cin);
endmodule

1 位 ALU:

module OneBitALU(a, b, cin, ainv, binv, less, op, result,
cout, set);
  input a, b, cin;
  input ainv, binv;
  input less;
  input [1:0] op;
  
  output result;
  output cout;
  output set;
  wire aneg, bneg;
  
  reg result;  
  reg tmp;
  reg set;
  assign aneg = ainv ? ~a : a;
  assign bneg = binv ? ~b : b;
  
  FullAdder fulladder(aneg, bneg, cin, tmp, cout);
  
  always @ (*) begin
    case(op)
      2'b00: result = aneg & bneg;
      2'b01: result = aneg | bneg;
      2'b10: result = tmp;
      2'b11: result = less;
      default: result = 1'b0;   
    endcase
  end
endmodule
    

4 位 ALU:


module FourBitALU(a, b, op, result, cout);
  input [3:0] a, b; 
  input [3:0] op;
  
  output [3:0] result;
  output cout;
  reg [3:0] result;
  reg [3:0] sum;
  wire [2:0] co;
  
  OneBitALU oba0(a[0], b[0], op[2], op[3], op[2], sum[3], op[1:0], result[0], co[0], sum[0]);
  OneBitALU oba1(a[1], b[1], co[0], op[3], op[2], 0, op[1:0], result[1], co[1], sum[1]);
  OneBitALU oba2(a[2], b[2], co[1], op[3], op[2], 0, op[1:0], result[2], co[2], sum[2]);
  OneBitALU oba3(a[3], b[3], co[2], op[3], op[2], 0, op[1:0], result[3], cout, sum[3]);
  
endmodule

更改了它,因此当 op = 0111 时,结果设置为较小,但现在我只能得到高阻抗状态。

verilog
1个回答
0
投票

对于SLT(设置小于)指令,根据RISC-V指令集架构,应该实现如下: “如果寄存器 rs1 小于寄存器 rs2(且两者都被视为有符号数),则将值 1 放入寄存器 rd,否则将 0 写入 rd。”

因此请检查您尝试实施的 ISA,以了解实施它的正确方法。 如果您的 ISA 类似于 RISC-v,您应该将您的 1 位 ALU 更正为:

module OneBitALU(a, b, cin, ainv, binv, less, op, result,
cout, set);
  input a, b, cin;
  input ainv, binv;
  input less;
  input [1:0] op;
  
  output result;
  output cout;
  output set;
  wire aneg, bneg;
  
  reg result;  
  reg tmp;
  reg set;
  assign aneg = ainv ? ~a : a;
  assign bneg = binv ? ~b : b;
  assign less = (a>b)? 1'b1: 1'b0 ; // new line
  FullAdder fulladder(aneg, bneg, cin, tmp, cout);
  
  always @ (*) begin
    case(op)
      2'b00: result = aneg & bneg;
      2'b01: result = aneg | bneg;
      2'b10: result = tmp;
      2'b11: result = less;
      default: result = 1'b0;   
    endcase
  end
endmodule
© www.soinside.com 2019 - 2024. All rights reserved.