刚刚自学汇编语言,希望有那位大神能过帮我把下面这段c语言翻译成汇编语言!感激不尽!

#include <stdio.h>
int main(){
int n;
int sum=0;
do{
printf("please enter an integer:\n");
scanf("%d",&n);

sum=sum+n;

printf("the sum is %d\n\n",sum);
}
while(n!=0);
return 0;
}

第1个回答  2014-12-28
:~/wenjian/bowl$ gcc -S tie.c -o tie.s
:~/wenjian/bowl$ vim tie.s
:~/wenjian/bowl$ cat tie.c tie.s
#include <stdio.h>
int main(void)
{
 int n;
 int sum=0;
 do{

  printf("please enter an integer:\n");
scanf("%d",&n);   
sum=sum+n;   
  printf("the sum is %d\n\n",sum);
 }while(n!=0);
   return 0;
}






.file "tie.c"
.section .rodata
.LC0:
.string "please enter an integer:"
.LC1:
.string "%d"
.LC2:
.string "the sum is %d\n\n"
.text
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
pushl %ebp
.cfi_def_cfa_offset 8
.cfi_offset 5, -8
movl %esp, %ebp
.cfi_def_cfa_register 5
andl $-16, %esp
subl $32, %esp
movl $0, 28(%esp)
.L2:
movl $.LC0, (%esp)
call puts
leal 24(%esp), %eax
movl %eax, 4(%esp)
movl $.LC1, (%esp)
call __isoc99_scanf
movl 24(%esp), %eax
addl %eax, 28(%esp)
movl 28(%esp), %eax
movl %eax, 4(%esp)
movl $.LC2, (%esp)
call printf
movl 24(%esp), %eax
testl %eax, %eax
jne .L2
movl $0, %eax
leave
.cfi_restore 5
.cfi_def_cfa 4, 4
ret
.cfi_endproc
.LFE0:
.size main, .-main
.ident "GCC: (Ubuntu 4.8.2-19ubuntu1) 4.8.2"
.section .note.GNU-stack,"",@progbits 

追问

大神,真的非常感谢你这么用心,但是好像除了一点问题~

请问这要怎么解决呢?

追答

可能要你新建一个tie.c的源文件吧,在里面保存c语言程序.
你要汇编干嘛,

本回答被网友采纳