Y Khan wrote:
Hi All, Please let me know if this is not the right place to ask this question.
Questions about computer architecture might be better in the comp.arch and related newsgroups.
I had read somewhere that a 32 bit processor can read/write only and only 32 bits in any one cycle. So, I thought that if I needed a 'char' then 32 bits would be read from memory into registers and then would be manipulated there to get a 'char'. As such I thought that it was logical that operations on int are faster than on chars. I was reading an ARM processor manual some time ago and I saw that processor has instructions to read a single byte too. So, I am confused now. I earlier thought that the compiler generates such code that reads in 32 bits and then manipulates those bits to get an 8-bit char value.
No code is generated to do this. You can see this for yourself using gcc -S. The programmer (through the ISA) sees an idealized abstraction of the interactions between the processor and memory. When an instruction says to load a certain sized value from a given location, the processor instructs memory (including caches) to deliver the correct sized value to the specified destination. If this requires multiple memory transfers or shifting is hidden from the programmer for the most part.
Now, ARM processor manual says that the processor can be instructed to read only one byte too. But the processor registers are 32 bits. so, this is again confusing.
What's confusing? When you read a byte from memory, a byte value is placed in the register.
This doesn't look very straightforward to me because if the data bus is 32 bits wide then probably we are still reading 32 bits.
The memory subsystem may transfer data in 8, 16, 32, 64 or even larger chunks. This has to do with the memory bus size, cache line size, etc. Transfers between cache and the processor may be different.
So, the question is: 1. Can only 8 bits be read from memory in a 32 bit register?
RTFM. What does the ARM processor manual say?
2. When a processor gives an instruction to read only 8 bits, then is it manipulating the 32 bits by itself?
There are many manipulations performed on values read from memory, especially when caches are involved.
3. If the address of my 'char' is 0x5, then do we only read the memory location 0x5, or from 0x4 to 0x7, and then manipulate it to get the value at 0x5 in the lowest 8 bits of the 32 bit register.
Yes, no, or maybe, depending on the processor, the memory bus size, the cache line size, whether there is a cache hit or a miss, what operations have been performed before this one and so forth. The interactions between memory and processor can be quite complex, even on simple processors. For example, if you read a char from 0x4, this may cause an 8-byte cache line to be read from memory and then the requested byte is transferred to a register. When you read a char from 0x5, nothing is read from memory. From the idealized view that the programmer sees, a byte is read from the specified location and placed in the register. -- Michael Eager eager@xxxxxxxxxxxx 1960 Park Blvd., Palo Alto, CA 94306 650-325-8077