Comparing C to machine language

preview_player
Показать описание
In this video, I compare a simple C program with the compiled machine code of that program.

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

As a web dev, watching this makes me feel like I just swallowed the red pill and saw the real world for the first time.

hattrickster
Автор

I don't care what other viewers say. Keep using paper! Sometimes you have to go the extra mile to make a point. I like your teaching style. Thanks for the videos. Very good info here!

quaxiscorporationforresear
Автор

Idk why but there's something so satisfying about seeing terminal output on paper. Especially C code and disassembled code.

randomoffspring
Автор

When I first started programming in C (mid 80s) I wanted to make sure the compiler was doing a good job and would always check the assembly for timing critical code. After doing this for a while I realized I could write the C code in such a way to influence the compiler to output very efficient assembly. Nowadays, the few times I do this, I'm amazed at how good modern compilers have gotten at optimizing for speed.

RolandGustafsson
Автор

The instruction at 0x10000f63 is moving the result of the printf function (the number of characters written) to a location in memory (even though it isn't used)

craig
Автор

In only 10 minutes, you made me want to learn assembly language. Il looks so simple when it's explained so well. You did a great job, Ben Eater.

ironfox
Автор

One of my college profs was in the Navy and needed to write assembly for the Navy to optimize COBOL code. He wrote it in FORTRAN and turned in the assembly. They had strict goals on lines of assembly to be written and debugged per day. He always met his goals. His reasoning was that FORTRAN was a pretty efficient language, and so he probably couldn't do much better. The Navy never knew they were converting their COBOL to FORTRAN.

BobZed
Автор

I like how the compiler optimised the while(1) into an unconditional jump instead of actually evaluating the expression "1".
I know compilers have been doing that for decades, also it's a very basic optimisation, but I enjoyed seeing it on paper :D

counterleo
Автор

Regarding, moving eax onto the stack. eax contains the return value of the printf call. It's not actually needed by this example. It's probably saved to help a C debugger display what was returned and is likely a nuance of the compiler.

dameonsmith
Автор

7:05 you can actually notice how each variable takes 4 bytes of memory from the way they are located always 0x4 apart from each other

awuuwa
Автор

The eax register will contain the return value of the printf function. Evidently it is being stored on the stack in the expectation that it will be needed later. Presumably you had the optimiser turned off when you compiled it.

lesliedellow
Автор

Compilers were invented in 1952. People in 1951:

MSTendo
Автор

At Uni I made a Snake game in Assembly IA-32 for a course. Never again, thanks.

Pokenopoly
Автор

I understood in theory how C went up to other languages. Now I understand how C goes down to bits. Awesome work.

WickedTwitches
Автор

My 14 year old self back in 2003 would be extremely excited and thankful if someone would explain machine naguage in such a clear way. Thank you and well done!

konstantinospalapanidis
Автор

The type of video that makes you ask "How did people come up with this?"

captainoblivious_yt
Автор

Just a little remark for people wondering why the code generated by the compiler contains strange and unuseful constructs. It is simply because the code was generated with the -O0 parameter which means, no optimization whatsoever. This means that the compiler basically does a nearly 1 to 1 translation of the C code to the assembly, without considering if the operation are redundant, unused or stupid.
It is only when optimization is enabled that the compiler will generate better code.
In this example, for example, it is stupid to read & write x, y, z continuously from memory. An optimizing compiler will assign register in the inner loop and will never write their values to memory. The spilling of the printf return value 'movq eax, 0x14'bp)' will of course not be emitted/

galier
Автор

Man, well done to you, you perfectly explained in 10 minutes what a professor in University had 6 months to demonstrate and still wasn't able to. Really interesting.

thiago_
Автор

0:20 how did you get that infinitely long paper?

LudwigvanBeethoven
Автор

I love how you write on the disassembled code like that. Makes it so much easier to retain and understand. I've wanted to learn to read disassembled code, I'll be doing this to help.

ccgm_harpy