user1585869
user1585869

Reputation: 301

Byte addressed mem and word addressed

What does it mean by word addressed memory and byte addressed memory?

Upvotes: 1

Views: 184

Answers (2)

vk8x10
vk8x10

Reputation: 1

Agree with Tom...in word access memory you can have whole 4 bytes when accessed to memory(like in AHB bus) For this type of memory,if u try to access byte you will get undefined behaviour

Upvotes: 0

Tom Tanner
Tom Tanner

Reputation: 9354

This is normally used in the context of the underlying hardware. Most systems nowadays have byte addressed memory. That is to say, that each byte in the memory can be individually addressed and fetched.

Some systems have word addressed memory, and pointer registers contain the addresses of individual words. Moreover, whenever memory is fetched, a whole word is fetched. If you need a specific byte, the compiler will fetch a word and then arrange to get the required byte out of that.

Note that on a system like that, using reinterpret_cast on a pointer is extremely dangerous, as the implementation will probably (for efficiency) keep pointers to word aligned thing as word pointers, and pointers to byte aligned things as byte pointers. So if your memory looks a bit like this:

 word X  : aa ab ac ed
 word X+1: ba bb bc bd

A pointer to word X will contain X, but a byte pointer to aa will contain X*4

reinterpret_cast<word *>(&aa) will give you a word pointer of X*4 which will be embarrassingly wrong.

On a byte addressed machine, both word and byte pointers will contain X*4, so it is 'safe' (that is to say undefined behavior and confusing) to reinterpret_cast between the two.

Upvotes: 3

Related Questions