Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
15 years ago

need help to design calculator function (addition and multiplication)

i need to design calculator that performs operations of addition and multiplication of 2 input (5-bit binary) that representing signed decimal numbers (range, -16 to + 15). I've already done the coding but now i'm stuck in BCD and seven segment coding..can anybody help me :cry:

module calculator (a,b,outadd,outmul, add,mul,clk);

input signed [4:0] a ;

input signed [4:0] b;

input add , mul;

input clk;

output reg [5:0] outadd;

output reg [9:0] outmul;

always @ (posedge clk)

begin

if (add)

outadd <= a + b;

begin

if (mul)

outmul <= a * b;

end

end

endmodule

17 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Where is the module name?

    sevsegment_1 (bcd_1,out1);
    should be

    7segment sevsegment_1 (bcd_1,out1);
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    got problem when i want to adding in negative side at bcd...example -16-16 =-32, in bcd the answer is 992...why this thing happen...

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I have told before, how negative numbers can be treated. You can't apply BCD conversion to 2s complement number representation.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I already invert the negative using this coding, but the answer still same

    always @ (*)

    begin

    if (resulta[9]==0)

    inv=resulta;

    else if (resulta[9]==1)

    inv = ((~resulta)+5'b00001);
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    I already invert the negative using this coding, but the answer still same

    --- Quote End ---

    Effectively impossible in my opinion.