LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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-19-2005, 07:18 AM   #1
andrewnow
Member
 
Registered: Dec 2004
Location: P.R.C
Posts: 38

Rep: Reputation: 15
why segment fault?


the code i wrote is to find the biggest number in num,but it shows segment fault when i run it.

nasm -f elf and.asm -o and.o
gcc -o and.o
./and
segment fault
////////////////////////////////////
section .data
num db -19,28,37,-46,55,61,-74,88
count equ $-num
max db 'max=?',0dh,0ah,'$'

section .text
global main
main:
mov al,0
mov ebx,num
mov ecx,[count]
last:
cmp [ebx],al
jc next
mov al,[ebx]
next:
inc ebx
loop last
mov [max+4],al
mov eax,4
mov ebx,1
mov ecx,max
mov edx,8
int 80h
mov eax,1
int 80h
 
Old 05-19-2005, 07:40 AM   #2
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
I can't help with your seg fault problem, but your initalization seems wrong. You've started with a value of zero, and -- if your data was all less than zero -- your logic would return zero instead of the largest value.

Also, I think you're comparing the character byte values rather than the numeric values represented by the set of bytes. (I may be wrong on this point -- its been thirty years since I last did asembly programming, and that was on an IBM 3090.)
 
Old 05-19-2005, 08:16 AM   #3
andrewnow
Member
 
Registered: Dec 2004
Location: P.R.C
Posts: 38

Original Poster
Rep: Reputation: 15
thank you very much Mr. PTrenholme. your suggestion seems much vulable. I'll try again. thank you again.
 
  


Reply



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
segment fault? melodious Fedora - Installation 1 10-25-2004 10:35 PM
9.1 new install segment fault jpearl24 Slackware 4 12-02-2003 03:17 PM
What is a segment fault Dumpsterm0uth Linux - General 9 08-03-2003 03:19 PM
netbsd, segment fault? HmmLinux *BSD 0 07-09-2003 05:32 PM
HELP! ipop3d segment fault zbychu900 Linux - Networking 0 06-20-2001 05:28 PM

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

All times are GMT -5. The time now is 01:25 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