linux-assembly.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: A D <a_d_249@hotmail.com>
To: "linux-assembly@vger.kernel.org" <linux-assembly@vger.kernel.org>
Subject: Unable to use a variable in instruction
Date: Sun, 14 Oct 2007 19:37:55 -0400	[thread overview]
Message-ID: <BAY133-W25307FEE9AA1A457394586F5A20@phx.gbl> (raw)


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

             reply	other threads:[~2007-10-14 23:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-14 23:37 A D [this message]
2007-10-15  1:45 ` Unable to use a variable in instruction Frank Kotler
2007-10-15  2:01 ` Robert Plantz
2007-10-15 13:31   ` A D

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BAY133-W25307FEE9AA1A457394586F5A20@phx.gbl \
    --to=a_d_249@hotmail.com \
    --cc=linux-assembly@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).