mainProgramming from the Ground Up Book - Support: sr #106602, Segmentation fault


sr #106602: Segmentation fault

Submitter:  None
Submitted:  Sat 10 Jan 2009 05:38:03 PM UTC
Category:  None Priority:  5 - Normal
Severity:  3 - Normal Status:  None
Privacy:  Public Assigned to:  None
Originator Email:  -email is unavailable- Open/Closed:  Open
Operating System:  None
* Mandatory Fields

Add a New Comment Rich Markup

Sat 10 Jan 2009 05:38:03 PM UTC, original submission:  

Hi there,

I'm really new to native programming, being a web developer, so I may just be missing something obvious. I'm trying to compile the maximum program in your book. I'm using Ubuntu 8.10, and I go to the terminal and assemble and link the program, and when I try to execute the program, I get "Segmentation Fault". Googling on the web, segmentation fault refers to trying to access protected memory, so I'm thinking maybe there's something in the modern Linux distros that blocks of the registers used in this program? Just a thought. Anyway, I'm attaching the source code to the example. Any help would be great.


#PURPOSE: This program finds the maximum number of a set
#   of data items.

#VARIABLES: The registers have the following uses:
# %edi - Holds the index of the data item being examined.
# %ebx - Largest data item found
# %eax - Current data item

.section .data

data_items:   #These are the data items
 .long 3, 67, 34, 222, 45, 75, 54, 34, 44, 33, 22, 11, 66, 0
 .section .text

 .globl _start
 movl $0, %edi # move 0 into the index register
 movl data_items(,%edi,4), %eax # load the first byte of data
 movl %eax, %ebx                # since this is the first item,
                                # %eax is the biggest
start_loop: # start loop
 cmpl $0, %eax # check to see if we've hit the end
 je loop_exit
 incl %edi      #load next value
 movl data_items(,%edi,4), %eax
 cmpl %ebx, %eax # compare values
 jle start_loop # jump to loop beginning if the
# new one isn't bigger
 movl %eax, %ebx    # move the value as the largest
 jmp start_loop # jump to loop beginning
 # %ebx is the status code for the exit system call
 # and it already has the maximum number
 movl $1, %eax #1 is the exit() syscall
 int $0x80



(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by None (Submitted the item)

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.


    No changes have been made to this item

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code