Skip to content

Instantly share code, notes, and snippets.

Created October 1, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/d404852febf3ecb54bbd to your computer and use it in GitHub Desktop.
Save anonymous/d404852febf3ecb54bbd to your computer and use it in GitHub Desktop.
#include <stdio.h>
int main(int argc, char *argv[]) {
char arr[40] = "this is a string referenced by an array";
printf("arr = %s; sizeof arr = %ld\n", arr, sizeof arr);
return 0;
}
.section __TEXT,__text,regular,pure_instructions
.macosx_version_min 10, 10
.globl _main
_main: ## @main
.cfi_startproc
## BB#0:
pushq %rbp
Ltmp0:
.cfi_def_cfa_offset 16
Ltmp1:
.cfi_offset %rbp, -16
movq %rsp, %rbp
Ltmp2:
.cfi_def_cfa_register %rbp
pushq %rbx
subq $56, %rsp
Ltmp3:
.cfi_offset %rbx, -24
movq ___stack_chk_guard@GOTPCREL(%rip), %rbx
movq (%rbx), %rbx
movq %rbx, -16(%rbp)
movabsq $34165616355123310, %rax ## imm = 0x7961727261206E
movq %rax, -32(%rbp)
movaps L_main.arr+16(%rip), %xmm0
movaps %xmm0, -48(%rbp)
movaps L_main.arr(%rip), %xmm0
movaps %xmm0, -64(%rbp)
leaq L_.str(%rip), %rdi
leaq -64(%rbp), %rsi
movl $40, %edx
xorl %eax, %eax
callq _printf
cmpq -16(%rbp), %rbx
jne LBB0_2
## BB#1:
xorl %eax, %eax
addq $56, %rsp
popq %rbx
popq %rbp
retq
LBB0_2:
callq ___stack_chk_fail
.cfi_endproc
.section __TEXT,__cstring,cstring_literals
.align 4 ## @main.arr
L_main.arr:
.asciz "this is a string referenced by an array"
L_.str: ## @.str
.asciz "arr = %s; sizeof arr = %ld\n"
.subsections_via_symbols
--- array.S 2015-10-01 10:04:35.000000000 -0400
+++ pointer.S 2015-10-01 10:04:35.000000000 -0400
@@ -12,43 +12,22 @@
movq %rsp, %rbp
Ltmp2:
.cfi_def_cfa_register %rbp
- pushq %rbx
- subq $56, %rsp
-Ltmp3:
- .cfi_offset %rbx, -24
- movq ___stack_chk_guard@GOTPCREL(%rip), %rbx
- movq (%rbx), %rbx
- movq %rbx, -16(%rbp)
- movabsq $34165616355123310, %rax ## imm = 0x7961727261206E
- movq %rax, -32(%rbp)
- movaps L_main.arr+16(%rip), %xmm0
- movaps %xmm0, -48(%rbp)
- movaps L_main.arr(%rip), %xmm0
- movaps %xmm0, -64(%rbp)
- leaq L_.str(%rip), %rdi
- leaq -64(%rbp), %rsi
- movl $40, %edx
+ leaq L_.str1(%rip), %rdi
+ leaq L_.str(%rip), %rsi
+ movl $8, %edx
xorl %eax, %eax
callq _printf
- cmpq -16(%rbp), %rbx
- jne LBB0_2
-## BB#1:
xorl %eax, %eax
- addq $56, %rsp
- popq %rbx
popq %rbp
retq
-LBB0_2:
- callq ___stack_chk_fail
.cfi_endproc
.section __TEXT,__cstring,cstring_literals
- .align 4 ## @main.arr
-L_main.arr:
- .asciz "this is a string referenced by an array"
-
L_.str: ## @.str
- .asciz "arr = %s; sizeof arr = %ld\n"
+ .asciz "this is a string referenced by a pointer"
+
+L_.str1: ## @.str1
+ .asciz "ptr = %s; sizeof ptr = %ld\n"
.subsections_via_symbols
#!/bin/bash
clang -S -Os -o array.S array.c
clang -S -Os -o static_array.S static_array.c
clang -S -Os -o pointer.S pointer.c
#include <stdio.h>
int main(int argc, char *argv[]) {
char *ptr = "this is a string referenced by a pointer";
printf("ptr = %s; sizeof ptr = %ld\n", ptr, sizeof ptr);
return 0;
}
.section __TEXT,__text,regular,pure_instructions
.macosx_version_min 10, 10
.globl _main
_main: ## @main
.cfi_startproc
## BB#0:
pushq %rbp
Ltmp0:
.cfi_def_cfa_offset 16
Ltmp1:
.cfi_offset %rbp, -16
movq %rsp, %rbp
Ltmp2:
.cfi_def_cfa_register %rbp
leaq L_.str1(%rip), %rdi
leaq L_.str(%rip), %rsi
movl $8, %edx
xorl %eax, %eax
callq _printf
xorl %eax, %eax
popq %rbp
retq
.cfi_endproc
.section __TEXT,__cstring,cstring_literals
L_.str: ## @.str
.asciz "this is a string referenced by a pointer"
L_.str1: ## @.str1
.asciz "ptr = %s; sizeof ptr = %ld\n"
.subsections_via_symbols
#include <stdio.h>
int main(int argc, char *argv[]) {
static char arr[40] = "this is a string referenced by an array";
printf("arr = %s; sizeof arr = %ld\n", arr, sizeof arr);
return 0;
}
.section __TEXT,__text,regular,pure_instructions
.macosx_version_min 10, 10
.globl _main
_main: ## @main
.cfi_startproc
## BB#0:
pushq %rbp
Ltmp0:
.cfi_def_cfa_offset 16
Ltmp1:
.cfi_offset %rbp, -16
movq %rsp, %rbp
Ltmp2:
.cfi_def_cfa_register %rbp
leaq L_.str(%rip), %rdi
leaq _main.arr(%rip), %rsi
movl $40, %edx
xorl %eax, %eax
callq _printf
xorl %eax, %eax
popq %rbp
retq
.cfi_endproc
.section __DATA,__data
.align 4 ## @main.arr
_main.arr:
.asciz "this is a string referenced by an array"
.section __TEXT,__cstring,cstring_literals
L_.str: ## @.str
.asciz "arr = %s; sizeof arr = %ld\n"
.subsections_via_symbols
--- static_array.S 2015-10-01 10:04:35.000000000 -0400
+++ pointer.S 2015-10-01 10:04:35.000000000 -0400
@@ -12,9 +12,9 @@
movq %rsp, %rbp
Ltmp2:
.cfi_def_cfa_register %rbp
- leaq L_.str(%rip), %rdi
- leaq _main.arr(%rip), %rsi
- movl $40, %edx
+ leaq L_.str1(%rip), %rdi
+ leaq L_.str(%rip), %rsi
+ movl $8, %edx
xorl %eax, %eax
callq _printf
xorl %eax, %eax
@@ -22,14 +22,12 @@
retq
.cfi_endproc
- .section __DATA,__data
- .align 4 ## @main.arr
-_main.arr:
- .asciz "this is a string referenced by an array"
-
.section __TEXT,__cstring,cstring_literals
L_.str: ## @.str
- .asciz "arr = %s; sizeof arr = %ld\n"
+ .asciz "this is a string referenced by a pointer"
+
+L_.str1: ## @.str1
+ .asciz "ptr = %s; sizeof ptr = %ld\n"
.subsections_via_symbols
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment