-1

I'm finding a lot of people, myself included, struggle with concepts about specific assembly instructions. Not just because they're intrinsically complex and ridden with side-effects, but because they're often used themselves in obtuse idioms.

Especially when dealing with compiler-generated code which concerns itself not at all with output readability - a rather unique aspect of the language.

To that, we have a ton of questions on instructions that seem very confusing like, for example, LEA (link to search) and TEST (link to search). I would guess there are over a fifty questions on both of them.

It's oftentimes easy to take all of those questions and just duplicate them over to whatever answer Peter Cordes gives, because oftentimes his answers are the most thorough, but there are a ton of good contributions on other answers (some from Intel employees), and often the two questions aren't close enough to warrant the duplicate.

In order to help facilitate organization I've created a few new tags:

Is creating the tags for instructions desirable?

Some people are removing those tags.

This is also the same convention we use elsewhere:

Not to mention, just look at this tag wiki page on x86. Anything to clean it up, even if only a little bit. ;)

29
  • 1
    Would we then need x64-lea and x64-test tags? Commented Apr 17, 2018 at 0:51
  • No, because we still have x86-64 which all the x64 questions should already be tagged with. Commented Apr 17, 2018 at 0:53
  • 1
    @1201ProgramAlarm: no, because x86 includes all versions of the ISA from 8086 to x86-64. And like most instructions, they didn't change behaviour in x86-64. (RIP-relative addressing modes are a new use-case for LEA, though). (Also, x64 is just a shorthand Microsoft invented. It's not used outside of Windows. Using "x86" to specifically mean 32-bit x86 / IA-32 is also a Windows thing. For example, in the Linux kernel you'll find the x86-64 stuff in arch/x86, along with 32-bit x86). I'm not convinced we need these tags at all, but if we do then no, we don't also need x86-64-lea. Commented Apr 17, 2018 at 0:55
  • @PeterCordes RIP-relative addressing just got my yesterday, part of the inspiration for the effort to organize these complex instructions reverseengineering.stackexchange.com/q/18007/22669 Commented Apr 17, 2018 at 1:02
  • It'd be cool if other people would dup-hammer most questions to my answers. :P My ego isn't large enough to dup-hammer the +500 upvotes Q&As about LEA to my answer on Address Computation Instruction -- leaq which explains that it's just a shift-and-add instruction that exposes this capability of the CPU to decode addressing modes, and there's no reason to think that using it for integer math instead of actual addresses is an "abuse" or hack. That's probably one of the intended purposes of putting LEA in the instruction set. Commented Apr 17, 2018 at 1:06
  • 1
    I found that answer INCREDIBLY useful, if that helps with your ego. The wiki for LEA would be a great place for that. =) Your (and our) biggest problem is we're all left trying to figure out how to best organize StackOverflow to get your contributions the most coverage. Commented Apr 17, 2018 at 1:09
  • This kind of comes back to the problem of posting better answers to old questions. I should could post that answer on one of the huge LEA questions, like What's the purpose of the LEA instruction?, but with the OP of that question last seen Nov 2 '09, it won't get "accepted" and will take forever to bubble up to the top. (I left a comment on the question, like I've done with some other LEA questions, but I think those sometimes get deleted :/). This is a general problem on SO; tags aren't usually the solution to duplicates and old mediocre answers. Commented Apr 17, 2018 at 1:18
  • Personally I think the tag wikis are a failure in a way because adding tags really doesn't force a new user to actually read the complete tag info. I doubt that most read the tag intro when they enter the tags in the first place. I base that observation on how many people tag [spring-boot] questions as [boot] despite this in the excerpt/guidance Do NOT use this tag for Spring Boot. Use [spring-boot] instead. . I stopped counting how many times I have had to clean up [boot], but if people even read the excerpt I wouldn't be doing the cleanup which is a daily task for me. Commented Apr 17, 2018 at 2:32
  • @MichaelPetch Be pretty easy to clean it up though, and it must not be too difficult to maintain it: stackoverflow.com/search?q=%5Bjava%5D+%5Bboot%5D+spring I'm not saying tags are implemented flawlessly -- truth be told a bit of hierarchy would do a lot to better the system, but they're far better than not having them. Commented Apr 17, 2018 at 2:44
  • I didn't say it takes a lot of work. I clean it up daily. the intent of the comment is to show that people who use the tags don't actually read the guidance in the pop up let alone the complete wiki. Maybe they would if users were some how forced to read the tag wiki info for a tag they use for the first time, but alas they'd probably still ignore it. Commented Apr 17, 2018 at 2:49
  • 2
    But that's the point, with the something simple like [boot] (which is often related to assembly) people don't read it because it tells them about spring-boot specifically. It isn't a long tag wiki, but people don't read it. Whether the x86 tag wiki is long or short - people likely won't read it whether it had 10 words or 10,000. People who use tags really aren't made to actually read them, and for the most part I believe n00bs ignore the info altogether. Commented Apr 17, 2018 at 3:02
  • 1
    I wish SO had a better mechanism for showing new users that tag wikis exist and often have well-curated collections of links. I've heard from many people that they didn't know stackoverflow.com/tags/x86/info even existed, even some experienced users. (Not just that they didn't know there was anything good on that tag wiki, but the entire concept of tag wikis.) I'd been answering asm questions for months before I found out about them. Commented Apr 17, 2018 at 3:17
  • 1
    Related (and more general) discussion: Should tags be created for functions of APIs?
    – BDL
    Commented Apr 17, 2018 at 7:56
  • 1
    Prove me wrong: all that content you maintain and all those questions you've answered -- have you ever personally linked to it once as a reference? Yes, I link the x86 tag wiki all the time. Often something like "see agner.org/optimize, and other performance links in the x86 tag wiki." Or for the section on ABI docs, or the debugging section at the bottom. I've definitely had people thank me for that, or say it was full of good stuff. It's definitely a mess, but not so messy that it's unusable. I use it for find canonical dup links. Commented Apr 17, 2018 at 17:36
  • 2
    @MichaelPetch I don't have the stats on how many people read tag wikis but I do and I'm happy they are here.
    – jrh
    Commented Jan 3, 2022 at 14:24

2 Answers 2

20

I'm mostly against creating tags for specific x86 instructions, and I am definitely against in the case of lea and test. I think questions about lea and test fit great under the existing general tags like x86.

I just don't think that in most cases a single x86 instruction that is described in about a page of text is broad enough for an entire tag. Yes, lea probably generates more questions than average due its relative ubiquity, its use in "intro to assembly" courses and its confusing nature where it calculates an address but doesn't use anything at its location, unlike all (?) other uses of [addressing expression], but that just needs one high quality answer.

By the way, I was among those that were deleting the x86-lea tags until I saw that the tag had been applied to more questions than I thought and gave up (and added them back to the questions where I had removed them since I became aware of this ongoing discussion on the topic). In doing this, I realized that a lot of the lea questions are still not duped against a canonical lea question but should be.

I also don't think test is interesting enough for its own tag. After all, it's exactly like and without writing the result, so should we have tags for and as well? It's a slippery slope because there are at least about a thousand instructions and I'd bet that most of them are probably more complex than lea or test.

Consider your other examples. INSERT, UPDATE and MERGE are pretty much the three verbs that form the backbone of modifications in SQL and have enough variations, considerations and caveats to fill a book. Similarly for things like HTML forms which are a large and complex topic (at least because anything in HTML is partly complex due to browser differences). Regex is less clear to me - do you really need a regex-negation topic? Still, even there, it seems like an effort has been made to create about a dozen top level topics in the regex-* tree to split up the topic. That's much coarser grained and probably more useful than per-instruction tags. I agree though that it's partly a matter of taste.

One might wonder what the harm is in having the tag anyway? Well, one big downside is that people may tag their question x86-lea and not x86 (as often happens with questions tagging c++11 and not c++), and then no one who follows the x86 tag will see it. To effectively follow the x86 related discussion you'd have to constantly update your follow list to include the growing set of instruction-specific flags...

13
  • 1
    Or maybe a high-quality answer for each of AT&T, NASM, and MASM syntax? It's unfortunately difficult to dup-close questions when they're duplicates except for x86-16 vs. x86-64, or asm syntax, even though the concepts are identical and so is the resulting machine-code. Those kinds of differences are confusing to people that don't understand asm and machine code yet, i.e. how the language really works. It's a thorny problem, but I agree a tag isn't the right solution. Great point about mis-tagging; that's another downside I hadn't considered. Commented Apr 17, 2018 at 1:30
  • 2
    If it alleviates your concerns, people asking questions will always be pretty bad at tagging them -- it's more for those experienced to organize the site so those inexperienced can navigate it. =) To that extent, StackOverflow does support wildcards in tags [tag:c++*] for example, and you can even create a feed for it. Commented Apr 17, 2018 at 1:31
  • @EvanCarroll - people might be bad at tagging questions, sure, but most of the relevant questions still seem to pop up as x86, so that system is mostly working. My concern there is that adding a very narrow x86 tag exacerbates the problem because some people will use that tag and not the primary one. Using wildcards helps that problem though (I didn't know about it: seems to work in "favorite tags" too).
    – BeeOnRope
    Commented Apr 17, 2018 at 1:36
  • 1
    @BeeOnRope the question is to what extent does your problem persist with wildcard searches? the advantage is that when I want to read all of the collective wisdom on x86-lea I can do so with great ease including the old answers by Intel employees with yours and Peter's stuff thrown in. That's relatively hard to do now. Especially when so many good answers get lost in the dupe-mix (as we try to find one golden answer that addresses everything.) Going back to Peter's answer. That's one of the best with less than 1,500 views and closed as dupe. Commented Apr 17, 2018 at 1:41
  • @EvanCarroll - the x86-lea tag isn't going to let you do that because almost no one is going to know there is an x86-lea tag and apply it to their question! You pretty much need a curator that is willing to keep searching for lea related questions and update the tag. Personally I find Google to mostly be a better search engine for SO than trying to use the internal search engine in combination with tags, etc. The problem with subscription is mostly gone for me with wildcards I think (but this doesn't apply to presumably many others already following x86 and not reading this thread).
    – BeeOnRope
    Commented Apr 17, 2018 at 1:46
  • @EvanCarroll: should I dup the other way, making Why is lea instruction named for memory addressing when it just performs arithmetic? a dup of the question I answered? After posting my answer, I noticed that Ross Ridge had already made the same basic point (with info on original 8086) in fewer words on a question asking the same thing, so I dup-hammered it. Commented Apr 17, 2018 at 1:46
  • 2
    I started removing the [x86-lea] tag last night and was going to request that the x86-lea tage be burniated. I started by removing 3 of them hoping that Evan might consider there may be an issue. He did stop, but today I found the tags [x86-cmp] and [x86-test] appearing as well as [x86-cmp]. I see no value in having a tag for each and every instruction that may have a question asked about it. Most of the [x86-lea] tags can probably be duplicates of of maybe 3 or 4 questions. Rather thancreate tags, I'd rather see them become duplicates of the others with good answers. Commented Apr 17, 2018 at 2:01
  • I drew PeterCordes attention to this issue in a comment to something he answered and I pretty much got the feelings I had expressed quite nicely. I have actually now gone and finished the job I started last night and removed all the [x86-*] tags involving individual instructions. I'll post to meta to burniate each of them and see where the discussion goes. Commented Apr 17, 2018 at 2:03
  • If someone wants to put an extra entry in the [x86] tag about LEA vs MOV, how does LEA work? etc - be my guest, I'd accept that over the individual instruction tags. We do that already for a variety of other x86 topics. Commented Apr 17, 2018 at 2:05
  • Regarding the comparison with sql-insert, sql-update etc - my argument would be that there are a variety of issues that may arise relating to those tags where you may find a wide selection of answers related to a number of topics. I do not believe the same logic applies to specific assembly language instructions given that most questions are probably answered with a link to the instruction set reference. I think the x86 instructions are too small a unit to consider as additional tags. Most of the LEA stuff are probably answered by 3 or 4 questions, TEST same thing, and same with CMP. Commented Apr 17, 2018 at 2:17
  • 3
    I doubt that most n00bs who add the x86 tag to their own questions actually read the tag info itself. If they did they'd likely find most of the questions they ask are already answered. I mean I am sure that i could spend all day adding [x86-div] and [x86-idiv] tags and those boiled down to some very specific questions as well (to which the [x86] tag info already link to). And I don't think they warrant a new tag. Commented Apr 17, 2018 at 2:19
  • You have no faith in the tag system or the people using it, that's fine. I'm not sure why you want no one else to use it or why you'd want to stop other peoples efforts that do use it. Perhaps you can explain here rather than starting a new topic to burninate tags currently being discussed elsewhere? Commented Apr 17, 2018 at 2:47
  • 1
    @EvanCarroll : because I consider machine language instructions to be synonymous with the architecture tag. I see all the extra tags as noise which could add an additional level of indirection that people likely won't follow anyway. Commented Apr 17, 2018 at 3:35
10

TL:DR my main objection is that there's no scope for future good questions about LEA specifically. It's not an open-ended topic, not really. In assembly language, each instruction makes a specific change to the machine's architectural state. LEA can't even depend on memory contents, only GP integer registers. People just need to understand this, not read or ask a zillion questions about each different context you might use it in.

Questions about how to efficiently get from machine state A to machine state B might or might not have LEA as the answer, but are covered perfectly well by [tag:x86]

You can search for x86 LEA questions without a tag, either with google for site:stackoverflow.com x86 "lea", or on SO itself with [x86] code:lea.


There's a problem here with lots of duplicate and near-duplicate questions, but I'm not convinced tags are best solution to the problem. The OP suggests that tagging them all will make it easier for future readers to wade through the pile, but there's so much duplication that I don't think that's useful. One to four good answers and the x86 manuals are all that's needed to explain LEA itself, and x86 addressing modes.

Links to such answers from the x86 tag wiki would help, but I wish SO had a better mechanism for showing new users that tag wikis exist and often have well-curated collections of links. Most new users, and many experienced users, don't know they exist!

I've already written (attempts at) canonical answers about LEA and also addressing modes. There is some agreement that at least the LEA answer is good. Now (as discussed in comments) the problem we have is of directing searches to a new good answer on a topic that already has lots of old highly-voted old answers. With an OP that's not been seen since Nov '09 on one of the highest-voted LEA questions (What's the purpose of the LEA instruction?), it's not going to get marked accepted if I posted a version of it there, so we have the classic SO problem that's been discussed many times on meta. (But usually not also with lots of duplicates with good answers on the lower-voted questions, too.)

