-2
if(Op_ex == 5'b11011 || Op_ex==5'b11100 || Op_ex==5'b11101 || Op_ex==5'b11110 || Op_ex==5'b11111 )
 begin
    temp_carry = 1'b0;
    ans_ex = A   >>>   B;
    flag[3] = ans_ex[0]^ans_ex[1]^ans_ex[2]^ans_ex[3]^ans_ex[4]^ans_ex[5]^ans_ex[6]^ans_ex[7];  //flag[3] = parity
    flag[2] = 0;                                                  //flag[2] = overflow  
    flag[0] = 0;
    if(ans_ex == 8'b00000000)
        begin
            flag[1] = 1'b1;                                   //flag[1] = zero
        end
    else
        begin
            flag[1] = 1'b0;
        end
        data_out = reg_data;
 end         
end 

If I put A = 8'hC0 and B = 8'h01 then it will give me output as 60, instead of e0 in hexadecimal .

Qiu
  • 5,651
  • 10
  • 49
  • 56
Jay Dangar
  • 3,271
  • 1
  • 16
  • 35

1 Answers1

1

A is unsigned. The sign extinction of an unsigned is always 0. Make A (possibly B well) a signed value. Two was to do so:

  • input signed [7:0] A,B
  • ans_ex = $signed(A) >>> B;

FYI:
(Op_ex == 5'b11011 || Op_ex==5'b11100 || Op_ex==5'b11101 || Op_ex==5'b11110 || Op_ex==5'b11111 ) can be simplified to (Op_ex >= 5'b11011)
flag[3] = ans_ex[0]^ans_ex[1]^ans_ex[2]^ans_ex[3]^ans_ex[4]^ans_ex[5]^ans_ex[6]^ans_ex[7]; can be simplified to: flag[3] = ^ans_ex; or flag[3] = ^ans_ex[7:0];

Greg
  • 18,111
  • 5
  • 46
  • 68