Tell me more ×
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free, no registration required.

I am designing a simple ALU with and, add, load operations for 16-bit inputs. This is what I have so far:

module ALU(overflow,out,in1,in2,select); 
input[1:0] select;
output[15:0] out;
output overflow;
reg[16:0] out;
reg overflow;
always @(in1,in2,select)

case(select)           

   0:out <= in1 & in2;    //and

   1:{overflow,out} <= in1 + in2;    //add

   2:out <= in1;         

   default: out<= 16'bx;

endcase                    
endmodule

I am confused how to deal with negative numbers and how to handle when my inputs are negative: what should I do?

share|improve this question
Please correct the writing. iam -> I am Makes it very difficult to tell what you're writing otherwise. Also place code in the proper style using the {} button. – Gustavo Litovsky Jan 22 at 21:42
Gustavo, just make the edit yourself next time. – dext0rb Jan 22 at 22:14
1  
Are you familiar with the concept of 2's complement arithmetic? It's not the only choice, but has become the most popular, at least for general-purpose computing. – Chris Stratton Jan 22 at 22:15
yes,i do.I was thinking in making inputs signed but in case of and operation it is logical operation doesn't deal with negative numbers – user18125 Jan 22 at 22:33
1  
You might want to put some effort into researching what typical CPUs do. I think you'll find that "inputs" aren't uniformly designated as signed or unsigned, but rather individual instructions interpret (or don't interpret) them that way. For logic functions the sometimes sign bit is just another bit - and sometimes it's important to be able to manipulate it logically. – Chris Stratton Jan 23 at 3:37

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.