Skip to contentSkip to conversation

Trouble Creating File

DISCUSSION Liam Prange 3 participants 3 messages Nov 13, 2007

lore
Share & tools
lore
#0 lore raw

Hi all,

I am new to assembly language and I am having trouble writing a program that creates a file. The file does get created, however, the program always causes a segmentation fault. The program is called "test" and you give the name of the file you wish to create as an argument, like so: ./test create.txt

..section .data
..section .bss
..lcomm BUFFER, 500
..section .text
..globl _start
_start:

movl %esp, %ebp #setup for referencing the stack

#Open/Create the file we are writing to
movl $5, %eax
movl 8( %ebp ), %ebx
movl $03101, %ecx
movl $0666, %edx
int $0x80
movl ( %eax ), %ebx #save the fd

#close the file
movl $6, %eax
int $0x80

Can anyone help me out as to why I am getting the segmentation fault?

Robert

      ____________________________________________________________________________________

Get easy, one-click access to your favorites. Make Yahoo! your homepage.
http://www.yahoo.com/r/hs

#1 lore raw

Change
movl ( %eax ), %ebx #save the fd
to
movl %eax, %ebx

-----Original Message-----
From: [email protected] [mailto:[email protected]]On Behalf Of Liam Prange
Sent: Tuesday, November 13, 2007 7:58 AM
To: [email protected]
Subject: Trouble Creating File

Hi all,

I am new to assembly language and I am having trouble writing a program that creates a file. The file does get created, however, the program always causes a segmentation fault. The program is called "test" and you give the name of the file you wish to create as an argument, like so: ./test create.txt

..section .data
..section .bss
..lcomm BUFFER, 500
..section .text
..globl _start
_start:

movl %esp, %ebp #setup for referencing the stack

#Open/Create the file we are writing to
movl $5, %eax
movl 8( %ebp ), %ebx
movl $03101, %ecx
movl $0666, %edx
int $0x80
movl ( %eax ), %ebx #save the fd

#close the file
movl $6, %eax
int $0x80

Can anyone help me out as to why I am getting the
segmentation fault?

Robert

      ____________________________________________________________________________________

Get easy, one-click access to your favorites.
Make Yahoo! your homepage.
http://www.yahoo.com/r/hs

-
To unsubscribe from this list: send the line "unsubscribe linux-assembly" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw

2007/11/13, LaPoint, Adam W <[email protected]>:

Quoted 40 lines

Change
movl ( %eax ), %ebx #save the fd
to
movl %eax, %ebx

-----Original Message-----
From: [email protected] [mailto:[email protected]]On Behalf Of Liam Prange
Sent: Tuesday, November 13, 2007 7:58 AM
To: [email protected]
Subject: Trouble Creating File

Hi all,

I am new to assembly language and I am having trouble writing a program that creates a file. The file does get created, however, the program always causes a segmentation fault. The program is called "test" and you give the name of the file you wish to create as an argument, like so: ./test create.txt

..section .data
..section .bss
..lcomm BUFFER, 500
..section .text
..globl _start
_start:

movl %esp, %ebp #setup for referencing the stack

#Open/Create the file we are writing to
movl $5, %eax
movl 8( %ebp ), %ebx
movl $03101, %ecx
movl $0666, %edx
int $0x80
movl ( %eax ), %ebx #save the fd

Quoted 7 lines

#close the file
movl $6, %eax
int $0x80

Can anyone help me out as to why I am getting the
segmentation fault?

and

_start:
pushl %ebp
movl %esp, %ebp
....

Signature · 1 line
noone is alone.