Last active
December 8, 2016 19:02
-
-
Save Kwpolska/9f2bd44739e81ca4bcde767cdfd3576d to your computer and use it in GitHub Desktop.
for loop vs while loop (C, gcc 6.2.1)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- for.s 2016-12-08 20:00:37.121281039 +0100 | |
+++ while.s 2016-12-08 20:00:38.705280904 +0100 | |
@@ -1,4 +1,4 @@ | |
- .file "for.c" | |
+ .file "while.c" | |
.intel_syntax noprefix | |
.text | |
.globl main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main() { | |
int n = 1; | |
for (int i = 2; i < 10; ++i) { | |
n += i; | |
} | |
return n; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.file "for.c" | |
.intel_syntax noprefix | |
.text | |
.globl main | |
.type main, @function | |
main: | |
.LFB0: | |
.cfi_startproc | |
push rbp | |
.cfi_def_cfa_offset 16 | |
.cfi_offset 6, -16 | |
mov rbp, rsp | |
.cfi_def_cfa_register 6 | |
mov DWORD PTR [rbp-4], 1 | |
mov DWORD PTR [rbp-8], 2 | |
jmp .L2 | |
.L3: | |
mov eax, DWORD PTR [rbp-8] | |
add DWORD PTR [rbp-4], eax | |
add DWORD PTR [rbp-8], 1 | |
.L2: | |
cmp DWORD PTR [rbp-8], 9 | |
jle .L3 | |
mov eax, DWORD PTR [rbp-4] | |
pop rbp | |
.cfi_def_cfa 7, 8 | |
ret | |
.cfi_endproc | |
.LFE0: | |
.size main, .-main | |
.ident "GCC: (GNU) 6.2.1 20160916 (Red Hat 6.2.1-2)" | |
.section .note.GNU-stack,"",@progbits |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main() { | |
int n = 1; | |
int i = 2; | |
while (i < 10) { | |
n += i; | |
++i; | |
} | |
return n; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.file "while.c" | |
.intel_syntax noprefix | |
.text | |
.globl main | |
.type main, @function | |
main: | |
.LFB0: | |
.cfi_startproc | |
push rbp | |
.cfi_def_cfa_offset 16 | |
.cfi_offset 6, -16 | |
mov rbp, rsp | |
.cfi_def_cfa_register 6 | |
mov DWORD PTR [rbp-4], 1 | |
mov DWORD PTR [rbp-8], 2 | |
jmp .L2 | |
.L3: | |
mov eax, DWORD PTR [rbp-8] | |
add DWORD PTR [rbp-4], eax | |
add DWORD PTR [rbp-8], 1 | |
.L2: | |
cmp DWORD PTR [rbp-8], 9 | |
jle .L3 | |
mov eax, DWORD PTR [rbp-4] | |
pop rbp | |
.cfi_def_cfa 7, 8 | |
ret | |
.cfi_endproc | |
.LFE0: | |
.size main, .-main | |
.ident "GCC: (GNU) 6.2.1 20160916 (Red Hat 6.2.1-2)" | |
.section .note.GNU-stack,"",@progbits |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment