Memory Usage – How to Update Exactly 1 Byte in RAM

cpumemorymemory usageregister

For example I have a static C++ array {'d', 'o', 'c', 's'}. And I have x86 architecture, with 32-bits length words.

I want to replace letter c with g. As far as I understand, when we make a read operation from a byte addressable RAM, CPU always reads 1 word from it. So it will read the whole array.

After CPU will read the array, I will replace letter c with g and write it back to memory.

Will CPU write 1 bytes or 4 byte in RAM?

If it writes 4 bytes, what's the point of using byte addressable memory instead of word addressable?

UPDATE

Let's consider another example. The CPU uses 32 bits words. We have an array of 4 bytes in RAM. It starts at address 0x000:

0x000: 1110 1111 0000 1100 [1110 1111] 0000 1100 // we want to update byte in brackets
0x003: ....
0x007: ....

Since RAM is byte addressable, each cell contains exactly 1 byte. So, theoretically, we can read or write 1 byte using single memory access. But since computer has 32 bits bus, CPU always reads 32 bits using single memory access.

So as far as I understand CPU reads the whole word into its register:

1110 1111 0000 1100 [1110 1111] 0000 1100

Then it updates 3rd byte in this register (for example with 1000 1111):

1110 1111 0000 1100 [1000 1111] 0000 1100

And I don't understand what’s next.
[Main question] Does CPU write all 32 bits from register to RAM or only 8 bits?

[Answered] If it updates 32 bits, what’s the point of not using word addressable RAM which works exactly the same? According to answers below we still did it because of our past and Sneakernet.

Best Answer

The internet.

When you have multiple computers networked together there is no such thing as "the word size". Every computer has its own idea how big it's bus is. But they all agree on bytes (even if they can't agree on byte order). So we keep making bytes addressable. It helps with compatibility issues. It's a carry over from the days of 8 bit computing when that was the bus size.

The sneaker net.

Even computers that aren't physically connected still share data using removable media. They need some kind of agreement on how big addressable units of memory are. Here we also settled on 8 bit bytes. It's why ASCII and EBCDIC fit in bytes.

These traditional forces are why when bus sizes grow they typically grow into something divisible by 8. It's hard to escape your past.

Is it possible to update exactly 1 byte in RAM?

Yes.

It has to be. It's just a question of how that's done. Exactly how it's done is architecture dependant.

Typically the bus itself is "byte addressable". So just because I've sent you more bytes than you need doesn't mean you have to use them all.

I've found a good explanation of that here.