LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-18-2004, 01:54 AM   #1
eshwar_ind
Member
 
Registered: Feb 2004
Location: Bangalore
Distribution: Redhat
Posts: 144

Rep: Reputation: 15
about alignment


Hi all!!
Can somebody explain me, Why there is a need for alignment restricted access in processors? I know this is the reason for buserror. I would like to know the reason for its implementation in processors.
thanks in advance
Bye,
Eshwar.
 
Old 10-18-2004, 07:06 AM   #2
Marius2
Member
 
Registered: Jan 2004
Location: Munich
Distribution: SuSE 9.2, 10.2, 10.3, knoppix
Posts: 276

Rep: Reputation: 31
One reason is speed. Imagine the processor data bus and the RAM data bus,
32 bit, directly connected:


Bit 0 - 31

Processor Buffer0 1 2 3

Bus |||||||| |||||||| |||||||| ||||||||

Ram Byte 0 1 2 3

Now what you can see is that you have a direct connection between Processor
ReadIn buffer 0 and Ram byte 0, Proc ReadIn 1... and so on. As a lot of data
in Ram actually is 32 bit, you're fine as long as you keep it aligned modulo 4
it's adress in ram. It's also obvious that if you have some data which consists
of a char (byte) in Ram byte 0 and then a long (32bit) in byte 1-4 then the
processor will need two memory accesses to only read the long. But if you fill
in Ram byte 1-3 with padding (meaningless) bytes and therefore move your
long to byte 4-7, processor will only need one access to read the long in.

That's the basic principle - in reality hw is much more complex, and it is very
much processor dependant.

HTH
 
Old 10-18-2004, 07:06 AM   #3
Marius2
Member
 
Registered: Jan 2004
Location: Munich
Distribution: SuSE 9.2, 10.2, 10.3, knoppix
Posts: 276

Rep: Reputation: 31
Hmmm... sorry all the spaces are cut out.... hope you can read it anyway.
 
Old 10-18-2004, 07:26 AM   #4
eshwar_ind
Member
 
Registered: Feb 2004
Location: Bangalore
Distribution: Redhat
Posts: 144

Original Poster
Rep: Reputation: 15
Hi Thanks for your answer. I have got another doubt In the above example why its not possible to access the address 1 directly( it means just placing 1 on the address bus )? If we are able to do that one we can get 4 bytes directly on to processor buffer with single memory read. Why its not possible?
I hope you understand my question. Could you please clarify my doubt?
 
Old 10-18-2004, 08:20 AM   #5
Marius2
Member
 
Registered: Jan 2004
Location: Munich
Distribution: SuSE 9.2, 10.2, 10.3, knoppix
Posts: 276

Rep: Reputation: 31
Well, actually you can, but since readin buffer 0 is hardwired (by thin wires
on the motherboard) to ram byte 0 (and modulo byte 4,8,12...), all you would
do is fill in readin buffers 0-3. Luckily the hw logic on the motherboard is intelligent enough to notice that you want to fill in 4 bytes from an odd adress, and does just that... by two read accesses.
 
Old 10-18-2004, 08:27 AM   #6
eshwar_ind
Member
 
Registered: Feb 2004
Location: Bangalore
Distribution: Redhat
Posts: 144

Original Poster
Rep: Reputation: 15
Oh now i got it, thank you, thank you very much Mr. Marius.
bye,
Eshwar.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Alignment of text in C pritchardtom Programming 3 11-21-2005 04:06 PM
struct member alignment wmoti Programming 2 10-10-2005 05:24 AM
glabels alignment Spaz17 Linux - Software 1 11-28-2003 01:17 PM
alignment justified in HTML nephilim Programming 1 10-31-2003 07:12 AM
Printer Alignment Looking_Lost Linux - Hardware 2 04-26-2003 08:50 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration