0

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
  • The console doesn't do nothing (blank). When I change all the __asm {...} to o++ it works!
    – Sheldon
    Nov 8, 2009 at 5:45

2 Answers 2

1
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!

5
  • Hi toto, I try that: call evaluarExpresion mov esi, [o] add esi, 4 //increment is here mov esp, ebp But doesn't work. Or do I need to put it in another place?
    – Sheldon
    Nov 8, 2009 at 6:29
  • Of course! Don't use INC, pointers are 4 bytes (in 32-bit assembly language...)
    – Artelius
    Nov 8, 2009 at 6:31
  • 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
    Nov 8, 2009 at 6:44
  • Your solution works!!! but not on this compiler :( Still, thank you very much! and check below, that goes for you also!
    – Sheldon
    Nov 8, 2009 at 7:03
  • I think, in the first example, you must add mov o, esi to save the value back to the o variable.
    – Artelius
    Nov 8, 2009 at 8:08
1

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.

6
  • I'd give some code but I've never used MASM syntax (or whatever it is you're using).
    – Artelius
    Nov 8, 2009 at 5:42
  • 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
    Nov 8, 2009 at 5:42
  • 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
    Nov 8, 2009 at 5:46
  • I pass the values to the registries but still have the problem. I edit the question, could you please check it out? thanks!
    – Sheldon
    Nov 8, 2009 at 6:13
  • 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
    Nov 8, 2009 at 7:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.