LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-31-2011, 11:11 AM   #1
josephgithin
LQ Newbie
 
Registered: May 2011
Posts: 2

Rep: Reputation: Disabled
Unhappy HELPPPP!!! PLSSS! SEGMENTATION FAULT in NASM...


i'm a very beginer in assembly programing...


I want to read from a file which is given as an argument....and write the content of the file in the screen....
when i compile the following program it shows SEGMENTATION FAULT..
i cant find wats wrong some one pls help me....!!



here is the code..\



section .data
data:resb 40
length: equ $-data

section .text
global _start

_start:
pop ebx
pop ebx
pop ebx
mov eax,3
mov [data],eax
int 80h
call filewrite


filewrite:
mov eax,4
mov ebx,1
mov ecx,data
mov edx,length
int 80h
mov eax,6
int 80h
ret
 
Old 05-31-2011, 12:18 PM   #2
josephgithin
LQ Newbie
 
Registered: May 2011
Posts: 2

Original Poster
Rep: Reputation: Disabled
Smile thanks... guys i've solved it using the code below...

section .data
data:db"i am an assembly programmer!",10
len: equ $-data
newfile:db"newfile.txt"
newdata:resb len
section .text
global _start

_start:
pop ebx
pop ebx
pop ebx
mov eax,5
mov ecx,00644Q
int 80h

test eax,eax
js skipread
call fileread
call createnewfile
call writenewfile
skipread:
mov eax,1
mov ebx,0
int 80h
fileread:
mov ebx,eax
mov eax,3
mov ecx,newdata
mov edx,len
int 80h
ret
createnewfile:
mov eax,8
mov ebx,newfile
mov ecx,00644Q
int 80h
ret
writenewfile:
mov ebx,eax
mov eax,4
mov ecx,newdata
mov edx,len
int 80h
mov eax,6
int 80h
mov eax,1
int 80h
ret
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Segmentation Fault babu.chanuvalli Linux - Newbie 4 05-27-2009 01:32 AM
yast segmentation fault, system freezing - nvidia driver at fault? BaltikaTroika SUSE / openSUSE 2 12-02-2005 09:34 AM
Segmentation Fault rupesh_pulikool Linux - Software 7 01-07-2005 05:55 AM
Segmentation fault.. please help me! rpmadness Linux - Software 4 11-25-2003 06:47 PM
Segmentation fault suriyamohan Linux - General 5 10-21-2003 01:37 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration