Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 05-19-2005, 08:18 AM   #1
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
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
mov al,0
mov ebx,num
mov ecx,[count]
cmp [ebx],al
jc next
mov al,[ebx]
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, 08:40 AM   #2
Senior Member
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,186

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
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, 09:16 AM   #3
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.


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

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

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