Velocity Reviews > VHDL > max and min

# max and min

qwerty321
Junior Member
Join Date: Dec 2009
Posts: 18

 12-13-2009
Hello
I have 2 8 bit vectors A and B and i need to write a vhdl code to find the maximum and minimum bewtween A and B but the comparison is to be done for two’s complement number so I can't use the built in < and > operators..any idea guys?

Thank you

qwerty321
Junior Member
Join Date: Dec 2009
Posts: 18

 12-13-2009
I really need help here guys

joris
Senior Member
Join Date: Jan 2009
Posts: 152

 12-13-2009
builtin < and > operators are defined to work on two's complement numbers.

qwerty321
Junior Member
Join Date: Dec 2009
Posts: 18

 12-13-2009
yeah but what i mean is:

if i have A=11000011 and B=00011001 then using the operator i will have A>B but because these are 2's complement B is greater than A because A is negative and B positive

joris
Senior Member
Join Date: Jan 2009
Posts: 152

 12-13-2009
in that case you're (incorrectly) interpreting them as unsigned,
you should be able to "cast" an unsigned value to a signed value (2nd complement interpretation), like,
signed(A) > signed(B)

Or only use signed instead of unsigned in the design (depending on your needs, one may be a better solution than the other)

qwerty321
Junior Member
Join Date: Dec 2009
Posts: 18

 12-13-2009
i did not understand what you said

the question says:

8-bit Comparison Operations

Control Signals C Operation
0101 Minimum of A and B
0110 Maximum of A and B
The comparison is to be done for two’s complement numbers and you are supposed to implement it yourself, so do not use the built in > and < available for standard logic vectors.

joris
Senior Member
Join Date: Jan 2009
Posts: 152

 12-13-2009
You didn't say that before;

I don't think anyone here is going to solve your homework for you;
I'll just say this. Looking at the binary representations,

- Assuming both numbers are positive, how can you see which is bigger?
- Assuming both numbers are negative, how can you see which is bigger?
- Assuming one is positive, one is negative, how can you see which is bigger?

Try and answer those, case by case, then try and implement it.

qwerty321
Junior Member
Join Date: Dec 2009
Posts: 18

 12-13-2009
it's ok i already did it
like u said also

CS_
Junior Member
Join Date: Dec 2009
Posts: 3

 12-14-2009
qwerty321 r u in QU ????