Why misaligned address access incur 2 or more accesses?

前端 未结 4 1609
野性不改
野性不改 2020-12-10 08:47

The normal answers to why data alignment is to access more efficiently and to simplify the design of CPU.

A relevant question and its answers is here. And another s

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-10 09:39

    Addressing 4 bytes with the first byte misaligned at the left at 0x1 not 0x0 means it does not start on a word boundary and spills over to the next adjacent word. First access grabs the 3 bytes to word boundary (assuming a 32-bit word) and then second access grabs byte 0x4 in the mode of completing the 4-byte 32-bit word of the memory addressing implementation. The object code or assembler effectively does the second access and concatenation for the programmer transparently. Its best to keep to word boundaries when possible usually in units of 4 bytes.

提交回复
热议问题