Velocity Reviews > VHDL > if statement problem

# if statement problem

lokesh kumar
Guest
Posts: n/a

 07-23-2013
How can I use the "if statement"?

I have a 9-bit number. I need to check the MSB. If the MSB is "1" then I have to do the XOR operation with "100101" (reduction polynomial).

If the MSB is zero then I have skip the bit.

My main aim is to reduce the 9-bit number to 5-bit.

For example:
Here m = 5

Loop 1 (2m-2 =
101010100 (MSB is the 9th bit)
100101
---------
x01111100

MSB = 1 (true), XOR with reduction polynomial.
Result: 01111100 (8 bit result, removed the 9th bit)

Loop 2 (7)
01111100 (MSB is the 8th bit)
100101
--------

MSB = 0 (false), skip and end the loop.
Result: 01111100 (still 8 bit result, but we are not using the MSB for the next loop)

Loop 3 (6)
1111100 (MSB is the 7th bit)
100101
-------
x110110

MSB = 1 (true), XOR with reduction polynomial.
Result: 0110110 (7 bit result)

Loop 4 (m = 5)
110110 (MSB is the 6th bit)
100101
------
x10011 (Final result)

MSB = 1 (true), XOR with reduction polynomial.
Final result: 010011 (6 bit result, but we can discard the MSB)

Many Thanks!

GaborSzakacs
Guest
Posts: n/a

 07-23-2013
lokesh kumar wrote:
> How can I use the "if statement"?
>
> I have a 9-bit number. I need to check the MSB. If the MSB is "1" then I have to do the XOR operation with "100101" (reduction polynomial).
>
> If the MSB is zero then I have skip the bit.
>
> My main aim is to reduce the 9-bit number to 5-bit.
>
> For example:
> Here m = 5
>
> Loop 1 (2m-2 =
> 101010100 (MSB is the 9th bit)
> 100101
> ---------
> x01111100
>
> MSB = 1 (true), XOR with reduction polynomial.
> Result: 01111100 (8 bit result, removed the 9th bit)
>
> Loop 2 (7)
> 01111100 (MSB is the 8th bit)
> 100101
> --------
>
> MSB = 0 (false), skip and end the loop.
> Result: 01111100 (still 8 bit result, but we are not using the MSB for the next loop)
>
> Loop 3 (6)
> 1111100 (MSB is the 7th bit)
> 100101
> -------
> x110110
>
> MSB = 1 (true), XOR with reduction polynomial.
> Result: 0110110 (7 bit result)
>
> Loop 4 (m = 5)
> 110110 (MSB is the 6th bit)
> 100101
> ------
> x10011 (Final result)
>
> MSB = 1 (true), XOR with reduction polynomial.
> Final result: 010011 (6 bit result, but we can discard the MSB)
>
>
> Many Thanks!

Start with a 9-bit vector set to "100000000" then in each loop
first AND this with your number and then check for not zero,
then shift the 9-bit vector right by 1 (divide by 2). So
on the second loop it will become "010000000" on the third
loop "001000000", etc.

--
Gabor

lokesh kumar
Guest
Posts: n/a

 07-23-2013
On Wednesday, July 24, 2013 2:15:17 AM UTC+5:30, Gabor Sz wrote:
> lokesh kumar wrote:
>
> > How can I use the "if statement"?

>
> >

>
> > I have a 9-bit number. I need to check the MSB. If the MSB is "1" then I have to do the XOR operation with "100101" (reduction polynomial).

>
> >

>
> > If the MSB is zero then I have skip the bit.

>
> >

>
> > My main aim is to reduce the 9-bit number to 5-bit.

>
> >

>
> > For example:

>
> > Here m = 5

>
> >

>
> > Loop 1 (2m-2 =

>
> > 101010100 (MSB is the 9th bit)

>
> > 100101

>
> > ---------

>
> > x01111100

>
> >

>
> > MSB = 1 (true), XOR with reduction polynomial.

>
> > Result: 01111100 (8 bit result, removed the 9th bit)

>
> >

>
> > Loop 2 (7)

>
> > 01111100 (MSB is the 8th bit)

>
> > 100101

>
> > --------

>
> >

>
> > MSB = 0 (false), skip and end the loop.

>
> > Result: 01111100 (still 8 bit result, but we are not using the MSB for the next loop)

>
> >

>
> > Loop 3 (6)

>
> > 1111100 (MSB is the 7th bit)

>
> > 100101

>
> > -------

>
> > x110110

>
> >

>
> > MSB = 1 (true), XOR with reduction polynomial.

>
> > Result: 0110110 (7 bit result)

>
> >

>
> > Loop 4 (m = 5)

>
> > 110110 (MSB is the 6th bit)

>
> > 100101

>
> > ------

>
> > x10011 (Final result)

>
> >

>
> > MSB = 1 (true), XOR with reduction polynomial.

>
> > Final result: 010011 (6 bit result, but we can discard the MSB)

>
> >

>

>
> >

>
> > Many Thanks!

>
>
>
> Start with a 9-bit vector set to "100000000" then in each loop
>
> first AND this with your number and then check for not zero,
>
> then shift the 9-bit vector right by 1 (divide by 2). So
>
> on the second loop it will become "010000000" on the third
>
> loop "001000000", etc.
>
>
>
> --
>
> Gabor

Sorry, did not get you properly. I am a beginner. Could you please help me to implement it?

goouse99@gmail.com
Guest
Posts: n/a

 07-24-2013
Am Dienstag, 23. Juli 2013 23:14:22 UTC+2 schrieb lokesh kumar:
> On Wednesday, July 24, 2013 2:15:17 AM UTC+5:30, Gabor Sz wrote:
>
> > lokesh kumar wrote:

>
> >

>
> > > How can I use the "if statement"?

>
> >

>
> > >

>
> >

>
> > > I have a 9-bit number. I need to check the MSB. If the MSB is "1" then I have to do the XOR operation with "100101" (reduction polynomial).

>
> >

>
> > >

>
> >

>
> > > If the MSB is zero then I have skip the bit.

>
> >

>
> > >

>
> >

>
> > > My main aim is to reduce the 9-bit number to 5-bit.

>
> >

>
> > >

>
> >

>
> > > For example:

>
> >

>
> > > Here m = 5

>
> >

>
> > >

>
> >

>
> > > Loop 1 (2m-2 =

>
> >

>
> > > 101010100 (MSB is the 9th bit)

>
> >

>
> > > 100101

>
> >

>
> > > ---------

>
> >

>
> > > x01111100

>
> >

>
> > >

>
> >

>
> > > MSB = 1 (true), XOR with reduction polynomial.

>
> >

>
> > > Result: 01111100 (8 bit result, removed the 9th bit)

>
> >

>
> > >

>
> >

>
> > > Loop 2 (7)

>
> >

>
> > > 01111100 (MSB is the 8th bit)

>
> >

>
> > > 100101

>
> >

>
> > > --------

>
> >

>
> > >

>
> >

>
> > > MSB = 0 (false), skip and end the loop.

>
> >

>
> > > Result: 01111100 (still 8 bit result, but we are not using the MSB for the next loop)

>
> >

>
> > >

>
> >

>
> > > Loop 3 (6)

>
> >

>
> > > 1111100 (MSB is the 7th bit)

>
> >

>
> > > 100101

>
> >

>
> > > -------

>
> >

>
> > > x110110

>
> >

>
> > >

>
> >

>
> > > MSB = 1 (true), XOR with reduction polynomial.

>
> >

>
> > > Result: 0110110 (7 bit result)

>
> >

>
> > >

>
> >

>
> > > Loop 4 (m = 5)

>
> >

>
> > > 110110 (MSB is the 6th bit)

>
> >

>
> > > 100101

>
> >

>
> > > ------

>
> >

>
> > > x10011 (Final result)

>
> >

>
> > >

>
> >

>
> > > MSB = 1 (true), XOR with reduction polynomial.

>
> >

>
> > > Final result: 010011 (6 bit result, but we can discard the MSB)

>
> >

>
> > >

>
> >

>

>
> >

>
> > >

>
> >

>
> > > Many Thanks!

>
> >

>
> >

>
> >

>
> > Start with a 9-bit vector set to "100000000" then in each loop

>
> >

>
> > first AND this with your number and then check for not zero,

>
> >

>
> > then shift the 9-bit vector right by 1 (divide by 2). So

>
> >

>
> > on the second loop it will become "010000000" on the third

>
> >

>
> > loop "001000000", etc.

>
> >

>
> >

>
> >

>
> > --

>
> >

>
> > Gabor

>
>
>
> Sorry, did not get you properly. I am a beginner. Could you please help me to implement it?

Hi Lokesh,
if you need work to be done, hire someone.
People here will give you hints and tips if you get stuck with some problem, but they won't do (your) work for free. (They are mostly busy with their own stuff)

The other option is to learn the things for yourself, but you should begin with something simple and not so complicated mathematical problems. First focus on the HDL, and once you have mastered it you can focus on the complex problems.

So you either have to spend money or time, which is said to be equivalent.

Kind regards
Eilert

lokesh kumar
Guest
Posts: n/a

 07-24-2013
On Wednesday, July 24, 2013 11:54:10 AM UTC+5:30, (E-Mail Removed) wrote:
> Am Dienstag, 23. Juli 2013 23:14:22 UTC+2 schrieb lokesh kumar:
>
> > On Wednesday, July 24, 2013 2:15:17 AM UTC+5:30, Gabor Sz wrote:

>
> >

>
> > > lokesh kumar wrote:

>
> >

>
> > >

>
> >

>
> > > > How can I use the "if statement"?

>
> >

>
> > >

>
> >

>
> > > >

>
> >

>
> > >

>
> >

>
> > > > I have a 9-bit number. I need to check the MSB. If the MSB is "1" then I have to do the XOR operation with "100101" (reduction polynomial).

>
> >

>
> > >

>
> >

>
> > > >

>
> >

>
> > >

>
> >

>
> > > > If the MSB is zero then I have skip the bit.

>
> >

>
> > >

>
> >

>
> > > >

>
> >

>
> > >

>
> >

>
> > > > My main aim is to reduce the 9-bit number to 5-bit.

>
> >

>
> > >

>
> >

>
> > > >

>
> >

>
> > >

>
> >

>
> > > > For example:

>
> >

>
> > >

>
> >

>
> > > > Here m = 5

>
> >

>
> > >

>
> >

>
> > > >

>
> >

>
> > >

>
> >

>
> > > > Loop 1 (2m-2 =

>
> >

>
> > >

>
> >

>
> > > > 101010100 (MSB is the 9th bit)

>
> >

>
> > >

>
> >

>
> > > > 100101

>
> >

>
> > >

>
> >

>
> > > > ---------

>
> >

>
> > >

>
> >

>
> > > > x01111100

>
> >

>
> > >

>
> >

>
> > > >

>
> >

>
> > >

>
> >

>
> > > > MSB = 1 (true), XOR with reduction polynomial.

>
> >

>
> > >

>
> >

>
> > > > Result: 01111100 (8 bit result, removed the 9th bit)

>
> >

>
> > >

>
> >

>
> > > >

>
> >

>
> > >

>
> >

>
> > > > Loop 2 (7)

>
> >

>
> > >

>
> >

>
> > > > 01111100 (MSB is the 8th bit)

>
> >

>
> > >

>
> >

>
> > > > 100101

>
> >

>
> > >

>
> >

>
> > > > --------

>
> >

>
> > >

>
> >

>
> > > >

>
> >

>
> > >

>
> >

>
> > > > MSB = 0 (false), skip and end the loop.

>
> >

>
> > >

>
> >

>
> > > > Result: 01111100 (still 8 bit result, but we are not using the MSB for the next loop)

>
> >

>
> > >

>
> >

>
> > > >

>
> >

>
> > >

>
> >

>
> > > > Loop 3 (6)

>
> >

>
> > >

>
> >

>
> > > > 1111100 (MSB is the 7th bit)

>
> >

>
> > >

>
> >

>
> > > > 100101

>
> >

>
> > >

>
> >

>
> > > > -------

>
> >

>
> > >

>
> >

>
> > > > x110110

>
> >

>
> > >

>
> >

>
> > > >

>
> >

>
> > >

>
> >

>
> > > > MSB = 1 (true), XOR with reduction polynomial.

>
> >

>
> > >

>
> >

>
> > > > Result: 0110110 (7 bit result)

>
> >

>
> > >

>
> >

>
> > > >

>
> >

>
> > >

>
> >

>
> > > > Loop 4 (m = 5)

>
> >

>
> > >

>
> >

>
> > > > 110110 (MSB is the 6th bit)

>
> >

>
> > >

>
> >

>
> > > > 100101

>
> >

>
> > >

>
> >

>
> > > > ------

>
> >

>
> > >

>
> >

>
> > > > x10011 (Final result)

>
> >

>
> > >

>
> >

>
> > > >

>
> >

>
> > >

>
> >

>
> > > > MSB = 1 (true), XOR with reduction polynomial.

>
> >

>
> > >

>
> >

>
> > > > Final result: 010011 (6 bit result, but we can discard the MSB)

>
> >

>
> > >

>
> >

>
> > > >

>
> >

>
> > >

>
> >

>

>
> >

>
> > >

>
> >

>
> > > >

>
> >

>
> > >

>
> >

>
> > > > Many Thanks!

>
> >

>
> > >

>
> >

>
> > >

>
> >

>
> > >

>
> >

>
> > > Start with a 9-bit vector set to "100000000" then in each loop

>
> >

>
> > >

>
> >

>
> > > first AND this with your number and then check for not zero,

>
> >

>
> > >

>
> >

>
> > > then shift the 9-bit vector right by 1 (divide by 2). So

>
> >

>
> > >

>
> >

>
> > > on the second loop it will become "010000000" on the third

>
> >

>
> > >

>
> >

>
> > > loop "001000000", etc.

>
> >

>
> > >

>
> >

>
> > >

>
> >

>
> > >

>
> >

>
> > > --

>
> >

>
> > >

>
> >

>
> > > Gabor

>
> >

>
> >

>
> >

>
> > Sorry, did not get you properly. I am a beginner. Could you please helpme to implement it?

>
>
>
> Hi Lokesh,
>
> if you need work to be done, hire someone.
>
> People here will give you hints and tips if you get stuck with some problem, but they won't do (your) work for free. (They are mostly busy with their own stuff)
>
>
>
> The other option is to learn the things for yourself, but you should begin with something simple and not so complicated mathematical problems. Firstfocus on the HDL, and once you have mastered it you can focus on the complex problems.
>
>
>
> So you either have to spend money or time, which is said to be equivalent..
>
>
>
> Kind regards
>
> Eilert

I did not force anyone to do the code either. I know you are right. But thing is that it is not always possible to solve the problem just by reading the books. Its a part of my project and I need to finish by the end of this month. Hiring someone for it, is not a big deal. But I want to learn something.As a computer science student, I do not have much idea about VHDL coding. And it 2 months are not enough to learn everything in VHDL. So I posted my query here, believing that someone might reply to it. There are a lot ofpeople who have passion about programming and they love to solve the problems. May be not like you, who just can give a hint or something. Sometimes the hints are not enough. I have been trying, still I am unable to solve the query. After all the query is not directly related to my project because it is difficult to put all the details of my project here. I wanted to knowhow the implementation is going on, So that I can relate it to my originalproject.

Some people have time to log on to the group, reading questions and giving the hints. But I would suggest they should reply to the appropriate question what they can answer.

Regards

lokesh kumar
Guest
Posts: n/a

 07-24-2013
On Wednesday, July 24, 2013 11:54:10 AM UTC+5:30, (E-Mail Removed) wrote:
> Am Dienstag, 23. Juli 2013 23:14:22 UTC+2 schrieb lokesh kumar:
>
> > On Wednesday, July 24, 2013 2:15:17 AM UTC+5:30, Gabor Sz wrote:

>
> >

>
> > > lokesh kumar wrote:

>
> >

>
> > >

>
> >

>
> > > > How can I use the "if statement"?

>
> >

>
> > >

>
> >

>
> > > >

>
> >

>
> > >

>
> >

>
> > > > I have a 9-bit number. I need to check the MSB. If the MSB is "1" then I have to do the XOR operation with "100101" (reduction polynomial).

>
> >

>
> > >

>
> >

>
> > > >

>
> >

>
> > >

>
> >

>
> > > > If the MSB is zero then I have skip the bit.

>
> >

>
> > >

>
> >

>
> > > >

>
> >

>
> > >

>
> >

>
> > > > My main aim is to reduce the 9-bit number to 5-bit.

>
> >

>
> > >

>
> >

>
> > > >

>
> >

>
> > >

>
> >

>
> > > > For example:

>
> >

>
> > >

>
> >

>
> > > > Here m = 5

>
> >

>
> > >

>
> >

>
> > > >

>
> >

>
> > >

>
> >

>
> > > > Loop 1 (2m-2 =

>
> >

>
> > >

>
> >

>
> > > > 101010100 (MSB is the 9th bit)

>
> >

>
> > >

>
> >

>
> > > > 100101

>
> >

>
> > >

>
> >

>
> > > > ---------

>
> >

>
> > >

>
> >

>
> > > > x01111100

>
> >

>
> > >

>
> >

>
> > > >

>
> >

>
> > >

>
> >

>
> > > > MSB = 1 (true), XOR with reduction polynomial.

>
> >

>
> > >

>
> >

>
> > > > Result: 01111100 (8 bit result, removed the 9th bit)

>
> >

>
> > >

>
> >

>
> > > >

>
> >

>
> > >

>
> >

>
> > > > Loop 2 (7)

>
> >

>
> > >

>
> >

>
> > > > 01111100 (MSB is the 8th bit)

>
> >

>
> > >

>
> >

>
> > > > 100101

>
> >

>
> > >

>
> >

>
> > > > --------

>
> >

>
> > >

>
> >

>
> > > >

>
> >

>
> > >

>
> >

>
> > > > MSB = 0 (false), skip and end the loop.

>
> >

>
> > >

>
> >

>
> > > > Result: 01111100 (still 8 bit result, but we are not using the MSB for the next loop)

>
> >

>
> > >

>
> >

>
> > > >

>
> >

>
> > >

>
> >

>
> > > > Loop 3 (6)

>
> >

>
> > >

>
> >

>
> > > > 1111100 (MSB is the 7th bit)

>
> >

>
> > >

>
> >

>
> > > > 100101

>
> >

>
> > >

>
> >

>
> > > > -------

>
> >

>
> > >

>
> >

>
> > > > x110110

>
> >

>
> > >

>
> >

>
> > > >

>
> >

>
> > >

>
> >

>
> > > > MSB = 1 (true), XOR with reduction polynomial.

>
> >

>
> > >

>
> >

>
> > > > Result: 0110110 (7 bit result)

>
> >

>
> > >

>
> >

>
> > > >

>
> >

>
> > >

>
> >

>
> > > > Loop 4 (m = 5)

>
> >

>
> > >

>
> >

>
> > > > 110110 (MSB is the 6th bit)

>
> >

>
> > >

>
> >

>
> > > > 100101

>
> >

>
> > >

>
> >

>
> > > > ------

>
> >

>
> > >

>
> >

>
> > > > x10011 (Final result)

>
> >

>
> > >

>
> >

>
> > > >

>
> >

>
> > >

>
> >

>
> > > > MSB = 1 (true), XOR with reduction polynomial.

>
> >

>
> > >

>
> >

>
> > > > Final result: 010011 (6 bit result, but we can discard the MSB)

>
> >

>
> > >

>
> >

>
> > > >

>
> >

>
> > >

>
> >

>

>
> >

>
> > >

>
> >

>
> > > >

>
> >

>
> > >

>
> >

>
> > > > Many Thanks!

>
> >

>
> > >

>
> >

>
> > >

>
> >

>
> > >

>
> >

>
> > > Start with a 9-bit vector set to "100000000" then in each loop

>
> >

>
> > >

>
> >

>
> > > first AND this with your number and then check for not zero,

>
> >

>
> > >

>
> >

>
> > > then shift the 9-bit vector right by 1 (divide by 2). So

>
> >

>
> > >

>
> >

>
> > > on the second loop it will become "010000000" on the third

>
> >

>
> > >

>
> >

>
> > > loop "001000000", etc.

>
> >

>
> > >

>
> >

>
> > >

>
> >

>
> > >

>
> >

>
> > > --

>
> >

>
> > >

>
> >

>
> > > Gabor

>
> >

>
> >

>
> >

>
> > Sorry, did not get you properly. I am a beginner. Could you please help me to implement it?

>
>
>
> Hi Lokesh,
>
> if you need work to be done, hire someone.
>
> People here will give you hints and tips if you get stuck with some problem, but they won't do (your) work for free. (They are mostly busy with their own stuff)
>
>
>
> The other option is to learn the things for yourself, but you should begin with something simple and not so complicated mathematical problems. First focus on the HDL, and once you have mastered it you can focus on the complex problems.
>
>
>
> So you either have to spend money or time, which is said to be equivalent.
>
>
>
> Kind regards
>
> Eilert

Eliert: I would say please do not post any comment on anyone's profile (who really wants to learn something) if you really can not help him.It is disappointing.

Fredxx
Guest
Posts: n/a

 07-24-2013
On 24/07/2013 10:43, lokesh kumar wrote:

<snip>

> I did not force anyone to do the code either. I know you are right.
> But thing is that it is not always possible to solve the problem just
> by reading the books. Its a part of my project and I need to finish
> by the end of this month. Hiring someone for it, is not a big deal.
> But I want to learn something.As a computer science student, I do not
> have much idea about VHDL coding. And it 2 months are not enough to
> learn everything in VHDL. So I posted my query here, believing that
> someone might reply to it. There are a lot of people who have passion
> about programming and they love to solve the problems. May be not
> like you, who just can give a hint or something. Sometimes the hints
> are not enough. I have been trying, still I am unable to solve the
> query. After all the query is not directly related to my project
> because it is difficult to put all the details of my project here. I
> wanted to know how the implementation is going on, So that I can
> relate it to my original project.
>
> Some people have time to log on to the group, reading questions and
> giving the hints. But I would suggest they should reply to the
> appropriate question what they can answer.
>
> Regards
>

I learnt VHDL the hard way, and I still have to lookup old designs for
reference. There is much example VHDL on the net and there is also
Ashenden's cookbook on the 'net to give you ideas of what you can do.

Good luck, it seems you have much to do in the next week.

Nicolas Matringe
Guest
Posts: n/a

 07-24-2013
Le 23/07/2013 23:14, lokesh kumar wrote (but he quoted a lot of stuff
and empty lines before) :

> Sorry, did not get you properly. I am a beginner. Could you please help me to implement it?

It would be realy nice if you trimmed your posts so that readers
wouldn't have to scroll several pages to read the one sentence you've

Nicolas

Andy Botterill
Guest
Posts: n/a

 07-24-2013
On 07/24/2013 10:46 AM, lokesh kumar wrote:
> On Wednesday, July 24, 2013 11:54:10 AM UTC+5:30, (E-Mail Removed) wrote:
>
> Eliert: I would say please do not post any comment on anyone's profile (who really wants to learn something) if you really can not help him.It is disappointing.

lokesh

You say you are trying to learn.
Post the code you have written and say where you are stuck.
It is unfair and unreasonable to expect someone else to do your work for
you.

Andy
>

lokesh kumar
Guest
Posts: n/a

 07-24-2013
for i in 8 downto 5 loop
if b(i) = '1' then
(temp(i) downto temp (i-5)) <= (b(i) downto b(i-5)) xor "100101";
else if b(i) = '0';
null;
end if;
end loop;
c <= (temp(4) downto temp(0));
--------
This is the code that I tried to write. But I am getting some unexpected errors. could anyone please help me out with it?