日期:2014-05-16  浏览次数:20579 次

请问该如何更改成汇编
请看:
#include <stdio.h>
int main()
{
  char *name[2];
  name[0]="/bin/ls";
  name[1]=NULL;
  execve(name[0],name,NULL);
  return 0;
}
这个可以执行,是显示文件目录的。我想把它改成汇编,请看:
.data
     msg:.string "/bin/ls"

.text
.global _start
_start:
      movl $0xb,%eax
      movl $msg,%ebx
      mov $msg,%ecx
      movl $0,%edx
      int $0x80
      movl $0,%ebx
      movl $1,%eax
      int $0x80

可是执行时没有反应,请问该如何更改?

------解决方案--------------------
gcc -S 出来的, 做个参考吧。

.file "main.cpp"
.section .rodata
.LC0:
.string "/bin/ls"
.text
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
pushl %ebp
.cfi_def_cfa_offset 8
movl %esp, %ebp
.cfi_offset 5, -8
.cfi_def_cfa_register 5
andl $-16, %esp
subl $32, %esp
movl $.LC0, 24(%esp)
movl $0, 28(%esp)
movl 24(%esp), %eax
movl $0, 8(%esp)
leal 24(%esp), %edx
movl %edx, 4(%esp)
movl %eax, (%esp)
call execve
movl $0, %eax
leave
.cfi_restore 5
.cfi_def_cfa 4, 4
ret
.cfi_endproc
.LFE0:
.size main, .-main
.ident "GCC: (SUSE Linux) 4.5.1 20101208 [gcc-4_5-branch revision 167585]"
.section .comment.SUSE.OPTs,"MS",@progbits,1
.string "ospwg"
.section .note.GNU-stack,"",@progbits


------解决方案--------------------
gcc *.c -S