Maybe tags are useful to catalogue the current mess, even if we don't want any future questions in those tags. But this is definitely now how SO should work in theory; real duplicates should be closed, not tagged with a subject. In theory there is no difference between theory and practice. In practice there is.

It's hard to merge because there are so many answers, and differences in x86-16 vs. x86-64 vs. 32-bit, and AT&T vs. NASM vs. MASM syntax make it look ugly (and confusing for beginners) to group multiple answers together with code like
lea dx, symbol and leaq symbol(%rip), %rdx, and lea eax, [symbol + edi].

I don't think tagging all the LEA questions so people can wade through them more easily is the Stack Overflow way of handling things. Maybe there's more value for beginners in all those different ways of repeating the same thing than I think there is; I'm not a beginner so I can't tell. (I understand that some people do find asm hard or confusing, but I really can't get inside their heads and understand what's so hard about creating steps for the CPU to follow that results in the computation you want.)


The main reason not to introduce an x86-lea tag is: There is basically no scope for asking a new question just about LEA that isn't already a duplicate. Creating a tag normally implies that there's room for an open-ended number of future questions about that topic. lea could appear as part of the code in any number of questions about blocks of x86 code (debugging, reverse-engineering, or whatever), or how to efficiently implement something, but I think we all agree the tag shouldn't apply unless the question is mostly about lea itself.

