2
movsd   (%rdx,%rsi,8), %xmm0    ## xmm0 = mem[0],zero

What does this line do? Especially (%rdx,%rsi,8)? (x86-64 architecture computer) I produced an Assembly file from a C code that does matrix multiplication, involving 3 loops. I found bunch of manuals but nothing really has a reliable information, even the "official" looking ones.

My Mac OS X is producing this in GAS syntax, so mov instruction of its variations are in order of:

mov source dest

But no one explains what happens when something like (%rdx,%rsi,8) suddenly joins the party.

Please help me learn more about this. Thank you.

Below link, slide 7 is the most related information I could find (but it probably is in Intel syntax which has source and dest flipped) https://www.bowdoin.edu/~sbarker/teaching/courses/spring16/its/lectures/lec15.pdf

Jester
  • 56,577
  • 4
  • 81
  • 125
Leonard
  • 2,978
  • 6
  • 21
  • 42
  • 3
    See for example the [gas manual](https://sourceware.org/binutils/docs/as/i386_002dMemory.html) or any of the gazillion at&t references including the [at&t syntax tag wiki](https://stackoverflow.com/tags/att/info). Also you can switch your compiler to produce intel syntax. – Jester Jul 20 '18 at 14:40
  • Wow that is almost impossible to find. Thanks ! I think figured it out now. I don't understand why anyone would downvote my question without any explanation. – Leonard Jul 20 '18 at 14:47
  • @Leonard You are asking a question about the syntax of a programming language without ever having checked out the reference for that programming language. That's why people downvote you: if you had searched for and read any reference for AT&T syntax, you wouldn't have to ask this question. – fuz Jul 21 '18 at 13:49
  • @Leonard: If you *have* attempted research but didn't find anything, nobody can know that unless you say something about it. SO gets lots of bad questions every day from things that are (unlike this) easy to google, so http://idownvotedbecau.se/noresearch/ is often justified. That link explains how to show that you did try to find the answer. Claiming that the official manuals didn't have reliable information seems unlikely, unless you only found manuals for Intel syntax. – Peter Cordes Jul 22 '18 at 07:40
  • Nope. You are all just assuming that I haven't done a research, and honestly that feels patronizing. Just remember this: A beginner is one doesn't know what one doesn't know. Even if the beginner looks at the manual, one may or may not be able to identify the necessary information and make connections between them. I looked at the documentations but couldn't find what I needed because I simply wasn't knowledgeable enough. That should be more than enough reason for me to ask a question. – Leonard Jul 26 '18 at 05:49
  • another easier to find duplicate: [What does a hexadecimal number, with a register in parenthesis mean in Assembly?](https://stackoverflow.com/q/31735903/995714) – phuclv Aug 09 '18 at 01:56

1 Answers1

6

This is the so called AT&T (or GAS) syntax. It's an alternative to more popular Intel syntax. In AT&T syntax the address operand syntax is:

segment:displacement(base register, index register, scale factor)

where most parts are optional. In your example %rdx is the base register, %rsi is the index register and 8 is the scale factor.

What it does is to load the lower 64-bit part of the xmm0 register from the address rdx + rsi * 8. In Intel syntax it would be:

movsd   xmm0, [rdx+rsi*8]

which is a bit more intuitive (at least to me).

cyco130
  • 4,654
  • 25
  • 34
  • Thank you. If you can, could you please upvote my question? Not for popularity, but so that other people can actually find this post and get help. – Leonard Jul 20 '18 at 14:53
  • 1
    Someone decided to just downvote this question with no explanation, which is really rude, so I worry that other people won't find this and get help. – Leonard Jul 20 '18 at 14:54
  • See [Why isn't providing feedback mandatory on downvotes, and why are ideas suggesting such shot down?](https://meta.stackoverflow.com/q/357436/547981) Also expect more anonymous downvotes due to the new "Code of conduct". – Jester Jul 20 '18 at 14:57
  • 2
    @Leonard this question has 100% some duplicate here (but I'm too lazy to search for it ... also to downvote you for not searching... I just so so produced this comment JFYI, I wonder why you didn't find it while searching for ... BTW I just tried for fun Google "x86 at&t memory operand syntax" -> first link https://en.wikibooks.org/wiki/X86_Assembly/GAS_Syntax - it's right there, point "4 Address operand syntax" ...) (so I guess you were just unable to guess the correct words, because otherwise you should check what kind of censorship is applied to you, if your search engine doesn't find it) – Ped7g Jul 20 '18 at 15:01
  • 2
    @Ped7g In all fairness, it is quiet hard to find any info without already knowing that it's AT&T syntax. – cyco130 Jul 20 '18 at 15:05
  • 2
    @cyco130 probably that, plus even if you know you are searching for "AT&T" and "GAS" syntax, you still may be unaware of words like "memory operand" and similar... basically somebody completely new to assembly needs good book or mentor (or both), or some top quality "tutorial", but that's just a kick-off before reading some good book(s) and most of the tutorials will probably not bother enough with technical terms to stay short... It's probably tough to find a good resource. That's where https://stackoverflow.com/tags/x86/info may help a lot, it's full of sort-of-verified resources. – Ped7g Jul 20 '18 at 15:10
  • @Ped7g Hello Ped7g, I think it is very very wrong to assume that I or people who ask questions here did little or no research. One big factor is the experience and knowledge gap. For beginners like me, I'm not only used to syntax, but often I don't exactly know which term I need to use to look for my specific situation. For people who know the concept and keyword it is easy to find, but for a beginner, it can get almost impossible just because I don't know that one single keyword. I thought this was more related to `mov` instruction rather than GAS syntax itself, – Leonard Jul 20 '18 at 15:12
  • @Ped7g and yes meanwhile I comment people have answered. A beginner is someone who doesn't know what he or she doesn't know. I think it is only natural for one to resort to asking questions after reasonable effort. (And plus you have helped me before so I think you know that I'm not that lazy :) ) – Leonard Jul 20 '18 at 15:15
  • 1
    @Leonard I understand your confusion. My general advice to beginners is: if you want to learn a language get yourself a tutorial for that language and work it through front to back before asking any questions at all. Many questions you get during your studies will be resolved in later parts of the tutorial, many tutorials like to leave unclear parts in one section to have a good motivation to introduce a new concept in the next section. Especially with assembly, it's a really terrible way to learn the concepts by starting with random code snippets and trying to figure out things on your own. – fuz Jul 21 '18 at 13:55
  • 1
    So please, do yourself the favour and use a proper tutorial. if you just try to wing it by cobbling together random code snippets and try to make sense of them, you are probably going to have a lot of misconceptions and gaps in your understanding because you are going to have a hard time seeing the big picture. Please don't try to learn like this. Even if it's tedious, you should really work through a tutorial. – fuz Jul 21 '18 at 13:56