I am using x86 AT&T Assembly on Ubuntu.
I need to rewrite any complex indirect addressing modes, like based indexed mode, into simple indirect addressing mode.
For example, take this snippet:
.L4:
movl i, %eax
movzbl ch, %edx
movb %dl, dict(%eax)
The line movb %dl, dict(%eax)
is based indexed addressing I think. What it does is it takes dict+%eax
and dereferences it, then places %dl
into it, right?
Now I wrote it like this to make it simple indirect addressing:
.L4:
movl i, %eax
movzbl ch, %edx
addl dict, %eax
movb %dl, (%eax)
As you can see I first added dict
and %eax
and placed the result into %eax
as well. Then on the next line I just dereference the result.
This should work the same way as above, right?
It compiles too, but when running it, I get a segmentation fault at my new movb
line.
Why doesn't this work?