So there are about 2 or 3 total that aren't just duplicates. (How does its syntax work in asm source and what does it do? How to use it for multiplying integers? How it runs internally on AGUs vs. ALUs and with what latency / throughput and whether it's worth using 2 LEA vs. one imul eax, ecx, 37. And maybe it's "intended" purpose, of pointer math vs. exposing the CPU capabilities for arbitrary use.)

We already have questions for all of those things. I don't see there being scope for any future good question specifically about lea, except maybe performance tradeoffs on some past or future CPUs where it's different from Sandybridge-family or Bulldozer / Ryzen. But that would be more a question about that microarchitecture than about the instruction, IMO, and wouldn't need an x86-lea tag.

myself included, struggle with concepts about specific Assembly instructions not just because they're intrinsically complex and ridden with side-effects

Huh? The manual for lea documents the complete exact behaviour of LEA in all situations. If you found it complex, you were reading explanations like the ones that say "it's for addresses" which lead readers down the wrong path, confusing them when they see LEA used for integer math on non-pointers. It makes LEA sound more "special" than it is.

Or, it's not lea that's complex, it's x86 addressing modes that are (somewhat) complex, and the syntax differences between different assemblers (MASM vs. NASM vs. GAS) is an added level of complexity. And the complexity of machine code decoding similarly in 16 / 32 / 64-bit mode, as you found on Disassembly shows LEA with RIP?. That's not an LEA issue; you'd have had exactly the same issue with 32-bit mov eax, [disp32] disassembled as mov eax, [RIP+rel32] if interpreted as 64-bit machine code. (Of course you wouldn't have had it at all if people hadn't been going on about using lea for 32-bit constants instead of the shorter and faster mov r32, imm32.)

