3

I'm learning Assembly and I've got a question about array addressing. Suppose rsi holds the address of an array and I want to get the first byte of data starting at this address. Would the following two pieces of code do the job? If so, what is the difference between them, if any? Thank you in advance.

(AT&T syntax)

Version 1

movb (%rsi), %al 

Version 2

movb (, %rsi, 1), %al 
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Theta
  • 231
  • 2
  • 14
  • 3
    Both do the same, but with different addressing modes, the former using an indexed addressing mode, while the latter uses a SIB address mode. Go for the former if possible. – fuz Jun 19 '19 at 02:10
  • 2
    Normally you want `movzx`, aka in AT&T syntax `movzbl (%rsi), %eax` to zero-extend a byte into RAX. You usually only want `mov` to an 8-bit register when you explicitly want to *merge* a new low byte into the existing high bytes. `add (%rsi), %al` is fine on most CPUs, though; you already have an input dependency on the old value of AL so you're not losing anything by avoiding a false dependency. – Peter Cordes Jun 19 '19 at 02:39

0 Answers0