Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main(void){
- int x = 1;
- while(x<=50){
- printf("%d\n",x);
- x++;
- }
- }
- /*
- I wanted to reconstruct the general logic that I thought was going on
- by using goto. The assembly code I got was similar to the logic in the cs50 example,
- but it was structured differently. I then decided to try the most logical (c programming)
- approach with my original try, and got output that was pretty much the same as the cs50 project.
- output #1:
- int x = 1;
- goto L2;
- L3:
- printf("%d\n",x);
- x++;
- L2:
- if(x <= 50){
- goto L3;
- }*/
- /* output
- .file "assembly.c"
- .section .rodata
- .LC0:
- .string "%d\n"
- .text
- .globl main
- .type main, @function
- main:
- .LFB0:
- .cfi_startproc
- pushq %rbp
- .cfi_def_cfa_offset 16
- .cfi_offset 6, -16
- movq %rsp, %rbp
- .cfi_def_cfa_register 6
- subq $16, %rsp
- movl $1, -4(%rbp)
- jmp .L2
- .L3:
- movl -4(%rbp), %eax
- movl %eax, %esi
- movl $.LC0, %edi
- movl $0, %eax
- call printf
- addl $1, -4(%rbp)
- .L2:
- cmpl $50, -4(%rbp)
- jle .L3
- leave
- .cfi_def_cfa 7, 8
- ret
- .cfi_endproc
- .LFE0:
- .size main, .-main
- .ident "GCC: (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4"
- .section .note.GNU-stack,"",@progbits
- */
Advertisement
Add Comment
Please, Sign In to add comment