Not sure if this is the actual assignment that's consuming cycles for you
i believe this is the assignment thats consuming cycles
for example
looc at this t1.c
#include <stdio.h>
int main(void)
{
int i;
size_t u;
for (i = 0; i < 10; i++) {
printf("i = %d, u = %zu\n", i, u);
}
return 0;
}
and the assmebly for t1.c
.file "t1.c"
.section .rodata
.LC0:
.string "i = %d, u = %zu\n"
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
andl $-16, %esp
subl $32, %esp
movl $0, 24(%esp)
jmp .L2
.L3:
movl $.LC0, %eax
movl 28(%esp), %edx
movl %edx, 8(%esp)
movl 24(%esp), %edx
movl %edx, 4(%esp)
movl %eax, (%esp)
call printf
addl $1, 24(%esp)
.L2:
cmpl $9, 24(%esp)
jle .L3
movl $0, %eax
leave
ret
.size main, .-main
.ident "GCC: (GNU) 4.4.6 20110731 (Red Hat 4.4.6-3)"
.section .note.GNU-stack,"",@progbits
in the above case no assignment atall for its ok for now
second case t2.c
#include <stdio.h>
int main(void)
{
int i;
size_t u;
for (i = 0; i < 10; i++) {
i = (size_t) u;
printf("i = %d, u = %zu\n", i, u);
}
return 0;
}
and the subsequent assmebly
.file "t2.c"
.section .rodata
.LC0:
.string "i = %d, u = %zu\n"
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
andl $-16, %esp
subl $32, %esp
movl $0, 24(%esp)
jmp .L2
.L3:
movl 28(%esp), %eax
movl %eax, 24(%esp)
movl $.LC0, %eax
movl 28(%esp), %edx
movl %edx, 8(%esp)
movl 24(%esp), %edx
movl %edx, 4(%esp)
movl %eax, (%esp)
call printf
addl $1, 24(%esp)
.L2:
cmpl $9, 24(%esp)
jle .L3
movl $0, %eax
leave
ret
.size main, .-main
.ident "GCC: (GNU) 4.4.6 20110731 (Red Hat 4.4.6-3)"
.section .note.GNU-stack,"",@progbits
Check the statements above
movl 28(%esp), %eax
movl %eax, 24(%esp)
now for the last example t3.c
#include <stdio.h>
int main(void)
{
int i;
int u;
for (i = 0; i < 10; i++) {
i = u;
printf("i = %d, u = %zu\n", i, u);
}
return 0;
}
and the subsequent assembly
.file "t3.c"
.section .rodata
.LC0:
.string "i = %d, u = %zu\n"
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
andl $-16, %esp
subl $32, %esp
movl $0, 24(%esp)
jmp .L2
.L3:
movl 28(%esp), %eax
movl %eax, 24(%esp)
movl $.LC0, %eax
movl 28(%esp), %edx
movl %edx, 8(%esp)
movl 24(%esp), %edx
movl %edx, 4(%esp)
movl %eax, (%esp)
call printf
addl $1, 24(%esp)
.L2:
cmpl $9, 24(%esp)
jle .L3
movl $0, %eax
leave
ret
.size main, .-main
.ident "GCC: (GNU) 4.4.6 20110731 (Red Hat 4.4.6-3)"
.section .note.GNU-stack,"",@progbits
Now you can observe t2 and t3 and see the difference here, but really varies from arch to arch though