概述
/*
typedef struct
{
_u8 a;
_u32 b;
_u8 c;
_u16 d;
_u32 e;
float f;
}test_t;
static test_t tmp_struct;
tmp_struct.a = 1;
tmp_struct.b = 2;
tmp_struct.c = 3;
tmp_struct.d = 4;
tmp_struct.e = 5;
tmp_struct.f = 1.2;
通过汇编取指访问结构体成员变量得知:结构体中的a占用4字节,b占用4字节,c占用2字节,d占用2字节,e占用4字节
*/
汇编:
80027c4: b580 push {r7, lr}
80027c6: 480c ldr r0, [pc, #48] ; (80027f8 <.text_4>)
80027c8: 2101 movs r1, #1
80027ca: 7001 strb r1, [r0, #0]
80027cc: 2102 movs r1, #2
80027ce: 6041 str r1, [r0, #4]
80027d0: 2103 movs r1, #3
80027d2: 7201 strb r1, [r0, #8]
80027d4: 2104 movs r1, #4
80027d6: 8141 strh r1, [r0, #10]
80027d8: 2105 movs r1, #5
80027da: 60c1 str r1, [r0, #12]
80027dc: 4907 ldr r1, [pc, #28] ; (80027fc <.text_5>),浮点数存放位置
80027de: 6101 str r1, [r0, #16]
80027e0: f7fd fe8f bl 8000502 <func1_test>
80027e4: f7ff fef7 bl 80025d6 <func2_test>
80027e8: f7fe fdd0 bl 800138c <func3_test>
80027ec: f000 f838 bl 8002860 <func4_test>
80027f0: f000 f84b bl 800288a <func5_test>
80027f4: 2001 movs r0, #1
80027f6: bd02 pop {r1, pc}
080027f8 <.text_4>:
80027f8: 200010a8 .word 0x200010a8
080027fc <.text_5>:
80027fc: 3f8ccccd .word 0x3f8ccccd
/*
typedef struct
{
_u32 a;
_u8 b;
_u8 c;
_u8 d;
_u16 e;
float f;
}test_t;
static test_t tmp_struct;
tmp_struct.a = 1;
tmp_struct.b = 2;
tmp_struct.c = 3;
tmp_struct.d = 4;
tmp_struct.e = 5;
tmp_struct.f = 2.1;
通过汇编取指访问结构体成员变量得知:结构体中的a占用4字节,b占用1字节,c占用1字节,d占用2字节,e占用4字节
*/
汇编:
80027c4: b580 push {r7, lr}
80027c6: 480c ldr r0, [pc, #48] ; (80027f8 <.text_4>)
80027c8: 2101 movs r1, #1
80027ca: 6001 str r1, [r0, #0]
80027cc: 2102 movs r1, #2
80027ce: 7101 strb r1, [r0, #4]
80027d0: 2103 movs r1, #3
80027d2: 7141 strb r1, [r0, #5]
80027d4: 2104 movs r1, #4
80027d6: 7181 strb r1, [r0, #6]
80027d8: 2105 movs r1, #5
80027da: 8101 strh r1, [r0, #8]
80027dc: 4907 ldr r1, [pc, #28] ; (80027fc <.text_5>) 浮点数存放位置
80027de: 60c1 str r1, [r0, #12]
80027e0: f7fd fe8f bl 8000502 <func1_test>
80027e4: f7ff fef7 bl 80025d6 <func2_test>
80027e8: f7fe fdd0 bl 800138c <func3_test>
80027ec: f000 f838 bl 8002860 <func4_test>
80027f0: f000 f84b bl 800288a <func5_test>
80027f4: 2001 movs r0, #1
80027f6: bd02 pop {r1, pc}
080027f8 <.text_4>:
80027f8: 200010dc .word 0x200010dc
080027fc <.text_5>:
80027fc: 40066666 .word 0x40066666
/*
typedef __packed struct
{
_u8 a;
_u32 b;
_u8 c;
_u16 d;
_u32 e;
float f;
}test_t;
static test_t tmp_struct;
tmp_struct.a = 1;
tmp_struct.b = 2;
tmp_struct.c = 3;
tmp_struct.d = 4;
tmp_struct.e = 5;
tmp_struct.f = 2.1;
通过汇编取指访问结构体成员变量得知:结构体中的a占用1字节,b占用4字节,c占用1字节,d占用2字节,e占用4字节
*/
汇编:
80027c4: b580 push {r7, lr}
80027c6: 480d ldr r0, [pc, #52] ; (80027fc <.text_4>)
80027c8: 2101 movs r1, #1
80027ca: 7001 strb r1, [r0, #0]
80027cc: 2102 movs r1, #2
80027ce: f8c0 1001 str.w r1, [r0, #1]
80027d2: 2103 movs r1, #3
80027d4: 7141 strb r1, [r0, #5]
80027d6: 2104 movs r1, #4
80027d8: 80c1 strh r1, [r0, #6]
80027da: 2105 movs r1, #5
80027dc: 6081 str r1, [r0, #8]
80027de: 4908 ldr r1, [pc, #32] ; (8002800 <.text_5>) 浮点数存放位置
80027e0: 60c1 str r1, [r0, #12]
80027e2: f7fd fe8e bl 8000502 <func1_test>
80027e6: f7ff fef6 bl 80025d6 <func2_test>
80027ea: f7fe fdcf bl 800138c <func3_test>
80027ee: f000 f839 bl 8002864 <func4_test>
80027f2: f000 f84c bl 800288e <func5_test>
80027f6: 2001 movs r0, #1
80027f8: bd02 pop {r1, pc}
...
080027fc <.text_4>:
80027fc: 200010dc .word 0x200010dc
08002800 <.text_5>:
8002800: 40066666 .word 0x40066666
/*
typedef __packed struct
{
_u32 a;
_u8 b;
_u8 c;
_u8 d;
_u32 e;
float f;
}test_t;
static test_t tmp_struct;
tmp_struct.a = 1;
tmp_struct.b = 2;
tmp_struct.c = 3;
tmp_struct.d = 4;
tmp_struct.e = 5;
tmp_struct.f = 2.1;
通过汇编取指访问结构体成员变量得知:结构体中的a占用4字节,b占用1字节,c占用1字节,d占用1字节,e占用4字节
*/
汇编:
80027c4: b580 push {r7, lr}
80027c6: 480d ldr r0, [pc, #52] ; (80027fc <.text_4>)
80027c8: 2101 movs r1, #1
80027ca: 6001 str r1, [r0, #0]
80027cc: 2102 movs r1, #2
80027ce: 7101 strb r1, [r0, #4]
80027d0: 2103 movs r1, #3
80027d2: 7141 strb r1, [r0, #5]
80027d4: 2104 movs r1, #4
80027d6: 7181 strb r1, [r0, #6]
80027d8: 2105 movs r1, #5
80027da: f8c0 1007 str.w r1, [r0, #7]
80027de: 4908 ldr r1, [pc, #32] ; (8002800 <.text_5>) 浮点数存放位置
80027e0: f8c0 100b str.w r1, [r0, #11]
80027e4: f7fd fe8d bl 8000502 <func1_test>
80027e8: f7ff fef5 bl 80025d6 <func2_test>
80027ec: f7fe fdce bl 800138c <func3_test>
80027f0: f000 f838 bl 8002864 <func4_test>
80027f4: f000 f84b bl 800288e <func5_test>
80027f8: 2001 movs r0, #1
80027fa: bd02 pop {r1, pc}
080027fc <.text_4>:
80027fc: 200010dc .word 0x200010dc
08002800 <.text_5>:
8002800: 40066666 .word 0x40066666
/*typedef __packed struct
{
_u32 a;
_u8 b;
_u8 c;
_u8 d;
_u16 e;
float f;
}test_t;
static test_t tmp_struct;
tmp_struct.a = 1;
tmp_struct.b = 2;
tmp_struct.c = 3;
tmp_struct.d = 4;
tmp_struct.e = 5;
tmp_struct.f = 2.1;
通过汇编取指访问结构体成员变量得知:结构体中的a占用4字节,b占用1字节,c占用1字节,d占用1字节,e占用2字节
*/
汇编:
80027c4: b580 push {r7, lr}
80027c6: 480d ldr r0, [pc, #52] ; (80027fc <.text_4>)
80027c8: 2101 movs r1, #1
80027ca: 6001 str r1, [r0, #0]
80027cc: 2102 movs r1, #2
80027ce: 7101 strb r1, [r0, #4]
80027d0: 2103 movs r1, #3
80027d2: 7141 strb r1, [r0, #5]
80027d4: 2104 movs r1, #4
80027d6: 7181 strb r1, [r0, #6]
80027d8: 2105 movs r1, #5
80027da: f8a0 1007 strh.w r1, [r0, #7]
80027de: 4908 ldr r1, [pc, #32] ; (8002800 <.text_5>) 浮点数存放位置
80027e0: f8c0 1009 str.w r1, [r0, #9]
80027e4: f7fd fe8d bl 8000502 <func1_test>
80027e8: f7ff fef5 bl 80025d6 <func2_test>
80027ec: f7fe fdce bl 800138c <func3_test>
80027f0: f000 f838 bl 8002864 <func4_test>
80027f4: f000 f84b bl 800288e <func5_test>
80027f8: 2001 movs r0, #1
80027fa: bd02 pop {r1, pc}
080027fc <.text_4>:
80027fc: 200010dc .word 0x200010dc
08002800 <.text_5>:
8002800: 40066666 .word 0x40066666
/*
#pragma pack(1)
typedef struct
{
_u32 a;
_u8 b;
_u8 c;
_u8 d;
_u16 e;
float f;
}__attribute__((packed)) test_t;
#pragma pack()
static test_t tmp_struct;
tmp_struct.a = 1;
tmp_struct.b = 2;
tmp_struct.c = 3;
tmp_struct.d = 4;
tmp_struct.e = 5;
tmp_struct.f = 2.1;
通过汇编取指访问结构体成员变量得知:结构体中的a占用4字节,b占用1字节,c占用1字节,d占用1字节,e占用2字节
*/
汇编:
80027c4: b580 push {r7, lr}
80027c6: 480d ldr r0, [pc, #52] ; (80027fc <.text_4>)
80027c8: 2101 movs r1, #1
80027ca: 6001 str r1, [r0, #0]
80027cc: 2102 movs r1, #2
80027ce: 7101 strb r1, [r0, #4]
80027d0: 2103 movs r1, #3
80027d2: 7141 strb r1, [r0, #5]
80027d4: 2104 movs r1, #4
80027d6: 7181 strb r1, [r0, #6]
80027d8: 2105 movs r1, #5
80027da: f8a0 1007 strh.w r1, [r0, #7]
80027de: 4908 ldr r1, [pc, #32] ; (8002800 <.text_5>) 浮点数存放位置
80027e0: f8c0 1009 str.w r1, [r0, #9]
80027e4: f7fd fe8d bl 8000502 <func1_test>
80027e8: f7ff fef5 bl 80025d6 <func2_test>
80027ec: f7fe fdce bl 800138c <func3_test>
80027f0: f000 f838 bl 8002864 <func4_test>
80027f4: f000 f84b bl 800288e <func5_test>
80027f8: 2001 movs r0, #1
80027fa: bd02 pop {r1, pc}
080027fc <.text_4>:
80027fc: 200010dc .word 0x200010dc
08002800 <.text_5>:
8002800: 40066666 .word 0x40066666
/*
//#pragma pack(1)
typedef struct
{
_u32 a;
_u8 b;
_u8 c;
_u8 d;
_u16 e;
float f;
_u64 g;
_u8 h;
double i;
}__attribute__((packed)) test_t;
//#pragma pack()
static test_t tmp_struct;
tmp_struct.a = 1;
tmp_struct.b = 2;
tmp_struct.c = 3;
tmp_struct.d = 4;
tmp_struct.e = 5;
tmp_struct.f = 2.1;
tmp_struct.g = 3;
tmp_struct.h = 2;
tmp_struct.i = 3.3;
通过汇编取指访问结构体成员变量得知:结构体中的a占用4字节,b占用1字节,c占用1字节,d占用1字节,e占用4字节,f占用4字节,g占用8字节,h占用8字节
*/
汇编:
80027c4: b580 push {r7, lr}
80027c6: 4812 ldr r0, [pc, #72] ; (8002810 <.text_4>)
80027c8: 2101 movs r1, #1
80027ca: 6001 str r1, [r0, #0]
80027cc: 2203 movs r2, #3
80027ce: 2102 movs r1, #2
80027d0: 7101 strb r1, [r0, #4]
80027d2: 2300 movs r3, #0
80027d4: 2103 movs r1, #3
80027d6: 7141 strb r1, [r0, #5]
80027d8: 2104 movs r1, #4
80027da: 7181 strb r1, [r0, #6]
80027dc: e9c0 2304 strd r2, r3, [r0, #16] //?????似乎是CPU的乱序执行!!!
80027e0: 2105 movs r1, #5
80027e2: 8101 strh r1, [r0, #8]
80027e4: f04f 3266 mov.w r2, #1717986918 ; 0x66666666
80027e8: 490a ldr r1, [pc, #40] ; (8002814 <.text_5>) 浮点数存放位置
80027ea: 4b0b ldr r3, [pc, #44] ; (8002818 <.text_6>) 浮点数存放位置
80027ec: 60c1 str r1, [r0, #12]
80027ee: e9c0 2308 strd r2, r3, [r0, #32]
80027f2: 2102 movs r1, #2
80027f4: 7601 strb r1, [r0, #24]
80027f6: f7fd fe84 bl 8000502 <func1_test>
80027fa: f7ff feec bl 80025d6 <func2_test>
80027fe: f7fe fdc5 bl 800138c <func3_test>
8002802: f000 f83b bl 800287c <func4_test>
8002806: f000 f84e bl 80028a6 <func5_test>
800280a: 2001 movs r0, #1
800280c: bd02 pop {r1, pc}
...
08002810 <.text_4>:
8002810: 20001090 .word 0x20001090
08002814 <.text_5>:
8002814: 40066666 .word 0x40066666
08002818 <.text_6>:
8002818: 400a6666 .word 0x400a6666
最后
以上就是纯真花瓣为你收集整理的STM32 IAR 结构体定义占用空间的全部内容,希望文章能够帮你解决STM32 IAR 结构体定义占用空间所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复