Just Enough Assembly for Compiler Explorer - Anders Schau Knatten - CppCon 2021

preview_player
Показать описание
---
Every other conference talk these days seems to be showing off some code on Compiler Explorer. But what does all that Assembly actually mean?

In this talk you'll learn the very basics of X86 Assembly and the X86_64 calling convention, just enough to understand the full Assembly listing of simple functions on Compiler Explorer. No previous experience with Assembly is necessary, but a basic understanding of C or C++ is useful.

After this talk you will:
- Be able to paste code from your own project into Compiler Explorer, and either understand the Assembly output or know how to simplify it until you do.
- Have a solid understanding of the fundamentals, so you know what to search for and understand it when you need to know more.

---
Anders Schau Knatten

---

*--*
Рекомендации по теме
Комментарии
Автор

One of the best introductions to x86 64 Assembly.

alienwaremx
Автор

Best comprehensive intro I've found so far for assembly for C++ guys. Kudos to the presenter !

sampathsubasinghe
Автор

that was very clear and informative, thank you!

seethe
Автор

Very nice and informative talk, thank you!

HaykKarapetyanGP
Автор

Thanks Anders, learnt a lot from this talk :)

annilator
Автор

It uses eax instead of rax, because you're not using 64-bit numbers. There is no reason to. The compilers optimize for small binaries, and using the 64-bit register get encoded to longer instructions, I believe another byte or so, possibly more in some cases. So, if you are using 32 bit numbers, encoding a 64 bit register increasing the binary size for no good reason, the compiler is smart enough to realize you are using 32 bit numbers. When the value gets copied to a 64 bit register, it can just zero extend for free, basically.

simonfarre
Автор

Instead of moving value between registers directly,

```
move eax, edi
```

Why the compiler first moves the value to memory then copy to the register like below?

```
mov dword ptr [rbp-4], edi
mov eax, dword ptr [rbp-4]
```

kai
Автор

He didn't answer the question at 24:30, why use `lea` instead of `mov`. The question was "why don't we take off the dereference operator (square brackets) to and use actual value stored in the register, substracting 8 on the fly: `mov rdi, rsp - 8` and I still can't find the answer other than "that's just how it is".

privetvastutnestoyalo
Автор

I admit this is insane - they even have risc-v )

browaruspierogus
Автор

I like to code in assembly, but i never use a compiler, so i do not need to use the calling convention.

maxmuster
Автор

Right off the bat I took issue with the register having the value two being copied as a literal 2 instead of the expected 1 . This appears as instead of . A register containing 4 should be and not . Maybe I'm just a noob nit picker but ? If the register can also contain instructions as binary things could get pretty screwed up ! Obviously I'm a beginner, and yet wtf ?---I get it . It's just an abbreviation for a 64 bit binary .

edwardmacnab
Автор

Just for fun! Your name sounds like an Egyptian Pharoah.

bmutthoju
Автор

off topic: as a C++ and computer science teacher/tutor I really dislike tutorial/test programs that have problems like the presenter showed in the slide at the beginning of the presentation. we teach students that globally scoped entities are something to be suspicious of, that they should use descriptive variable names, and that the code they write should directly express the solution to the problem they're solving - and then support material like what the presenter showed throws not only C++ standards out the window but also general good programming practices, then I get students who think their code isn't clever if it's not code golf, not to mention how those things slows adoption of C++ core guideline standards as students then think the core guidelines are the awkward and odd style... ahem, any way carry on lol

georganatoly