Link to home
Start Free TrialLog in
Avatar of brundavani
brundavani

asked on

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

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.

Avatar of ozo
ozo
Flag of United States of America image

printf "0x%08x\n",$_ for(0..63);
Avatar of brundavani
brundavani

ASKER

Dear ozo,
             can you please write more clearly.Your help will be appreciated.

Thank you.
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?
ASKER CERTIFIED SOLUTION
Avatar of CmdrRickHunter
CmdrRickHunter

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
and what does BL and DW have to do with anything?  I didn't see them factoring in anywhere.
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
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
Thank you very much.
What errors do you get running
printf "0x%08x\n",$_ for(0..63);
?
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.


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


There should be a space between the $_ and the for
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.