This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Assembly code generated


Hi,

This is (rather primitive) C code to execute a shell:

	#include <stdio.h>
	
	void main()
	{
	    char *name[2];
	
	    name[0] = "/bin/sh";
	    name[1] = NULL;
	    execve(name[0], name, NULL);
	}
	

It was compiled with 

	gcc -ggdb -o exec_shell exec_shell.c


What follows is the correspong gdb disassembly of function main:

	(gdb) disassemble main
	Dump of assembler code for function main:
	0x080481f4 <main+0>:    push   %ebp
	0x080481f5 <main+1>:    mov    %esp,%ebp
	0x080481f7 <main+3>:    sub    $0x18,%esp
	0x080481fa <main+6>:    and    $0xfffffff0,%esp
	0x080481fd <main+9>:    mov    $0x0,%eax
	0x08048202 <main+14>:   sub    %eax,%esp
	0x08048204 <main+16>:   movl   $0x8095ce8,0xfffffff8(%ebp)
	0x0804820b <main+23>:   movl   $0x0,0xfffffffc(%ebp)
	0x08048212 <main+30>:   movl   $0x0,0x8(%esp,1)
	0x0804821a <main+38>:   lea    0xfffffff8(%ebp),%eax
	0x0804821d <main+41>:   mov    %eax,0x4(%esp,1)
	0x08048221 <main+45>:   mov    0xfffffff8(%ebp),%eax
	0x08048224 <main+48>:   mov    %eax,(%esp,1)
	0x08048227 <main+51>:   call   0x804ce40 <execve>
	0x0804822c <main+56>:   leave  
	0x0804822d <main+57>:   ret    
	End of assembler dump.
	
	
Rest of the assembly code I more or less understand can somebody tell me
what purpose, if any, do the instructions 
	mov $0x0,%eax 
	sub %eax,%esp
serve ?


-- 
``A prince never lacks legitimate reasons to break his promise.''
				-- Machiavelli 

	Date: Mon Sep 20 13:41:12 IST 2004
	GNU/Linux [2.6.9-rc2] System: up   3:21


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]