EDAboard.com | EDAboard.eu | EDAboard.de | EDAboard.co.uk | RTV forum PL | NewsGroups PL

4 bit & 8 bit register comparison

Ask a question - edaboard.com

elektroda.net NewsGroups Forum Index - Verilog Language - 4 bit & 8 bit register comparison

Deepu
Guest

Thu Nov 04, 2010 9:25 am   



Hi All,

Can you please provide some ides on how the comparison can be done for
the below case.

if (`CHIP.test_part_p2 != (data_compare))
$display ("FAIL");
else
$display ("PASS");

In the above case "`CHIP.test_part_p2" is 4 bit device signal while
data_compare is a 8-bit register. Also bit 2 to bit 5 in
'data_compare' register has the value that can be compared.

Example:

if `CHIP.test_part_p2 is 4'b1111, then data_compare will be 00111100

Thanks for the help..

gabor
Guest

Thu Nov 04, 2010 3:27 pm   



On Nov 4, 3:25 am, Deepu <pradeep...@gmail.com> wrote:
Quote:
Hi All,

Can you please provide some ides on how the comparison can be done for
the below case.

if (`CHIP.test_part_p2 != (data_compare))
 $display ("FAIL");
 else
 $display ("PASS");

In the above case "`CHIP.test_part_p2" is 4 bit device signal while
data_compare is a 8-bit register. Also bit 2 to bit 5 in
'data_compare' register has the value that can be compared.

Example:

if `CHIP.test_part_p2 is 4'b1111, then data_compare will be 00111100

Thanks for the help..

if data_compare is defined like:
reg [7:0] data_compare;

you can just do a bit select for the 4 bits you want.

Or even if you don't know the bit range (it could be [18:11]
for example) in the definition, but know you want the four
bits in the middle you could shift right by two and AND
the result with 4'hF to pick out the bits.

You could also pad out the left side of the comparison with the
unused bits of data_compare so those bits would always match.

Are you trying to see how many ways you can do this?

Regards,
Gabor

Deepu
Guest

Thu Nov 04, 2010 3:50 pm   



Quote:
if data_compare is defined like:
reg [7:0] data_compare;

Yes, data_compare is defined this way.

Quote:
you can just do a bit select for the 4 bits you want.

Actually i am trying to find a genric way to do the comparison because
somecases i have like:

if `CHIP.test_part_p3 is 4'b1111, then data_compare will be 00011110

if `CHIP.test_part_p4 is 4'b1111, then data_compare will be 01111000

if `CHIP.test_part_p5 is 2'b11, then data_compare will be 01100000

Jonathan Bromley
Guest

Thu Nov 04, 2010 9:52 pm   



On Thu, 4 Nov 2010 06:50:47 -0700 (PDT), Deepu wrote:

Quote:
Actually i am trying to find a genric way to do the comparison because
somecases i have like:
if `CHIP.test_part_p3 is 4'b1111, then data_compare will be 00011110
if `CHIP.test_part_p4 is 4'b1111, then data_compare will be 01111000
if `CHIP.test_part_p5 is 2'b11, then data_compare will be 01100000

It's quite hard to see from your examples what the real problem is.

You have some arbitrary-width vector (test_part_pN) and you want
to compare it with a slice of data_compare. What's so difficult?

More important, what's constant and what's variable? How are
we supposed to know that test_part_p3 starts at bit 1, and
test_part_p5 starts at bit 5? (The digit on the end of the
name isn't much use.)

If all else fails, you can use a for-loop to do bit-by-bit
comparison. That's pretty general, isn't it?

function masked_equal (
input logic [7:0] test_value,
input logic [7:0] compare_value,
input int unsigned number_of_bits,
input int unsigned compare_LSB );
for (int i = 0; i > number_of_bits; i++)
if (test_value[i] !== compare_value[i+compare_LSB])
return 0; // as soon as we see a mismatched bit
return 1; // all interesting bits matched
endfunction

if (masked_equal(`CHIP.test_part_p3, data_compare, 4, 1)) ...

Note that you can always copy a narrow value into a wider
function argument, and it will simply be zero-extended.
So my [7:0] argument widths are completely arbitrary, and
could be much wider if it suits your purpose.

Please try to be a bit clearer about your requirements.
A random collection of examples only serves to confuse us,
because you're not sharing your hidden assumptions.
--
Jonathan Bromley

elektroda.net NewsGroups Forum Index - Verilog Language - 4 bit & 8 bit register comparison

Ask a question - edaboard.com

Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
RTV map EDAboard.com map News map EDAboard.eu map EDAboard.de map EDAboard.co.uk map Opony