If the real reason for most questions about LEA isn't LEA itself, but some other aspects of x86, then I don't think having an x86-lea tag helps us that much. Or we're on a slippery slope to having questions about every x86 instruction, and there are far too many of them for that to make sense. Intel already publishes nice x86 instruction-set manuals, and HTML versions of it exist, and see links in the x86 tag wiki.

I think you want LEA questions to be a way for people to learn about all the complexity you can encounter when using it. But some of the things, like addressing modes, can also come up when using them with other instructions.

Your idea of cataloguing all the x86-lea questions so people can go through them all seems like you're creating a repetitive and not great quality book to teach x86 in general. Because to understand all the answers, you have to learn more than just LEA itself.


In my (not very humble at all) opinion :) most (but not all) of what's been written on SO about LEA is either bogus or covered in my answer on Using LEA on values that aren't addresses / pointers?, which says pretty much everything you need to know to understand LEA, when to use it, how it works, and why it's part of the instruction set in the first place. (In ~1100 words, formatted to be skimmable for the part you want. It's so long because I covered the evolution from 8086 to 386 to x86-64, and the evolution of addressing modes). Along with links to the ISA reference manual entry for lea, and docs for addressing modes, that just about covers it. But it's still short enough to be a good dup target for most LEA questions; I tried (and probably only partly succeeded) not to get too bogged down in random details.

