#include <cstddef>
#include<cstdio>
void function(size_t len)
{
int arr[len];
for(size_t i = 0; i < len; ++i)
{
arr[i] = i;
printf("%d\n", arr[i]);
}
}
.LC0:
.string "%d\n"
function:
push rbp
mov rbp, rsp
push rbx
sub rsp, 56
mov QWORD PTR [rbp-56], rdi
mov rax, rsp
mov rbx, rax
mov rax, QWORD PTR [rbp-56]
mov rdx, rax
sub rdx, 1
mov QWORD PTR [rbp-32], rdx
mov r10, rax
mov r11d, 0
mov r8, rax
mov r9d, 0
lea rdx, [0+rax*4]
mov eax, 16
sub rax, 1
add rax, rdx
mov esi, 16
mov edx, 0
div rsi
imul rax, rax, 16
sub rsp, rax
mov rax, rsp
add rax, 3
shr rax, 2
sal rax, 2
mov QWORD PTR [rbp-40], rax
mov QWORD PTR [rbp-24], 0
jmp .L2
.L3:
mov rax, QWORD PTR [rbp-24]
mov ecx, eax
mov rax, QWORD PTR [rbp-40]
mov rdx, QWORD PTR [rbp-24]
mov DWORD PTR [rax+rdx*4], ecx
mov rax, QWORD PTR [rbp-40]
mov rdx, QWORD PTR [rbp-24]
mov eax, DWORD PTR [rax+rdx*4]
mov esi, eax
mov edi, OFFSET FLAT:.LC0
mov eax, 0
call printf
add QWORD PTR [rbp-24], 1
.L2:
mov rax, QWORD PTR [rbp-24]
cmp rax, QWORD PTR [rbp-56]
jb .L3
mov rsp, rbx
nop
mov rbx, QWORD PTR [rbp-8]
leave
ret
c코드 결과 - x86-64 gcc 5.x
반면에 x86-64 gcc 4.x로 하면 아래 처럼 뜬다.
<source>: In function 'function':
<source>:6:1: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
for(size_t i = 0; i < len; ++i)
^
<source>:6:1: note: use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code
Compiler returned: 1
.LC0:
.string "%d\n"
function(unsigned long):
push rbp
mov rbp, rsp
push rbx
sub rsp, 56
mov QWORD PTR [rbp-56], rdi
mov rax, rsp
mov rbx, rax
mov rax, QWORD PTR [rbp-56]
sub rax, 1
mov QWORD PTR [rbp-32], rax
mov rdx, rax
add rdx, 1
mov r10, rdx
mov r11d, 0
mov rdx, rax
add rdx, 1
mov r8, rdx
mov r9d, 0
add rax, 1
lea rdx, [0+rax*4]
mov eax, 16
sub rax, 1
add rax, rdx
mov esi, 16
mov edx, 0
div rsi
imul rax, rax, 16
sub rsp, rax
mov rax, rsp
add rax, 3
shr rax, 2
sal rax, 2
mov QWORD PTR [rbp-40], rax
mov QWORD PTR [rbp-24], 0
.L3:
mov rax, QWORD PTR [rbp-24]
cmp rax, QWORD PTR [rbp-56]
jnb .L2
mov rax, QWORD PTR [rbp-24]
mov ecx, eax
mov rax, QWORD PTR [rbp-40]
mov rdx, QWORD PTR [rbp-24]
mov DWORD PTR [rax+rdx*4], ecx
mov rax, QWORD PTR [rbp-40]
mov rdx, QWORD PTR [rbp-24]
mov eax, DWORD PTR [rax+rdx*4]
mov esi, eax
mov edi, OFFSET FLAT:.LC0
mov eax, 0
call printf
add QWORD PTR [rbp-24], 1
jmp .L3
.L2:
mov rsp, rbx
nop
mov rbx, QWORD PTR [rbp-8]
leave
ret
c++ 코드 결과
'취업,면접 대비' 카테고리의 다른 글
현업자들이 바라보는 iOS앱 개발자의 미래 1.0 - 블라인드 ver (0) | 2021.07.22 |
---|---|
<개발자 취업 대비?> 내가 생각하는 컴공으로 개발자 취직하기 좋은 테크 (0) | 2020.12.31 |
면접 대비 운영체제 공부 (abraham 4장 thread) (0) | 2019.12.09 |
면접 대비 운영체제 공부 (abraham 3장 Process) (0) | 2019.12.08 |
면접 대비 자료구조 공부 (abraham 2장 시스템 구조) (0) | 2019.12.07 |