So I'm not sure if this belongs in the longue, but it does pertain to programming and potentially to C++(maybe depending on the compiler?)
I'm currently reading William Stallings's Computer Architecture and Organisation. After just finishing reading Charles Petzold's code second edition, I have a better understanding of what's happening under the hood.
Since Charles's book walks us through the Intel 8080, a rather primitive CPU compared to today's beasts. Well, enough preamble.
A word in computer science pertains to the size of the registers and data a CPU can process(and obviously the data lines too). 64-bit processors to my knowledge have 64-bit registers and a 64-bit data bus from memory to processor; although it could be a lot more? I would imagine maybe it's more as the CPU contains a cache, but for the sake of this post, let's assume the amount of data fetched is 8 bytes or 64 bits.
There can be multi-byte fetch instructions on the intel 8080. For example, one instruction may have one operand such as move immediate(MVI A,23), one fetch for the opcode and one fetch for the byte to move to register A. Once each respective fetch has finished, the program counter will be incremented. This is quite simple for this processor as not only is memory byte addressable(still is) , but the word size is also 8 bits/1 byte. So each fetch will increment the program counter by 1. Now with a 64 bit machine it gets a little bit murky.
With a 64 bit machine, let's assume a word is 64 bits and as stated the memory still only stores one byte each. It would make sense to fetch all 64 bits from memory i.e. acesses 8 bytes of storage then increment the program counter by 8 bytes, I'm guessing this is done??
But, what happens if we have a program, really simple program such as
double a = 3.14 // store 8 bytes in memory
uint8_t b = 120; // store 1 byte in memory
cout << a << endl ;// read 8 bytes from memory, perhaps place it in register and let sysout display 3.14
cout << b << endl; // read 1 byte from memory, perhaps place it in a register and let sysout display 120
If we read 8 bytes from memory we can display our double a, but next, we read 1 byte from memory to display uint8_t b. Each memory fetch is expensive(let's assume it's not cached). If we read 1 byte from memory and place it in the LSB of a register isn't that a waste of a memory fetch, considering we only retrieve one byte?
I also remember there is a #pragma align if I can remember correctly which aligns memory, I'm guessing this is in some way related?