max and min

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

  1. qwerty321

    qwerty321

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

  2. qwerty321

    qwerty321

    Joined:
    Dec 9, 2009
    Messages:
    18
    I really need help here guys
     
    qwerty321, Dec 13, 2009
    #2
    1. Advertising

  3. qwerty321

    joris

    Joined:
    Jan 29, 2009
    Messages:
    152
    builtin < and > operators are defined to work on two's complement numbers.
     
    joris, Dec 13, 2009
    #3
  4. qwerty321

    qwerty321

    Joined:
    Dec 9, 2009
    Messages:
    18
    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
    #4
  5. qwerty321

    joris

    Joined:
    Jan 29, 2009
    Messages:
    152
    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
    #5
  6. qwerty321

    qwerty321

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

    joris

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

    qwerty321

    Joined:
    Dec 9, 2009
    Messages:
    18
    it's ok i already did it
    like u said also :D
     
    qwerty321, Dec 13, 2009
    #8
  9. qwerty321

    CS_

    Joined:
    Dec 6, 2009
    Messages:
    3
    qwerty321 r u in QU ????
     
    CS_, Dec 14, 2009
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Aaron Boxer
    Replies:
    3
    Views:
    682
    Aaron Boxer
    Jul 7, 2003
  2. Lois
    Replies:
    1
    Views:
    3,245
    Ryan Stewart
    Dec 27, 2004
  3. juergen
    Replies:
    3
    Views:
    570
    opalpa@gmail.com opalinski from opalpaweb
    Sep 20, 2006
  4. Albert Hopkins

    When is min(a, b) != min(b, a)?

    Albert Hopkins, Jan 21, 2008, in forum: Python
    Replies:
    31
    Views:
    832
    Albert van der Horst
    Feb 4, 2008
  5. carmen

    Converting hrs and min to just min

    carmen, Aug 10, 2004, in forum: ASP General
    Replies:
    4
    Views:
    135
    carmen
    Aug 10, 2004
Loading...

Share This Page