opensubscriber
   Find in this group all groups
 
Unknown more information…

l : linux-assembly@vger.kernel.org 15 October 2007 • 7:37AM -0400

Unable to use a variable in instruction
by A D

REPLY TO AUTHOR
 
REPLY TO GROUP





I'm having strange problem accessing a variable in a gnu assembly language program.
When i write a code:

.section .data
   x = 4
mm:
   .int 1, 2

.section .text
.globl _start
_start:
   nop
   movl x, %ecx   #can't do this
   movl $1, %eax
   movl $0, %ebx
   int $0x80

I can't move the contents of variable x to %ecx register. This program compiles
and links without giving any error message. But when i run the program I get:

Segmentation fault(core dumped)


Debugging with gdb using core:


Core was generated by `./test'.
Program terminated with signal 11, Segmentation fault.
#0  _start () at test.s:14
10         movl x, %ecx   #can't do this


Another odd thing about it is when i modify the program:

.section .data
   x = 4
mm:
   .int 1, 2

.section .text
.globl _start
_start:
   nop
   movl $0, %ecx
   movl mm(, %ecx, x), %eax
   movl $1, %eax
   movl $0, %ebx
   int $0x80

the code runs without any problem. Even %ecx register contains the correct value.
Is it possible to explain the reason why I can't move directly the value of x in the first
place? Isn't x a variable? If not how come it can store value(in this case 4) and
be used as a size of an array's element? Thanks.


_________________________________________________________________
Express yourself with free Messenger emoticons. Get them today!
http://www.freemessengeremoticons.ca/?icid=EMENCA122-
To unsubscribe from this list: send the line "unsubscribe linux-assembly" in
the body of a message to majordomo@vger...
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Bookmark with:

Delicious   Digg   reddit   Facebook   StumbleUpon

Related Messages

opensubscriber is not affiliated with the authors of this message nor responsible for its content.