1

Stuck with study of assembler

mov byte ptr [rax+rdx-01],00

RAX=00000004
RDX=2295EA3B878

and

mov [r10+rsi],al

RAX=0000000000000065
RSI=000002295EA3B878
R10=0000000000000000

It's clear about mov al byte ptr. But i don't understand what means [rax+rdx-01] and [r10+rsi] where rax and r10 not pointer.

In most cases i faced with [RAX+C1] where rax is pointer and C1 is offset but i have no idea what meaning when register store some value, but not a pointer

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
user199588
  • 539
  • 2
  • 6
  • 21
  • 3
    `rax` may not be a pointer, but `rdx` could be. – Raymond Chen Feb 19 '20 at 20:21
  • The `byte ptr` means that an address is formed, and is needed because the size of `0` can't be inferred. In `[r10+rsi]` the `rsi` will almost certainly be a pointer. – Weather Vane Feb 19 '20 at 20:24
  • Raymond you mean it`s same like [rsi+0] offset or what? – user199588 Feb 19 '20 at 20:29
  • Yes, that's why Intel syntax uses `+` for both registers and constant displacements, of course. Intel's manuals document addressing modes; you can consult them or google for any detail you're wondering about. – Peter Cordes Feb 19 '20 at 20:30
  • So if i understand righht there is no matter of sequense [pointer+offset] or [offset+pointer] and 0 offset for the cases where r10 !=0 ? – user199588 Feb 19 '20 at 20:32
  • Yep, addition is commutative so in this case it doesn't matter which register you think of as the pointer and which one as the offset. Note that if you want to include a scale of 2, 4 or 8 (see addressing modes link below) then it does matter as the scale will only be multiplied by the offset value. – Nate Eldredge Feb 19 '20 at 20:39

1 Answers1

5

You might like to read about x86 addressing modes.

[rax+rdx-01] refers to the address computed by adding rax and rdx and subtracting 1. This is commonly used if one of rax, rdx is a pointer to an array (the "base address"), and the other is an index into that array. So this might be generated by C code such as

char *array = ...;
size_t i = ...;
// ...
array[i-1] = 0;

where the value of array is stored in rax and i is in rdx, or vice versa. You say here that rax is not a pointer, but perhaps rdx is.

Likewise, mov [r10+rsi], al could correspond to

char *array = ...;
size_t i = ...;
char c = ...;
// ...
array[i] = c;

where r10=array and rsi=i (or vice versa) and al=c.

Nate Eldredge
  • 48,811
  • 6
  • 54
  • 82
  • to be clear in first case 2295EA3B878+04-01 means that i need address 2295EA3B87B? – user199588 Feb 19 '20 at 20:34
  • @user199588: Looks to me like you get 2295EA3B87B, yes. – Nate Eldredge Feb 19 '20 at 20:36
  • You said `where the value of array is stored in rax and i is in rdx, or vice versa. You say here that rax is not a pointer, but perhaps rdx is`. i guess you mean rdx is array and rax is ` i ` ? Becouse rdx is a pointer – user199588 Feb 19 '20 at 20:39
  • 1
    Yes, it appears that your example would correspond to having `rdx=array` and `rax=i`. My point is that you could also use the same instruction if you had chosen to use the registers the other way around. – Nate Eldredge Feb 19 '20 at 20:41