Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 20th, 2005, 11:16 AM   #1
Arnvidr
Newbie
 
Join Date: Mar 2005
Posts: 2
Rep Power: 0 Arnvidr is on a distinguished road
Unhappy x86 assembly (segfault)

Consider this bit of code which is part of a kinda itoa procedure, only the string is reversed:
#get a number from a parameter, this bit is identical to functional bits getting chars and strings
movl (%esi), %eax
addl $4, %esi

#uses the %ecx-register for the string, adds a zero at the beginning for later reversal purposes
movl $0, %ecx
incl %ecx

#the actual procedure
loop:
cmpl $0, (%eax)
je done
cdq #is this really necessary? doesn't seem to make any difference atm
movl $10, %ebx # the divisor
idivl %ebx
addl $48, %edx
movb (%edx), %bl
movb %bl, (%ecx)
incl %ecx
jmp loop
ignoring the fact that it doesn't handle negative integers at the moment, I can't for the life of me see why this would be segfaulting...
Arnvidr is offline   Reply With Quote
Old Mar 20th, 2005, 12:18 PM   #2
Arnvidr
Newbie
 
Join Date: Mar 2005
Posts: 2
Rep Power: 0 Arnvidr is on a distinguished road
I've found that (at least the first) reason for the segfault is this line:
movl   (%esi), %ecx
The %esi register contains the parameters for the whole program, and this line is identical to functioning procedures for getting both chars and strings, so I gather there must be some other method of handling ints?
Arnvidr is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:43 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC