• 0
Sign in to follow this  
askhunter

A question about vhdl.

Question

Hi, can anyone explain this syntax?

rom_bit <= xxx(to_integer(rom_addr))(to_integer(rom_col));   

constant xxx: rom_type := (
       "00111100", --   ****
       "01111110", --  ******
       "11111111", -- ********
       "11111111", -- ********
       "11111111", -- ********
       "11111111", -- ********
       "01111110", --  ******
       "00111100"  --   ****
    );

    signal rom_addr, rom_col: unsigned(0 to 2);
    signal rom_bit: std_logic;

    rom_bit <= xxx(to_integer(rom_addr))(to_integer(rom_col)); 

 

Edited by askhunter

Share this post


Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0

For starters you haven't included the definition for type rom_type; that should clear up a lot of your confusion. You don't mention if Vivado synthesizes the code that this snippet is part of. I bet it doesn't since ???????? isn't a valid VHDL statement ( as far as I know ). The problem smells like a quiz question.

Edited by zygot

Share this post


Link to post
Share on other sites
  • 0
2 hours ago, zygot said:

For starters you haven't included the definition for type rom_type; that should clear up a lot of your confusion. You don't mention if Vivado synthesizes the code that this snippet is part of. I bet it doesn't since ???????? isn't a valid VHDL statement ( as far as I know ). The problem smells like a quiz question.

I'm sorry my fault. I erased the question mark.it was just for attention.

type rom_type is array (0 to 7) of std_logic_vector(7 downto 0); -- This is type.

Also this is not a quiz question. 

The following code is quoted from pog chu's book. The code I shared in my first post is a different spelling of pong chu's code and it works. I am wondering how it works. I've never seen such syntax before.

rom_data <= BALL_ROM(to_integer(rom_addr));
rom_bit <= rom_data(to_integer(rom_co1));

 

Share this post


Link to post
Share on other sites
  • 0
14 hours ago, askhunter said:

I've never seen such syntax before

That's probably good. Generally it's a good idea to have a coding style that is understandable to others who are reasonably competent with a language. I've known of people who purposely create obfuscated code in an attempt at job security. Sometimes certain people can't resist demonstrating how clever they (think that) are. Some languages like C are ideal for writing terse code. I've seen beautifully written code that is terse; but it is also informative and not mysterious. I used to subscribe to the C User's Journal (I think that was the name) who held an annual C coding obfuscation contest. The only rule was that a standard compiler wouldn't choke on it. Some of the code was amazing and did things that mortal C programmers like me couldn't decipher from reading it afters a month's effort. While entertaining I wouldn't want to start a job having and having a few thousand lines of it thrown at me to maintain and fix. Badly written, poorly tested, and incorrect code with layers of "band-aid fixes" that only obscure the actual problem is bad enough; even with little or a swamp of incorrect documentation to wade through.

Here's a question for @askhunter: What is a std_logic_vector? Answer that and perhaps you will see the light bulb glow.

[edit] I'm no doubt the king of edited posts to the Digilent forums; I seem be confirming that as I type. My fingers do the walking, to quote an old ad, and my brain isn't so good at catching wandering digits. Anyway, I never make an edit to cover past errors, or add to the confusion of random readers arriving late to the thread progression. I suggest that in this case your removal of the evidence of a crime.. er error is a mistake. Better to have just corrected it after the post pointing it out.

Edited by zygot

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this