Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Assembly (http://www.programmingforums.org/forum20.html)
-   -   x86 assembly (segfault) (http://www.programmingforums.org/showthread.php?t=2849)

Arnvidr Mar 20th, 2005 11:16 AM

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 Mar 20th, 2005 12:18 PM

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?


All times are GMT -5. The time now is 5:56 PM.

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