MCU單晶片韌體設計

2018年2月26日 星期一

ARM Alignment



On ARM-based systems you cannot address a 32-bit word that is not aligned to a 4-byte boundary 


LDR r0, = 0x1001
LDR r1, [r0]
The second line in the above code will give hard fault since are trying to read 4 bytes but the memory address is not divisible by 4
If we change the second line in above code to the following
LDRB r1, [r0];//Load 1 byte from address
The above line will not produce a hard fault, since we are trying to access 1 byte(1 byte can be accessed from any memory location)
Also notice the following example;
LDR r0,= 0x1002
LDRH r1,[r0];   //Load half word from 0x1002


References:





沒有留言 :

張貼留言