I'm learning asm and here's one of my (many) problems: I'd like to change the value of some index of an array. Let's say that:
I've tried movl %eax, (-4(%ebp),0(%esp),4)
but it did not work.
Worse, it throws a syntax error : bobi.s:15: Error: junk `(%ebp),0(%esp),4)' after expression
What is the correct syntax?
There is no single instruction to do this in x86 assembly. You have to find an available register, use it to store the address of the array that you get from -4(%ebp)
, find another register to hold the index 0(%esp)
, and only then does it become possible to access the cell you are interested in (and in more RISC-like assemblies, you'd still need to add these two registers together before you can do the memory access).
Assuming the registers are available, something like:
movl -4(%ebp), %ebx
movl 0(%esp), %ecx
movl %eax, 0(%ebx,%ecx,4)
should work.