Skip to content

Instantly share code, notes, and snippets.

@nokute78
Created December 21, 2016 14:49
Show Gist options
  • Save nokute78/993f8c647dcf6bef8e9feeda66af12c4 to your computer and use it in GitHub Desktop.
Save nokute78/993f8c647dcf6bef8e9feeda66af12c4 to your computer and use it in GitHub Desktop.
initializing at head of function or at some cases.
# OS
Raspbian on Raspberry Pi 2
# gcc
$ gcc --version
gcc (Debian 4.6.3-14+rpi1) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ gcc init_char.c
# objdump
$ objdump --version
GNU objdump (GNU Binutils for Debian) 2.24.51.20140425
Copyright (C) 2014 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) any later version.
This program has absolutely no warranty.
#include <stdio.h>
int init_at_case1(int type)
{
switch(type){
case 0:
printf("nothing to do\n");
break;
case 1:
{
char buf[32] = {0};
snprintf(buf, sizeof(buf)-1, "%d", 123);
printf("%s\n",buf);
}
break;
default:
printf("default\n");
}
return 0;
}
int init_everytime(int type)
{
char buf[32] = {0};
switch(type){
case 0:
printf("nothing to do\n");
break;
case 1:
{
snprintf(buf, sizeof(buf)-1, "%d", 123);
printf("%s\n",buf);
}
break;
default:
printf("default\n");
}
return 0;
}
int main(void)
{
int i;
for(i=0; i<3; i++){
init_at_case1(i);
init_everytime(i);
}
return 0;
}
00008400 <init_at_case1>:
8400: e92d4800 push {fp, lr}
8404: e28db004 add fp, sp, #4
8408: e24dd028 sub sp, sp, #40 ; 0x28
840c: e50b0028 str r0, [fp, #-40] ; 0x28
8410: e51b3028 ldr r3, [fp, #-40] ; 0x28
8414: e3530000 cmp r3, #0
8418: 0a000002 beq 8428 <init_at_case1+0x28>
841c: e3530001 cmp r3, #1
8420: 0a000003 beq 8434 <init_at_case1+0x34>
8424: ea000026 b 84c4 <init_at_case1+0xc4>
8428: e59f00ac ldr r0, [pc, #172] ; 84dc <init_at_case1+0xdc>
842c: ebffffb9 bl 8318 <puts@plt>
8430: ea000025 b 84cc <init_at_case1+0xcc>
8434: e24b3024 sub r3, fp, #36 ; 0x24
8438: e3a02000 mov r2, #0
843c: e5832000 str r2, [r3]
8440: e2833004 add r3, r3, #4
8444: e3a02000 mov r2, #0
8448: e5832000 str r2, [r3]
844c: e2833004 add r3, r3, #4
8450: e3a02000 mov r2, #0
8454: e5832000 str r2, [r3]
8458: e2833004 add r3, r3, #4
845c: e3a02000 mov r2, #0
8460: e5832000 str r2, [r3]
8464: e2833004 add r3, r3, #4
8468: e3a02000 mov r2, #0
846c: e5832000 str r2, [r3]
8470: e2833004 add r3, r3, #4
8474: e3a02000 mov r2, #0
8478: e5832000 str r2, [r3]
847c: e2833004 add r3, r3, #4
8480: e3a02000 mov r2, #0
8484: e5832000 str r2, [r3]
8488: e2833004 add r3, r3, #4
848c: e3a02000 mov r2, #0
8490: e5832000 str r2, [r3]
8494: e2833004 add r3, r3, #4
8498: e59f3040 ldr r3, [pc, #64] ; 84e0 <init_at_case1+0xe0>
849c: e24b2024 sub r2, fp, #36 ; 0x24
84a0: e1a00002 mov r0, r2
84a4: e3a0101f mov r1, #31
84a8: e1a02003 mov r2, r3
84ac: e3a0307b mov r3, #123 ; 0x7b
84b0: ebffffa1 bl 833c <snprintf@plt>
84b4: e24b3024 sub r3, fp, #36 ; 0x24
84b8: e1a00003 mov r0, r3
84bc: ebffff95 bl 8318 <puts@plt>
84c0: ea000001 b 84cc <init_at_case1+0xcc>
84c4: e59f0018 ldr r0, [pc, #24] ; 84e4 <init_at_case1+0xe4>
84c8: ebffff92 bl 8318 <puts@plt>
84cc: e3a03000 mov r3, #0
84d0: e1a00003 mov r0, r3
84d4: e24bd004 sub sp, fp, #4
84d8: e8bd8800 pop {fp, pc}
84dc: 00008690 .word 0x00008690
84e0: 000086a0 .word 0x000086a0
84e4: 000086a4 .word 0x000086a4
000084e8 <init_everytime>:
84e8: e92d4800 push {fp, lr}
84ec: e28db004 add fp, sp, #4
84f0: e24dd028 sub sp, sp, #40 ; 0x28
84f4: e50b0028 str r0, [fp, #-40] ; 0x28
84f8: e24b3024 sub r3, fp, #36 ; 0x24
84fc: e3a02000 mov r2, #0
8500: e5832000 str r2, [r3]
8504: e2833004 add r3, r3, #4
8508: e3a02000 mov r2, #0
850c: e5832000 str r2, [r3]
8510: e2833004 add r3, r3, #4
8514: e3a02000 mov r2, #0
8518: e5832000 str r2, [r3]
851c: e2833004 add r3, r3, #4
8520: e3a02000 mov r2, #0
8524: e5832000 str r2, [r3]
8528: e2833004 add r3, r3, #4
852c: e3a02000 mov r2, #0
8530: e5832000 str r2, [r3]
8534: e2833004 add r3, r3, #4
8538: e3a02000 mov r2, #0
853c: e5832000 str r2, [r3]
8540: e2833004 add r3, r3, #4
8544: e3a02000 mov r2, #0
8548: e5832000 str r2, [r3]
854c: e2833004 add r3, r3, #4
8550: e3a02000 mov r2, #0
8554: e5832000 str r2, [r3]
8558: e2833004 add r3, r3, #4
855c: e51b3028 ldr r3, [fp, #-40] ; 0x28
8560: e3530000 cmp r3, #0
8564: 0a000002 beq 8574 <init_everytime+0x8c>
8568: e3530001 cmp r3, #1
856c: 0a000003 beq 8580 <init_everytime+0x98>
8570: ea00000d b 85ac <init_everytime+0xc4>
8574: e59f0048 ldr r0, [pc, #72] ; 85c4 <init_everytime+0xdc>
8578: ebffff66 bl 8318 <puts@plt>
857c: ea00000c b 85b4 <init_everytime+0xcc>
8580: e59f3040 ldr r3, [pc, #64] ; 85c8 <init_everytime+0xe0>
8584: e24b2024 sub r2, fp, #36 ; 0x24
8588: e1a00002 mov r0, r2
858c: e3a0101f mov r1, #31
8590: e1a02003 mov r2, r3
8594: e3a0307b mov r3, #123 ; 0x7b
8598: ebffff67 bl 833c <snprintf@plt>
859c: e24b3024 sub r3, fp, #36 ; 0x24
85a0: e1a00003 mov r0, r3
85a4: ebffff5b bl 8318 <puts@plt>
85a8: ea000001 b 85b4 <init_everytime+0xcc>
85ac: e59f0018 ldr r0, [pc, #24] ; 85cc <init_everytime+0xe4>
85b0: ebffff58 bl 8318 <puts@plt>
85b4: e3a03000 mov r3, #0
85b8: e1a00003 mov r0, r3
85bc: e24bd004 sub sp, fp, #4
85c0: e8bd8800 pop {fp, pc}
85c4: 00008690 .word 0x00008690
85c8: 000086a0 .word 0x000086a0
85cc: 000086a4 .word 0x000086a4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment