Solved

32bit address generation using command parsing

Posted on 2004-09-26
15
261 Views
Last Modified: 2010-05-18
Hi ,I am very new to PERL.And,I need to write a program to generate a 32 bit number for the below input parameters.I will appreciate your help.

Write a Perl program to generate an number Addr(32-bit address) for the given
input parameters.
Input Arguments--> BL ( Burst Length).
Input Arguments--> DW ( Data Bus Width).

The output file format is described below.
Output file ---> Addr(32-bit hex).

Assumptions:
Lets assume that the BL = 8 and DW = 64(fixed for now).

So the perl program should take BL and DW as inputs and generate
a address sequence like below.

Addr  = { Bank, Row, Col, Byte}

Bank, Row, Col, Byte are local to the perl pogram.The final Addr is packed with these
local variables.The idea is to play with the local variables and generate the final Addr.

Bank ---> ranges from {0...7} decimal numbers(3 bits in binary)
Row  ---> ranges from {0....16383} decimal numbers(14 bits in binary).
Col  ---> ranges from {0....1023} decimal numbers(10 bits in binary).
Byte ---> ranges from {1.....8}   decimal numbers(3 bits in binary).


Lets clamp Bank and Row to be always 0 for now.
Since the Bank and Row are always 0, so the higher order bits(14 to 31) are always 0.
The only remaining are Col and Byte.

Generate the below sequence using the col and Byte.

(a) Byte  ----Start at decimal 1 and increment upto 8(8 inclusive).
    Col   ----Initially for the first time Keep the col to 0.
    So the final Hex addr looks like 0x0000001
                                     0x0000002
                                     0x0000003.......0x00000008
                                         

(b) Now Increment the col by 1 and repeat (a).
   
(c) Do it upto col value  8.

In essence start from col value 0 and increment byte from 1 to 8 values.
Increment col value by 1 and repeat the byte increment starting from 1 to 8 values again.
Stop when col value 8.Effectively you should have 64 hex addresses in
the output file.

Write the output file in hex.

0
Comment
Question by:brundavani
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 4
15 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 12154804
printf "0x%08x\n",$_ for(0..63);
0
 

Author Comment

by:brundavani
ID: 12155168
Dear ozo,
             can you please write more clearly.Your help will be appreciated.

Thank you.
0
 
LVL 84

Expert Comment

by:ozo
ID: 12155197
What is unclear about it?
The perl interpreter understands  that statement precisely.
I'm actually unclear about exactly what your question is
so I proposed a solution to the closest question I could understand.
If that does not answer the question you intended to ask,
could you explain why?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Accepted Solution

by:
CmdrRickHunter earned 500 total points
ID: 12156761
when you say write "in hex" do you mean you want the text "0x0A53FC...etc" to appear in a text file, or do you want to create a binary file whose first character is character 10(0x0A), second is 83 (0x53), third is 252 (0xFC), etc.  The former is just a straightforward printf, as ozo wrote.  The latter involves using "pack".

And in ozo's defence... for an experianced perl programmer the code he wrote makes perfect sense.  Unfortunatly perl has a habit of making really obsfucated code.  It is possible to write a perl script one day, optimize it in the evening... wake up in the morning and scratch your head wondering "how the heck does this even work".
0
 
LVL 3

Expert Comment

by:CmdrRickHunter
ID: 12156767
and what does BL and DW have to do with anything?  I didn't see them factoring in anywhere.
0
 

Author Comment

by:brundavani
ID: 12159518
Dear Sir/Madam,
                        Thank you so much for your response.I just started learning PERL.So,I am still in learning stage of commands.
Aim is to generate 32-bit hex output (ADDR)in the format 0x0A53FC...etc.
This ADDR should contain { Bank, Row, Col, Byte}
which are 3,16384,1024 and 8 widths respectively. Byte is LSB.
I want to concatenate Bank, Row, Col, Byte to get ADDR(output).
It is so nice of experienced people like you and CmdrRickHunter to respond my question.I will be grateful to you if you can explain me the command.I tried to run the command printf "0x%08x\n",$_ for(0..63);
But,getting errors.Please help me.I have started learnig PERL.So,in my next question,I promise ,I wont trouble you this much.

Thank you for your time and patience,
Brundavani
0
 
LVL 3

Expert Comment

by:CmdrRickHunter
ID: 12160322
I think you misplaced the answer.  Ozo got the answer right, I just asked some questions to get a better idea of what you were exactl trying to do.  He got the answer without asking questions, so should get the points
0
 

Author Comment

by:brundavani
ID: 12160422
Thank you very much.
0
 
LVL 84

Expert Comment

by:ozo
ID: 12165529
What errors do you get running
printf "0x%08x\n",$_ for(0..63);
?
0
 

Author Comment

by:brundavani
ID: 12168438
Errors I found are synrax and compilation errors.


Scalar found where operator expected at D:\Perl\eg\ex6.pl line 1, near ""0x%08x\
n"$_for"
        (Missing operator before $_for?)
syntax error at D:\Perl\eg\ex6.pl line 1, near ""0x%08x\n"$_for"
Execution of D:\Perl\eg\ex6.pl aborted due to compilation errors.


0
 
LVL 3

Expert Comment

by:CmdrRickHunter
ID: 12169064
Did you forget the comma between the ending quote and the dollar sign?
0
 

Author Comment

by:brundavani
ID: 12171120
Yes,you are right.I forgot the comma.But,even after I put the comma,I am getting the following errors.It is so hard for an experienced programmer like you guys to comedown to my level and answer my doubts.I really appreciate your help guys.

D:\Perl\eg>type ex6.pl
printf"0x%08x\n",$_for(0..63);

D:\Perl\eg>ex6.pl
syntax error at D:\Perl\eg\ex6.pl line 1, near "$_for("
Execution of D:\Perl\eg\ex6.pl aborted due to compilation errors.


0
 
LVL 84

Expert Comment

by:ozo
ID: 12174110
There should be a space between the $_ and the for
0
 

Author Comment

by:brundavani
ID: 12174685
Thank you so much.It works now.
0
 
LVL 3

Expert Comment

by:CmdrRickHunter
ID: 12176601
I still sugest changing the "accepted" answer from mine to ozo's, as his solution is what actually worked.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Reading fields from the text file. 4 106
Search in text file in column and compare 4 75
Regular Expression question to filter with negation. 6 108
Merging two files with Perl 5 56
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question