tags:

views:

373

answers:

2

Hi, I'm stuck with this. I'm self studying assenbler and translating some basics instructions. But i can't with this one.

Can anyone help me, please?

int
secuencia ( int n, EXPRESION * * o )
{
  int a, i;
  for ( i = 0; i < n; i++ ){

    a = evaluarExpresion( *o );

    // Im trying to do this: o++;
  __asm {
      mov eax,dword ptr [o] 
      mov ecx,dword ptr [eax] 
      inc [ecx]  
    }
  }
  return a ;
}

I wrote the inside for and works, but still don't know how to increment O

int
secuencia ( int n, EXPRESION * * o )
{
  int a, i;
  for ( i = 0; i < n; i++ ){

      __asm {

      mov eax,dword ptr [o] 
      mov ecx,dword ptr [eax] 
     push ebp
      mov ebp, esp
      push ecx

      call evaluarExpresion
     mov esp, ebp

     pop ebp

     mov a, eax
      }

    o++;
  }
  return a ;
}
+1  A: 

There are two options:

Either:

  • move the value of o from memory into a register (eax, for example)
  • increment the register
  • move the value from the register back to memory

or

  • increment the value stored in memory directly

Try to use both methods.

Artelius
I'd give some code but I've never used MASM syntax (or whatever it is you're using).
Artelius
Hi Artelius, I know that I need to do the second one, But i really don't know how. I'm working for a few hours... but nothing, can you please code-explain me? I also try with lea eax, o but doesn't work.thanks
Sheldon
Try `inc dword ptr o` or `inc dword ptr [o]`. If this succeeds, good, but I suggest for practice you also try to move `o` into a register, increment the register, and move the register into memory again.
Artelius
I pass the values to the registries but still have the problem. I edit the question, could you please check it out? thanks!
Sheldon
I follow your recomendation and read about it. I'm using MASM and what I want to do is not possible (at least not in a easy way).So I just incresea the value directly following the advice from toto: add o, 4 and it solves the problem. Thank you! (Do you want a google wave invitation as a way to say thanks?)
Sheldon
That would be nice! I shall send you an email.
Artelius
+1  A: 
mov esi, o
add esi, 4 //increment is here

Line1 : We move your o pointer to the esi register. Line2: We increment your o pointer

or

mov eax, o
mov esi, [eax]
add esi, 4

I don't understand perfectly what you are trying to do but I hope it helped!

toto
Hi toto,I try that: call evaluarExpresion mov esi, [o] add esi, 4 //increment is here mov esp, ebpBut doesn't work. Or do I need to put it in another place?
Sheldon
Of course! Don't use INC, pointers are 4 bytes (in 32-bit assembly language...)
Artelius
Hi Toto, and thanks again.What I need to do is that inside assembler, replace the o++ instruction.I need to get a pointer to o, and modify the instruction within that pointer to add 4 (so it can pass to next element). I try both of your recommendations but doesn't work. What is more strange is that just leaving o++ outside the asm (of course is C) it works. So It must be a translating issue. I don't know if I explain myself. Thank you very much for your help.
Sheldon
Your solution works!!! but not on this compiler :(Still, thank you very much! and check below, that goes for you also!
Sheldon
I think, in the first example, you must add `mov o, esi` to save the value back to the `o` variable.
Artelius