struct testStruct{
uint8_t i;
uint32_t j;
uint8_t l;
uint32_t k;
};
memset在Keil下的汇编语句 146: memset(&a, 0, sizeof(struct testStruct));
0x08009176 2000 MOVS r0,#0x00
0x08009178 9002 STR r0,[sp,#0x08]
0x0800917A 9003 STR r0,[sp,#0x0C]
0x0800917C 9004 STR r0,[sp,#0x10]
0x0800917E 9005 STR r0,[sp,#0x14]
148: memset(&a, 0x63, sizeof(struct testStruct));
0x08009176 2263 MOVS r2,#0x63
0x08009178 2110 MOVS r1,#0x10
0x0800917A A806 ADD r0,sp,#0x18
0x0800917C F7F7FD38 BL.W __aeabi_memset (0x08000BF0)
将memset会变为STR语句在这里是4bytes对齐的。
memcpy在Keil下的汇编语句应该是在程序中,有一个memcpy的库文件。
151: memcpy(&b, (void *)&a, a.i);
0x08009196 F89D2018 LDRB r2,[sp,#0x18]
0x0800919A A906 ADD r1,sp,#0x18
0x0800919C A802 ADD r0,sp,#0x08
0x0800919E F7F7FCF5 BL.W __aeabi_memcpy4 (0x08000B8C)
struct testStruct{
uint8_t i;
uint32_t j;
uint8_t l;
uint32_t k;
};
volatile uint32_t t1;
volatile uint8_t t2;
volatile uint8_t p[20];
memset(&a, 0x63, sizeof(struct testStruct));
a.i = sizeof(struct testStruct);
a.j = 0x68;
a.l = 0x14;
a.k = 0x81;
a = a;
memcpy(p, (void*)&a, a.i);
memcpy(&b, (void *)&a, a.i);
volatile struct testStruct a;
struct testStruct b; |