if statement problem

L

lokesh kumar

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 = 8)
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)

Could you please help me to design the code to give me an idea about "if statement"?

Many Thanks!
 
G

GaborSzakacs

lokesh said:
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 = 8)
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)

Could you please help me to design the code to give me an idea about "if statement"?

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.
 
L

lokesh kumar

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.

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

goouse99

Am Dienstag, 23. Juli 2013 23:14:22 UTC+2 schrieb lokesh kumar:
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
 
L

lokesh kumar

Am Dienstag, 23. Juli 2013 23:14:22 UTC+2 schrieb lokesh kumar:




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
 
L

lokesh kumar

Am Dienstag, 23. Juli 2013 23:14:22 UTC+2 schrieb lokesh kumar:




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.
 
F

Fredxx

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

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.
 
N

Nicolas Matringe

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
added at the bottom

Nicolas
 
A

Andy Botterill

On Wednesday, July 24, 2013 11:54:10 AM UTC+5:30, (e-mail address 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
 
L

lokesh kumar

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));
 
B

Bart Fox

Am 24.07.13 20:17, schrieb lokesh kumar:
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));

$ ghdl -a test.vhd
test.vhd:1:2: entity, architecture, package or configuration keyword
expected
test.vhd:1:2: design file is empty (no design unit found)

There's a lot missing on your code. My vhdl code start with 'library
ieee' and ends with 'end architechture'

regards,
Bart
 
L

lokesh kumar

entity squr_5bit is
Port ( a : in STD_LOGIC_VECTOR (4 downto 0);
c : out STD_LOGIC_VECTOR (8 downto 0));
end squr_5bit;

architecture Behavioral of squr_5bit is
signal b : STD_LOGIC_VECTOR (8 downto 0);
signal temp : STD_LOGIC_VECTOR (8 downto 0);
begin
position_even_b: for i in 0 to 4 generate b(2*i) <= a(i);
end generate;
c <= b;
position_odd_b: for i in 0 to 3 generate b(2*i+1) <= '0';
end generate;

-- position_c: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));
end Behavioral;
----------------------------------
This is the full code. I am taking a 5-bit number. And making its square. (Please note that the final addition is not a simple binary addition, its anXOR operation). So the output will be a 9-bit number. It suppose, A = a4a3 a2 a1 a0 then then output always come as, C = a4 0 a3 0 a2 0 a1 0 a0 (in this manner)
Now I need to reduce the output to 5-bit number.

suppose the square is, 101010101
For reduction, I have to use 100101.

101010101
100101
 
A

Andy

Every entry-level VHDL text book states that for-loops are sequential statements and must be in a process or subprogram (function/procedure).

Andy
 
P

Paul Uiterlinden

lokesh said:
entity squr_5bit is
Port ( a : in STD_LOGIC_VECTOR (4 downto 0);
c : out STD_LOGIC_VECTOR (8 downto 0));
end squr_5bit;

architecture Behavioral of squr_5bit is
signal b : STD_LOGIC_VECTOR (8 downto 0);
signal temp : STD_LOGIC_VECTOR (8 downto 0);
begin
position_even_b: for i in 0 to 4 generate b(2*i) <= a(i);
end generate;
c <= b;
position_odd_b: for i in 0 to 3 generate b(2*i+1) <= '0';
end generate;

-- position_c: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));
end Behavioral;

If you want a slice of a vector, it is temp(4 downto 0) instead of
(temp(4) downto temp(0)).
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top