# max and min

Discussion in 'VHDL' started by qwerty321, Dec 13, 2009.

1. ### qwerty321

Joined:
Dec 9, 2009
Messages:
18
0
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, Dec 13, 2009

2. ### qwerty321

Joined:
Dec 9, 2009
Messages:
18
0
I really need help here guys

qwerty321, Dec 13, 2009

3. ### joris

Joined:
Jan 29, 2009
Messages:
152
0
builtin < and > operators are defined to work on two's complement numbers.

joris, Dec 13, 2009
4. ### qwerty321

Joined:
Dec 9, 2009
Messages:
18
0
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

qwerty321, Dec 13, 2009
5. ### joris

Joined:
Jan 29, 2009
Messages:
152
0
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)

joris, Dec 13, 2009
6. ### qwerty321

Joined:
Dec 9, 2009
Messages:
18
0
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.

qwerty321, Dec 13, 2009
7. ### joris

Joined:
Jan 29, 2009
Messages:
152
0
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.

joris, Dec 13, 2009
8. ### qwerty321

Joined:
Dec 9, 2009
Messages:
18
0
it's ok i already did it
like u said also

qwerty321, Dec 13, 2009

Joined:
Dec 6, 2009
Messages:
3