Beginners that think of asm as a compiled language with variables like C get very confused. I think some people don't understand that lea dx, symbol has exactly the same effect on the architectural state as mov dx, OFFSET symbol (a MASM syntax example that's come up at least once), except for advancing IP by 1 extra byte. Everything in asm is bits / bytes / integers, including pointers. Also including the bit-patterns that represent floating-point numbers.

I think the root cause of most of the lea questions (and upvotes on them) is lack of understanding this, and / or failure to read the manual. Or the real question is about addressing-modes or assembler syntax, rather than the LEA machine instruction itself.

Other answers (on other questions) mostly say the same things in different ways. This is not necessarily a bad thing, as some people may grok ideas more easily the way others express them. But it's still duplication. (And the good is mixed with outdated or mis-information about performance, or claims I disagree with about the "intended" purpose of LEA, or bad advice like using lea dx, symbol instead of mov dx, offset symbol, because some people think of asm as a language of its own, rather than a way to express machine code).

I'm not such an egomaniac that I'm going to dup-hammer all the LEA questions as duplicates of my canonical answer, though. It's (IMO) unfortunately not the accepted answer on the question where it's posted, though, and the question uses AT&T syntax, so it's not a perfect dup target for many of the questions. Maybe I should rewrite a version of it with NASM syntax throughout and post it somewhere else, like maybe a new Q&A.

If other people agree with me, though, feel free to close-vote as duplicate (and upvote my canonical answer). I think that's the right move for most of them, but obviously I realize that I'm biased here. I know a lot of people like my answers, and Evan says he found that one very helpful, but self-promotion needs to have limits.


Given the limit of 5 tags per question, there sometimes isn't much room for super-specific tags if your question involves lea or how/when to use it. [x86] [assembly] [micro-optimization] [performance] [x86-64] already takes up all 5, and doesn't leave room for [gcc] or [clang] if asking about compiler code-gen choices, or whatever.

I think these tags are too specific, especially x86-cmp and x86-test. Maybe x86-condition-codes would be more appropriate? I think the real question is usually what ja vs. jl means after cmp eax,0 or equivalently but better test eax,eax, or about the test eax,eax idiom itself. But that's one question; we don't need a tag, we need dup close votes. (I often do dup-hammer to that target, because it's a simpler question and less syntax-dependent.)

3
  • Sorry this answer is so long, I think I ended up repeating myself / making the same point multiple times different ways in different paragraphs. Commented Apr 17, 2018 at 6:48
  • 4
    If your point was 'we shuld not create tags that map to sections in the Intel assembler/user manuals', then I agree. Commented Apr 17, 2018 at 8:16
  • @MartinJames: Yeah, that's the wrong choice in this case, but in the general case that's not exactly the reason I'm suggesting for rejecting it. And the OP isn't wanting to make tags for every section or entry in the manual (but with separate tags for x86-cmp and x86-test instead of just one called x86-flags, yeah that's obviously terrible for the exact reason you give). I was mostly arguing that LEA only needs like 4 total non-duplicate questions at most about it specifically, and we should probably only have tags for open-ended subjects. Commented Apr 17, 2018 at 8:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .