Use the following statement :
c program: Int.c
c program: ConstInt.c
g++ filename.c -S
org++ filename.cpp -S
example 1:c program: Int.c
#include
int main()
{
int a =10;
int *p = (int *)&a;
*p = *p + 1;
printf("Value at pointer p = %9d\nValue of a = %9d\n",*p, a);
printf("Value of pointer p = %9u\nAddress of a = %9u\n",(unsigned int)p,(unsigned int)&a);
return 0;
}
statement executed at the terminal:int main()
{
int a =10;
int *p = (int *)&a;
*p = *p + 1;
printf("Value at pointer p = %9d\nValue of a = %9d\n",*p, a);
printf("Value of pointer p = %9u\nAddress of a = %9u\n",(unsigned int)p,(unsigned int)&a);
return 0;
}
g++ Int.c -S
Output Assembly language file: Int.s .file "Int.c"
.section .rodata
.align 4
.LC0:
.string "Value at pointer p = %9d\nValue of a = %9d\n"
.align 4
.LC1:
.string "Value of pointer p = %9u\nAddress of a = %9u\n"
.text
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
.cfi_personality 0x0,__gxx_personality_v0
pushl %ebp
.cfi_def_cfa_offset 8
movl %esp, %ebp
.cfi_offset 5, -8
.cfi_def_cfa_register 5
andl $-16, %esp
subl $32, %esp
movl $10, 28(%esp)
leal 28(%esp), %eax
movl %eax, 24(%esp)
movl 24(%esp), %eax
movl (%eax), %eax
leal 1(%eax), %edx
movl 24(%esp), %eax
movl %edx, (%eax)
movl 28(%esp), %edx//extra added line
movl 24(%esp), %eax
movl (%eax), %eax
movl %edx, 8(%esp)//changed statement
movl %eax, 4(%esp)
movl $.LC0, (%esp)
call printf
leal 28(%esp), %edx
movl 24(%esp), %eax
movl %edx, 8(%esp)
movl %eax, 4(%esp)
movl $.LC1, (%esp)
call printf
movl $0, %eax
leave
ret
.cfi_endproc
.LFE0:
.size main, .-main
.ident "GCC: (Ubuntu 4.4.3-4ubuntu5) 4.4.3"
.section .note.GNU-stack,"",@progbits
example 2:c program: ConstInt.c
#include
int main()
{
const int a =10;
int *p = (int *)&a;
*p = *p + 1;
printf("Value at pointer p = %9d\nValue of a = %9d\n",*p, a);
printf("Value of pointer p = %9u\nAddress of a = %9u\n",(unsigned int)p,(unsigned int)&a);
return 0;
}
statement executed at the terminal:int main()
{
const int a =10;
int *p = (int *)&a;
*p = *p + 1;
printf("Value at pointer p = %9d\nValue of a = %9d\n",*p, a);
printf("Value of pointer p = %9u\nAddress of a = %9u\n",(unsigned int)p,(unsigned int)&a);
return 0;
}
g++ ConstInt.c -S
Output Assembly language file: Int.s .file "ConstInt.c"
.section .rodata
.align 4
.LC0:
.string "Value at pointer p = %9d\nValue of a = %9d\n"
.align 4
.LC1:
.string "Value of pointer p = %9u\nAddress of a = %9u\n"
.text
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
.cfi_personality 0x0,__gxx_personality_v0
pushl %ebp
.cfi_def_cfa_offset 8
movl %esp, %ebp
.cfi_offset 5, -8
.cfi_def_cfa_register 5
andl $-16, %esp
subl $32, %esp
movl $10, 28(%esp)
leal 28(%esp), %eax
movl %eax, 24(%esp)
movl 24(%esp), %eax
movl (%eax), %eax
leal 1(%eax), %edx
movl 24(%esp), %eax
movl %edx, (%eax)
movl 24(%esp), %eax
movl (%eax), %eax
movl $10, 8(%esp)//changed statement
movl %eax, 4(%esp)
movl $.LC0, (%esp)
call printf
leal 28(%esp), %edx
movl 24(%esp), %eax
movl %edx, 8(%esp)
movl %eax, 4(%esp)
movl $.LC1, (%esp)
call printf
movl $0, %eax
leave
ret
.cfi_endproc
.LFE0:
.size main, .-main
.ident "GCC: (Ubuntu 4.4.3-4ubuntu5) 4.4.3"
No comments:
Post a Comment