×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Problem with the movl instruction in x86 assembly

Problem with the movl instruction in x86 assembly

Problem with the movl instruction in x86 assembly

(OP)
I am trying to run a simple program in x86 linux assembly, but it keeps mysteriously segfaulting, and I can't figure out why. The line of code that is causing the problem is:

movl %esi, 0x8(%esi)

In fact I ran a separate program consisting of just this one line of code (embedded in c) and it segfaults. I replaced %esi with $0x0 and it segfaults again. If I replace the entire expression with something like "movl %esi %eax" then it doesn't segfault. So clearly the problem must be with the 0x8(%esi) part. Does this mean I cannot write to the memory location 0x8($esi)?? Any suggestions on how to get around this problem?
Bob

RE: Problem with the movl instruction in x86 assembly

1. What does ESI point to ?
   Is it a valid pointer in ur program's address space.

2. While using inline assembly with GCC, u need to be
   careful about few things. For exp, the COMPILER never
   knows anything about the registers u r destroying.
   If u dont inform GCC that u r destroying a value in
   a register, GCC would not relinquish register-memory
   mappings while generating code. For exp, if the compiler
   had generated code such that "EBX" contains the value
   of a memory location prior and after ur code, then ur
   assembly instruction would b a pain in the ass. He would
   spoil the entire broth
      Similarly, if u update a memory location in ur
   inline assembly , u need to explicitly tell GCC that
   it has to purge "all" register--memory caches prior
   to this assembly. An ASM implementation of
   "memcpy" would need this..

   So, for exp : consider this :
     __asm__ ("movl %eax, %ebx");
  If u insert this intrn amidst ur "C" code, it might
  b catastrphic. Coz, prior and after this instrn,
  GCC would have generated Code that might have a   
  dependency that EBX would contain some value.. Since
  u r destroying it now.. u need to tell GCC explicity that
  this ASM stmt would destroy EBX register.
  like this: __asm__ ("movl %eax, %ebx":::"bx");
  The "bx" is called a "clobber". This means that
  GCC doesn't peep into ur ASM stmt and see what all
  it destroys. U need to tell him explicitly. Thats
  reasonable too.

  IIIrly when u write into a memory location in ur
   inline assembly, just tell GCC to relinquish all
   register-memory mappings during Code Generation.

  Thus ur new code would look like:
    __asm__ ("movl %esi, 0x8(%esi)":::"memory");

Hope it helped

For more info on GCC inline =>

http://www.tux.org/hypermail/linux-gcc/2000-mar/att-0024/01-gcc-asm.txt


Sarnath


Do not rejoice that ur code works.
it might be a special case of an error

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close