32bit address generation using command parsing

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

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

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

Who is Participating?
CmdrRickHunterConnect With a Mentor Commented:
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".
printf "0x%08x\n",$_ for(0..63);
brundavaniAuthor Commented:
Dear ozo,
             can you please write more clearly.Your help will be appreciated.

Thank you.
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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?
and what does BL and DW have to do with anything?  I didn't see them factoring in anywhere.
brundavaniAuthor Commented:
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,
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
brundavaniAuthor Commented:
Thank you very much.
What errors do you get running
printf "0x%08x\n",$_ for(0..63);
brundavaniAuthor Commented:
Errors I found are synrax and compilation errors.

Scalar found where operator expected at D:\Perl\eg\ex6.pl line 1, near ""0x%08x\
        (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.

Did you forget the comma between the ending quote and the dollar sign?
brundavaniAuthor Commented:
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

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

There should be a space between the $_ and the for
brundavaniAuthor Commented:
Thank you so much.It works now.
I still sugest changing the "accepted" answer from mine to ozo's, as his solution is what actually worked.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.