0%

计算机组成原理试验一

bf872aac9531133175bdffd015a16058

module alu(a,b,aluc,r,z);
    input [31:0] a,b;
    input [3:0] aluc;
    output [31:0] r;
    output z;
    assign r = cal (a,b,aluc);
        assign z = ~|r;

        function [31:0] cal;
            input [31:0] a,b;
            input [3:0] aluc;
            casex (aluc)
                4'bx000: cal = a + b;
                4'bx100: cal = a - b;
                4'bx001: cal = a & b;
                4'bx101: cal = a | b;
                4'bx010: cal = a ^ b;
                4'bx110: cal = {b[15:0],16'h0};
                4'bx011: cal = b << a[4:0];
                4'b0111: cal = b >> a[4:0];
                4'b1111: cal = $signed(b) >>> a[4:0];
            endcase
        endfunction
endmodule

module ext8to32(a,s);
    input [7:0] a;
    output [31:0] s;
    assign s = {4{a}}; // 把a扩展成32位
endmodule
lmp_latch