Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How a single byte of memory is accessed by CPU in a 32-bit memory and 32-bit processor

I quite understand a what 32 or 64 bit system means. so basically all registers or word length is either 32 or 64 bit.

For simplicity let us take a 32 bit system and say i'am writing a program in C. if i declare a int type say "int a = 5;" then a memory location of one word length is reserved for var a. so when ever i want to access it i can do so using word address for that memory location.

But say i have 4 characters " char a,b,c,d;" since it is one byte each all of them are placed in one word, so what do i do if i want to access only char b?(saying the memory is byte addressable) now say b is the third byte in the word....then how does it come on to the bus? is'nt the 3rd byte hard wired to 17th to 24th line in the bus? so what happens to the other 24 lines when only b is being accessed?

like image 519
deepak Avatar asked Sep 18 '12 15:09

deepak


People also ask

How many bytes can a 32-bit computer access?

One bit in the register can reference an individual byte in memory, so a 32-bit system can address a maximum of 4 GB (4,294,967,296 bytes) of RAM. The actual limit is often less than around 3.5 GB since part of the register is used to store other temporary values besides memory addresses.

How much memory can be directly referenced on systems with 32-bit addressing?

A 32-bit register can store 232 different values. The signed range of integer values that can be stored in 32 bits is -2,147,483,648 through 2,147,483,647 (unsigned: 0 through 4,294,967,295). Hence, a processor with 32-bit memory addresses can directly access 4 GiB of byte-addressable memory.

What provide 32-bit path to the processor?

A SIMM (single in-line memory module) typically has a 32 data bit (36 bits counting parity bits) path to the computer that requires a 72-pin connector.

When a 32-bit CPU and a 64-bit CPU are compared a 64-bit CPU has a larger theoretical maximum memory space?

Another big difference between 32-bit processors and 64-bit processors is the maximum amount of memory (RAM) that is supported. 32-bit computers support a maximum of 4 GB (232 bytes) of memory, whereas 64-bit CPUs can address a theoretical maximum of 18 EB (264 bytes).


2 Answers

The answer to your question largely depends on which compiler you use and the internal workings of your CPU, memory controller and memory architecture (cache and external memory).
You only have control over the compiler (assuming you are using C or C++ compiler). Compilers have different modes for cases when you are using variables which are smaller than a word size. There are flags for speed optimization and memory optimization. Depending on which of those flags are turned on, the compiler may choose to generate code which packs all four variables (in your case) into one word. Or the compiler may choose to allocate a memory word for each of the variables but use a particular byte to store the actual value. The way the compiler will do it for each of the cases is to generate different set of instructions for the CPU. In the latter case, if the variable is read from memory then the entire word is put on the bus and then into a general purpose register. In the former case, the word is put in the register but then the word can get shifted bit wise and the other bits can be zeroed out by using logic AND operation. That way the right byte is going to be in the register. Or may be the CPU architecture supports byte level access in a word in which case it will be only one operation performed by the CPU. In the end, it is a good idea to understand what happens inside but you will not care much because the set of instructions generated by the compiler will work correctly from your standpoint. The only time you will care is when you write performance sensitive software. In that case you will need to know the details of your CPU and memory as well as the flags supported by the compiler.

like image 69
shargors Avatar answered Oct 03 '22 07:10

shargors


It depends on the assembler, it may choose to give one word of memory or a byte.
So now even if you have 4 different characters in the word, what would happen is all of them are accessed at once, but only the one you require is operated on. i.e. all of them come into the processor from the memory, then only the byte you want is considered, the others are rejected.

like image 22
user2050939 Avatar answered Oct 03 '22 07:10

user2050939