Code:
#include <stdio.h>
int main(void)
{
int x;
int number;
for(x=0; x<100; x++) {
number = 0;
number += 2;
printf("Number = %d\n",number);
}
return 0;
}
Same assembler code as:
Code:
#include <stdio.h>
int main(void)
{
int x;
for(x=0; x<100; x++) {
int number = 0;
number += 2;
printf("Number = %d\n",number);
}
return 0;
}
Code:
.file "test1.c"
.def ___main; .scl 2; .type 32; .endef
.section .rdata,"dr"
LC0:
.ascii "Number = %d\12\0"
.text
.globl _main
.def _main; .scl 2; .type 32; .endef
_main:
pushl %ebp
movl %esp, %ebp
subl $24, %esp
andl $-16, %esp
movl $0, %eax
addl $15, %eax
addl $15, %eax
shrl $4, %eax
sall $4, %eax
movl %eax, -12(%ebp)
movl -12(%ebp), %eax
call __alloca
call ___main
movl $0, -4(%ebp)
L2:
cmpl $99, -4(%ebp)
jg L3
movl $0, -8(%ebp)
leal -8(%ebp), %eax
addl $2, (%eax)
movl -8(%ebp), %eax
movl %eax, 4(%esp)
movl $LC0, (%esp)
call _printf
leal -4(%ebp), %eax
incl (%eax)
jmp L2
L3:
movl $0, %eax
leave
ret
.def _printf; .scl 2; .type 32; .endef
The only thing that changes is the file name.
And the only problem I have is that if you declare an initialized variable inside the for loop, it will be initialized in every single loop. So... its not good in some cases.