If there is an address of a char array in eax, what's the difference between 0(%eax) and (%eax)?Or are they the same, both refer to the first element in the array?
Asked
Active
Viewed 624 times
-2
-
5when you assembled then disassembled them did you see a difference? – old_timer May 17 '17 at 21:06
-
Think about what `0(%eax)` means. It means that there is an offset of 0 from the value in `eax`. Now, what does `(%eax)` mean? It means the value in `eax`. So as long as `x == x + 0`, no, there is obviously no difference. – Cody Gray - on strike May 19 '17 at 08:21
-
If you're seeing something like `0(%eax)` in disassembler output (as opposed to assembly source code) then the 0 is probably the target of a relocation that would change it some other value when the object file is linked. – Ross Ridge May 19 '17 at 18:51
2 Answers
2
They are exactly the same. You could prove this easily by assembling and then disassembling the two instructions:
movl (%eax),%edx
movl 0(%eax),%edx
Disassembly of section .text:
0000000000000000 <.text>:
0: 67 8b 10 mov (%eax),%edx
3: 67 8b 10 mov (%eax),%edx
Notice that they have exactly the same encoding in bytes.

Cody Gray - on strike
- 239,200
- 50
- 490
- 574

old_timer
- 69,149
- 8
- 89
- 168
0
They are the same.
Asuming that you had eax set correctly to point to the address of the first element in the array, would could use movb to put a byte of data in the array using it.

lostbard
- 5,065
- 1
- 15
- 17
-
What does `MOVB` have to do with anything here? If it's just a random example, it's particularly confusing because you cannot use `MOVB` with `EAX`, as shown in the question; a BYTE-sized register is required. Perhaps a better example would have been `MOVZBL`? Or just `MOVL` to store a DWORD-sized value. – Cody Gray - on strike May 19 '17 at 08:24
-
The question asked about char array in eax, so accessing elements of the array would require a movb. ie: movb $32, 0(%eax) – lostbard May 19 '17 at 10:14