Advertisement

07.29.2008 at 05:46AM PDT, ID: 23603739
[x]
Attachment Details

Simple Linux Assembly Program

Asked by chsalvia in Assembly Programming Language

I'm trying to write my first simple assembly program using the gas assembler on Linux, with AT&T syntax.

The program is meant to simply push some characters onto the stack, and then output them to stdout.  So I start by pushing 16 ASCII characters onto the stack, then I set up the registers for a system call to write(), and then I execute the system call.  My assumption here is that after pushing the string onto the stack, the stack pointer (esp) will be pointing to the beginning of the string.

The program compiles and runs, but it doesn't output anything.  Can someone explain why it doesn't work?Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
.global _start
 
_start:
 
# push an ASCII string onto the stack
 
push	$0x0a515151
push	$0x51515151
push	$0x51515151
push	$0x51515151
 
movl	$16, %edx	# third argument: message length
movl	%esp, %ecx	# second argument: stack pointer
movl	$1, %ebx	# first argument: file handle (stdout)
movl	$4, %eax	# system call number (sys_write)
int	$0x80	
 
# exit
 
movl	$0,%ebx
movl	$1,%eax
int	$0x80
[+][-]07.29.2008 at 06:53AM PDT, ID: 22111433

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.29.2008 at 07:48AM PDT, ID: 22111985

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.29.2008 at 11:10AM PDT, ID: 22113971

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.29.2008 at 04:44PM PDT, ID: 22116636

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.30.2008 at 12:36AM PDT, ID: 22118159

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.30.2008 at 08:47AM PDT, ID: 22121641

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.30.2008 at 12:30PM PDT, ID: 22123864

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Assembly Programming Language
Sign Up Now!
Solution Provided By: Infinity08
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628