Comparing C to machine language

2015 ж. 7 Ақп.
5 010 948 Рет қаралды

In this video, I compare a simple C program with the compiled machine code of that program.
Support me on Patreon: / beneater

Пікірлер
  • 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.

    @hattrickster33@hattrickster334 жыл бұрын
    • Yeah I know how this feeling too. It just kicks in like "Oh we evolved all the way to here, jeez"

      @pyrookil480@pyrookil4804 жыл бұрын
    • As an electrical engineer this makes me say "here we go again".

      @NPC-rq9tp@NPC-rq9tp4 жыл бұрын
    • @@hattrickster33 you could say that c is one of the closest to the metal in the high language class.

      @dasemmiyogurt6288@dasemmiyogurt62884 жыл бұрын
    • @@hattrickster33 well compared to other languages, C is probably the closest thing to machine code, but C itself is still a high level language

      @deschia_@deschia_4 жыл бұрын
    • @@deschia_ We did testing on it back in college, comparing hand-coded assembly, C, Fortran 77, PL/1, and last (and least) Cobol. C and Fortran compilers did a reasonable job of producing something pretty close to what we did in assembly. PL/1 threw in some extra overhead which I think was related to memory management. And Cobol created a scary pile of machine code that we decided not to look into too deeply. I think it was summoning something from Cthulhu.

      @jimruby9657@jimruby96574 жыл бұрын
  • 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!

    @quaxiscorporationforresear5557@quaxiscorporationforresear55578 жыл бұрын
    • +JP Aldama I agree. There is something I love in making notes on printed text. Plus, you can explain something so much quicker on paper because drawing and organising information is quick and intuitive, whereas doing such on a computer takes time to plan out.

      @HarmonicaMustang@HarmonicaMustang8 жыл бұрын
    • They don't teach us that because the last forty years of computing history has been all about NOT reinventing the wheel. People got tired of having to start over every time a new computer came around, so we standardized our hardware, and operating systems (most notably, Unix) became portable between CPU architectures. Developers (the vast majority of them, at least) stopped caring about the low level stuff because they didn't need to anymore, and the computer science world progressed towards higher level things. They don't teach us how to actually do it because to go from nothing to even just a bare bones, functional shell environment by yourself would take years and years of development. So they just teach us the theory behind how it works and leave it up to you to do that stuff, if you want to. I feel where you're coming from, though. I used to feel the same way and I tried to learn things from the bottom up, but trust me; you'll be a lot better off if you start with the higher level systems and work your way down. It gives you kind of a bigger picture to see where the little things fit into.

      @ianhamilton350@ianhamilton3507 жыл бұрын
    • It's not a problem, though. Nobody teaches 8-bit assembly because nobody uses 8-bit assembly anymore except hobbyists, and hobbyists already have many resources available them to learn from. Not to mention that most people interested in 8-bit assembly grew up with computers that ran it, and thus already know it! In fact, we have access to all the resources they did and more with the help of the internet. We can't expect the world to cater to our extremely niche interests. That's why we're all so grateful to Ben for sharing his knowledge and guiding us through the process

      @ianhamilton350@ianhamilton3507 жыл бұрын
    • In the UK assembler is taught as part of A-level electronics. The kids love it

      @markhesketh9467@markhesketh94677 жыл бұрын
    • Not just hobbyists. Assembly language can also be useful for hacking. I'd imagine it be really useful for reverse engineering, finding certain exploits, and malware development.

      @ricardocolon5122@ricardocolon51227 жыл бұрын
  • 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@RolandGustafsson2 жыл бұрын
    • this guy is the real dela

      @dukeelma7ala@dukeelma7ala Жыл бұрын
    • I would like to learn to make the compiler more efficient. But I just started whit c and c++.

      @user-iu8ps1yo1w@user-iu8ps1yo1w Жыл бұрын
    • ​@@user-iu8ps1yo1w theres not much you can do now in days lol. Also not really worth it imho because of how good compilers have gotten. But there are some reserved keywords in C and C++ that can tell the compiler certain things. All i really know about is marking functions inline can speed up the compilation process sometimes and can boost performance. Again, its not really worth doing that because the compiler should do all of that for you when necessary (if you mark the compiling command with -O3) its pretty easy to look up and youll eventually get the hang of it when you code more

      @The_Codemaster144k@The_Codemaster144k Жыл бұрын
    • @@user-iu8ps1yo1w Why would you? What's wrong with your compiler that you want to upgrade it already as a beginner? Maybe you should just try another one? Msvc, mingw or clang.

      @squizex7463@squizex746311 ай бұрын
    • @@squizex7463 Maybe just due to curiosity? Or because a man wants to understand things better or just keen to do hard things? By your logic, one doesn't have to do anything because all the good things, by which you can do your software, are already written. So all you left to do is use them, which's boring af

      @grenadier1653@grenadier165310 ай бұрын
  • 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@awuuwa2 жыл бұрын
    • same thought!

      @SreenikethanI@SreenikethanI2 жыл бұрын
    • Ah, I thought that the memory adresses were just chosen "ranndomly" by the compiler". But this makes me wonder though... how does the computer know how much space a variable takes up? Nothing in the machine code in the video shows that. What if the variable took up more than 4 bytes?

      @aurelia8028@aurelia80282 жыл бұрын
    • ​@@aurelia8028 in many languages you determine the datatype right? in "int x = 2;" an "int" is for example always 4 bytes and "double y = 5.4;" would make it 8 bytes etc *edit:* the size also depends on your platform... as mentioned by another commenter below, an int may be 2 bytes as well

      @SreenikethanI@SreenikethanI2 жыл бұрын
    • @@SreenikethanI Sort of, it depends on hardware and/or compiler. `int` can be 2 bytes as well.

      @TeoTN@TeoTN2 жыл бұрын
    • @@TeoTN oh right yeah

      @SreenikethanI@SreenikethanI2 жыл бұрын
  • Idk why but there's something so satisfying about seeing terminal output on paper. Especially C code and disassembled code. Mmmmmm.....

    @randomoffspring561@randomoffspring5617 жыл бұрын
    • Too bad its at&t syntax though. Eww.

      @randomoffspring561@randomoffspring5617 жыл бұрын
    • yea lol intel 4ever

      @natetwd1990@natetwd19907 жыл бұрын
    • random offspring Ikr

      @user-dl9cw8mi3f@user-dl9cw8mi3f7 жыл бұрын
    • random offspring , you deserve a stack of tractor-feed paper with alternating green & white lines :)

      @massimookissed1023@massimookissed10237 жыл бұрын
    • IKR can't explain it either, but it just looks so satisfying and perfectly organized. something like asmr

      @MrBruno7447@MrBruno74477 жыл бұрын
  • 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)

    @craig1231@craig12314 жыл бұрын
    • Thank you! This comment should be pinned.

      @mrwensveen@mrwensveen4 жыл бұрын
    • I never figured out what the printf() was supposed to be; It is implemented in 16-bit code that has to keep two registers pointed to the same address; It runs much much slower than what makes sense to me; A data-block like 1024 or whatever shroud be alloc at init; Like above while ( int ) I found much established C/S to be Horror Code of the Damned written by relatives of the Munsters to prevent use of sanity checks like if do while which works much much better due to zero based indexing

      @ChiDraconis@ChiDraconis4 жыл бұрын
    • @@opus_X And I get paid well for it 🤣

      @craig1231@craig12314 жыл бұрын
    • @@craig1231 how much time u spend in learning machine code, i want to learn too!! Its cool

      @osmarmartinez1174@osmarmartinez11744 жыл бұрын
    • So you're saying the code was suboptimal in execution time?

      @louislebel2995@louislebel29954 жыл бұрын
  • 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@BobZed3 жыл бұрын
    • You’ve reminded me of a talk I gave this year showing how some fortran code appeared in assembly. Fortran is still widely used in my field (supercomputing) and understanding the impact of such things like compiler optimisation is very helpful.

      @draconianTL@draconianTL10 ай бұрын
    • I think we had the same college professor

      @mohamedrh4093@mohamedrh40935 ай бұрын
    • @@mohamedrh4093lel

      @geekzombie8795@geekzombie87953 ай бұрын
    • ​@@mohamedrh4093 of what college?

      @18890426@18890426Ай бұрын
    • @@18890426 aui ?

      @mohamedrh4093@mohamedrh4093Ай бұрын
  • 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@counterleo3 жыл бұрын
    • Except it didn't optimise anything. This was without any optimisations

      @_yakumo420@_yakumo4202 жыл бұрын
    • @@_yakumo420 I think it is pretty interesting that even without any optimization, it became an unconditional jump, rather than test whether the int 1 evaluated to 1 (I'm pretty sure that's how while(..) works in C). I guess it's common enough that the GCC developers just hard coded that optimization construct into the compiler?

      @somebodyelse9130@somebodyelse91302 жыл бұрын
    • C doesn’t have booleans… so 1 == True

      @splashhhhhhhhhh@splashhhhhhhhhh2 жыл бұрын
    • @@splashhhhhhhhhh Yes indeed but that wasn’t the point. The compiler detected that it’s a tautology and optimised it even without the optimisation flags set.

      @counterleo@counterleo2 жыл бұрын
    • Even without optimizations on there are some optimizations that will always take place, such as not using hardware multiply/divide/modulus on powers of 2 etc

      @williamdrum9899@williamdrum9899 Жыл бұрын
  • 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.

    @ironfox7363@ironfox73634 жыл бұрын
    • Hahaha......

      @boggeshzahim3713@boggeshzahim37134 жыл бұрын
    • Go for it. Sure a fun language, you start seeing everything the compiler or interpreter does in background for your happiness

      @pawncube2050@pawncube20504 жыл бұрын
    • I always thought assembly is useless and just a waste of time and money to take that class in uni but after I finished the class I realized how important it is, this might seem like an exaggeration but Assembly made me finally understand how Computers actually work and its diff one of the most important classes in CS . also its really useful for reverse engineering a TA in my uni showed me how to crack a program just by understanding assembly

      @khaleds1792@khaleds17924 жыл бұрын
    • @Adam Richard lol so true, I tried making more elaborated programs and instantly gave up. The fact it might be very different for each processor one might have makes it very discouraging. Or just raging, don't even need the "disco"

      @pawncube2050@pawncube20504 жыл бұрын
    • The real question is which flavor? Arm? Intel? 68000? PIC?

      @AllenKll@AllenKll4 жыл бұрын
  • At Uni I made a Snake game in Assembly IA-32 for a course. Never again, thanks.

    @Pokenopoly@Pokenopoly5 жыл бұрын
    • Github? :P

      @rkan2@rkan24 жыл бұрын
    • I wrote the a-star pathfinding algo in x86-64. Just for fun...

      @slowvomit@slowvomit4 жыл бұрын
    • I feel terrible for you. I tried messing with assembly once but i couldnt get anything working

      @nearbygamerfanable@nearbygamerfanable4 жыл бұрын
    • Play shenzen io

      @xaiano794@xaiano7944 жыл бұрын
    • @@xaiano794 i dont need to buy shenzen i/o to experience the pain of assembly

      @nearbygamerfanable@nearbygamerfanable4 жыл бұрын
  • 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.

    @lesliedellow1533@lesliedellow15333 жыл бұрын
    • I'm genuinely surprised C makes so much use of the hardware stack, since if you looked at the C2 compiler in Java for example it absolutely hates using stacks and almost always does everything in registers unless it has no other choice

      @theshermantanker7043@theshermantanker70432 жыл бұрын
    • @@theshermantanker7043 If you compile on any level of optimization, it usually doesn't make as much use of the stack. By default, GCC compiles with absolutely no optimizations on, though. I find it's easier to make sense of the compiler's assembly on -O1 (the lowest level for GCC), because it puts things in registers a lot more, like a human would.

      @somebodyelse9130@somebodyelse91302 жыл бұрын
    • ​@@theshermantanker7043Originally that is what the register keyword was for. It told the compiler you wanted it to store variables in registers if possible, but it was just a request and not a given.

      @johnshaw6702@johnshaw67028 ай бұрын
    • @@theshermantanker7043 THIS. THIS is a comment I like. I wish I had a save button like Reddit here... I'm replying instead. Thanks!

      @Brahvim@Brahvim7 ай бұрын
    • I see, thanks for pointing that out, its interesting that the compiler still consider that [printf] would need to going back to where it come from even when it see that the loop is infinite

      @theBigNine@theBigNine7 ай бұрын
  • The type of video that makes you ask "How did people come up with this?"

    @captainoblivious_yt@captainoblivious_yt3 жыл бұрын
    • The type of video that makes you ask "about the type of people that came up with this?!"

      @PrimiusLovin@PrimiusLovin3 жыл бұрын
    • @@hiotis75 Ελληνάρα

      @saulgoodman5662@saulgoodman56623 жыл бұрын
    • The crash course yt channel has a series on computer science. Clears a lot of things up.

      @quintongordon6024@quintongordon60243 жыл бұрын
    • Of course aliens taught these people lol

      @MrFiyaka@MrFiyaka3 жыл бұрын
    • I guess it's tightly related to how memory and cpu work internally. And it is very limiting due to the binary nature as well as a frequency ceiling of the transistors. Dead end if you will in my opinion. Invention of multiple cpu cores bought us some time I suppose but the future is somewhere else.

      @HG-Pilot@HG-Pilot3 жыл бұрын
  • 0:20 how did you get that infinitely long paper?

    @LudwigvanBeethoven2@LudwigvanBeethoven24 жыл бұрын
    • it's a vector h ah ahaha iam bad , iam going to commit a suicide,bye world, sorry people that were actually hurt by this joke

      @younlok1081@younlok10814 жыл бұрын
    • Coz while(1) is an infinite loop

      @zhigong6099@zhigong60994 жыл бұрын
    • I would rather call it "indefinitely long" :P

      @louislebel2995@louislebel29954 жыл бұрын
    • its still being printed out, he just cut out a part of it

      @guillemvidal1958@guillemvidal19584 жыл бұрын
    • I was wondering the same thing. Wizardry?

      @rorymax@rorymax4 жыл бұрын
  • 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.

    @dameonsmith937@dameonsmith9377 жыл бұрын
    • So basically, it's almost like the compiler turned "printf ("%d ", x);" into "int oX14 /* I chose the name as a mock of the memory location shown in the above assembly */ = printf ("%d ", x);"?

      @Collidedatoms@Collidedatoms7 жыл бұрын
    • Dameon Smith this was going to be my guess

      @baconology@baconology7 жыл бұрын
    • This makes sense, but I was wondering why this instruction only occurs after the prior 7 lines instead of right after the call instruction? I'm guessing this might be because the cmpl instruction will actually overwrite the value of eax to store the comparison result. Does this have to do with the compiler not being able to look ahead to see if the value will be referenced and just postponing storing the value for future reference until it absolutely has to? Also, this would mean the instruction wouldn't be there if the routine wouldn't reuse eax and just returned instead, correct? What code could have followed and still use this value at this point, without explicitly assigning it to a variable right away? Can you give an example?

      @JaapvanderVelde@JaapvanderVelde7 жыл бұрын
    • Thanks for the explanation, but I'm still unclear on part of it. I understand that eax/rax contains the return value of the printf function and by the time "movl %eax, -0x14(%rbp)" gets executed, that's still the value of eax. From what you're saying, I get that trying to access -0x14 from assembler code would be a mistake, and I get that, but I don't see why the value needs to be kept around at all - it's clearly not referenced anywhere in the source code? What use is the return value of the printf function at that point? And why does it only get moved to that address at that point in time, instead of sooner?

      @JaapvanderVelde@JaapvanderVelde7 жыл бұрын
    • Yes, I suppose so, in that I agree with you: it's really a question about the compiler and not so much about the program either in C or assembler. I'm a software engineer myself, and having written compilers, as well as tinkered with command interpreters in the age of DOS on an 8086, I can strongly relate to what you're saying. My curiosity was raised by the question raised in the video, about the meaning of that particular instruction - which was answered above by +Dameon Smith: it's the return value of the printf function that's being saved for whatever reason, independently of the program under consideration. I suppose I could look into the inner workings of the GCC compiler to find out, I more or less hoped someone might have an intuitive (and therefore short) reason off the top of their heads. But I agree with you, that's likely not the case - and certainly not the topic of the video, as the author rightfully stepped over the problem and seems to have taken some care to write their C code in such a way that the assembler would be as clean as possible for demonstration purposes.

      @JaapvanderVelde@JaapvanderVelde7 жыл бұрын
  • I understood in theory how C went up to other languages. Now I understand how C goes down to bits. Awesome work.

    @WickedTwitches@WickedTwitches3 жыл бұрын
  • Scrolling through your videos i can see the depth of your knowledge , its brilliant and inspiring. I just subscribed.

    @davidchukwuocha5912@davidchukwuocha5912 Жыл бұрын
  • 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/

    @galier2@galier24 жыл бұрын
    • Interesting that clang -O2 results in the output values (1, 1, 2, ... 144, 233) being hardcoded into the binary. The clang compiler is evaluating the result of the loop at compile time.

      @zoomosis@zoomosis4 жыл бұрын
    • @@zoomosis Hahaha, thats very interesting. I've always thought compiler does so complicated stuff that Im not gonna even try to understand it. So I always assume that they can do pretty much anything. I wish to write my own compiler one day, very simple though.

      @garad123456@garad1234564 жыл бұрын
    • Can you define what you mean by 'spilling'? I mean, yeah, the return value of printf is loaded into this memory location, but it is never checked for success anyways, so why isn't it redundant?

      @lukasseifriedsberger3208@lukasseifriedsberger32084 жыл бұрын
    • @@lukasseifriedsberger3208 That 'redundant' store of the printf() result _IS_ the 'spilling'. The 'prototype' of the printf() function shows that it returns an int so, by default, the compiler will SAVE that value somewhere (even though the value is never used!) If the source code is compiled with some degree of optimisation (eg: -O1, -O2 etc), then it will remove this redundant store of the printf() result since it's never USED! For further reading, what does the returned value of the printf() function actually mean!!! (Not many people have ever USED this printf() return value, so they don't know what it actually signifies - It's probably more relevant for sprintf() or fprintf())

      @trevorvanbremen4718@trevorvanbremen47184 жыл бұрын
    • Thanks for that info... This excellent video's inspired lots of useful comments!

      @samuelglover7685@samuelglover76854 жыл бұрын
  • I taught myself BASIC then Pascal then C++. Learning was actually fun with some of the books they had in the '80s. I got a C64 for my 8th birthday, and I got the C64 Programmer's Reference Guide. It's just amazing the things that were in that book. It went from teaching you BASIC to showing you the memory maps, the pinouts for all the chips, and how to do graphics and sound. But it also had a 100-page chapter teaching assembly! It confused me because it made cryptic references to an assembler called 64MON which I had no idea how to get, but that made it more intriguing. The assembler class I took in college was also one of the only interesting classes I ever took. But I'm pretty weird. I was such a nerdy kid that in middle school I wrote letters to Brian Fargo and John Carmack asking for career advice.

    @RaquelFoster@RaquelFoster4 жыл бұрын
    • That is seriously awesome.

      @captaincaption@captaincaption2 жыл бұрын
    • @@captaincaption Brian Fargo actually wrote me back! That would've been about 1990 or 1991. I don't know what happened to the letter. I really loved Bard's Tale III and Wasteland. And today, 21 years later, I'm doing 2nd round interviews for L5 (senior dev) at Google ... but I just wanted to see if they offered anything interesting.

      @RaquelFoster@RaquelFoster2 жыл бұрын
    • @@RaquelFoster great stories! It sounds like you’re doing well in your career and interest. That’s always good to read!

      @draconianTL@draconianTL10 ай бұрын
  • This is so cool, and I think this would be a way more fun/efficient way to learn Assembly than what's taught in colleges. It's way easier to see where these commands come from and what they mean if they're being directly compared to an actual C program. Much harder if a bunch of Assembly terms you've never heard are tossed at you and all of a sudden you're expected to code a program like this.

    @piyushkumbhare5969@piyushkumbhare5969 Жыл бұрын
    • Try coding in machine language, now that was a chore. Assembly is just a higher level language that is converted/compiled into machine code. I originally started out studying electronics, so we had a course in machine code and had to write a program using it.

      @johnshaw6702@johnshaw67028 ай бұрын
    • ​@@johnshaw6702assembly is machine code put in a readable way for a human.

      @wa57s577@wa57s5773 ай бұрын
    • Fr 💀

      @tgsvampire@tgsvampireАй бұрын
    • ​@@johnshaw6702 That might be interesting to know how those 0s and 1s run your Processor right ?

      @tgsvampire@tgsvampireАй бұрын
  • Your video is still helpful in 2020 and I'm sure other people would also understand concepts from it in coming years. Subscribed!

    @ankurgokhale5564@ankurgokhale55643 жыл бұрын
  • I feel calm when people use paper to explain :) very educational and relaxing

    @glidingbutter5899@glidingbutter58994 жыл бұрын
  • 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_101@thiago_1016 жыл бұрын
  • This came up on my recommended. I remember using this video the night before my computer architecture exam several years ago back in college. Thank you, Ben Eater, for saving me on that one question.

    @lazarus6983@lazarus69833 жыл бұрын
  • this brings me back to my assembly class at university, in 2002. i liked that class a lot, but i've never used it again since i didn't go into a career in embedded

    @MultiClittle@MultiClittle Жыл бұрын
    • Can you tell me what does the 0000000100000f2e under _main: means

      @deepkarmakar5346@deepkarmakar5346 Жыл бұрын
    • @@tamny9963 - So you think that because someone can't remember something from 20-years ago that they're automatically lying? Or, are you just looking for attention?

      @Snarkapotamus@Snarkapotamus Жыл бұрын
    • @@deepkarmakar5346 virtual address (image base + VA = full address) of the instruction ?

      @radon-sp@radon-sp Жыл бұрын
    • @@radon-sp thinku

      @deepkarmakar5346@deepkarmakar5346 Жыл бұрын
    • @Jonathan Dahan you okay?

      @MultiClittle@MultiClittle Жыл бұрын
  • you didnt mention why y is allocated in 0xC. That is because integers have a sizeof 4 bytes so 0x8 + 4 = 0xC

    @Suppboio@Suppboio7 жыл бұрын
    • Technically a long. :P

      @lisamariefan@lisamariefan7 жыл бұрын
    • that's only in C definitions

      @zubirhusein@zubirhusein7 жыл бұрын
    • Same for z: 0x0C + 4 bytes => 0x10

      @Cortex403@Cortex4037 жыл бұрын
    • Zupprezed And why does it starts at 8 instead of 0 ?

      @Bvic3@Bvic37 жыл бұрын
    • Bvic3 Notice that something is being already saved to the position 0x04 at the top. And the number is basically an offset to the base pointer (%rbp) so 0x00 would be the base(?) of the stack frame. I don't know, maybe something is stored there

      @timojarv@timojarv7 жыл бұрын
  • Ohhhhh this helped me for my malware and reverse engineering final. THANK YOU!

    @uraxii2944@uraxii29446 жыл бұрын
  • This is an excellent video that was easy to understand. You also managed to not skip anything seemingly trivial, which is rare for these types of videos and should be appreciated. Good job, man.

    @PatricPuola@PatricPuola3 жыл бұрын
  • Very impressed the way you explained with the amount of knowledge you had with that assembly code.

    @muudus_tv@muudus_tv3 жыл бұрын
  • This is a valuable analysis. Knowing what’s going on at this level I think is fundamental to truly understanding computing. And code and architecture. Great.

    @woodywoodlstein9519@woodywoodlstein95195 жыл бұрын
  • Your teaching is great, informative and esthetic. I loved watching it. Thanks!

    @user-xq6cu3it9s@user-xq6cu3it9s4 жыл бұрын
  • Many thanks for a wonderful and insightful tutorial. I have been writing code for more years than I care to remember but this is by far the best explanation of how machine code relates to back to it's source code. Fantastic video.

    @paulgriffin8566@paulgriffin85663 жыл бұрын
  • great video. When I learnt about programming languages, I always wanted to somewhat understand how computers treat the information we feed them, but looking at assembly on your own is just like *question marks* comparing it side to side to C is really insightful!

    @KrazeeKrab@KrazeeKrab3 жыл бұрын
  • Old video, but I still want to remark that you can add the "-S" switch to make GCC output assembly directly into the output file.

    @frozendude707@frozendude7077 жыл бұрын
    • Nice tip, thanks!

      @ulilulable@ulilulable7 жыл бұрын
    • frozen_dude - Yeah, I was hopping to have "otool" installed, but I didn't. I looked around and found this: stackoverflow.com/questions/137038/how-do-you-get-assembler-output-from-c-c-source-in-gcc There are lots and lots of ways to get gcc to output the intermittent stages of compilation. I love gcc! If people have never walked through the stages of compilation, I highly recommend doing it.

      @siliconpenguin@siliconpenguin7 жыл бұрын
    • or > otool -tv main > main.s

      @dbolorkhuu@dbolorkhuu7 жыл бұрын
    • I thought I'd throw an example of the complete compilation stages out there... I guess because I find it interesting and informative. So when you compile a C source file, the process goes through 4 stages: Preprocessing, Compiling, Assembling, and Linking. 1. Preprocessing: 'gcc -E example.c -o test.i' < The example.c file is preprocessed with the include files, and other directives, #ifdef, #include, and #define. 2. Compiling: 'gcc -S example.i -o example.s' < The source file is compiled into assembly. 3. Assembling: 'gcc -c example.s -o example.o' < The assembly file is converted into an object file, a machine code file. 4. Linking: 'gcc example.o -o example' < The machine code file is linked together with other machine code objects and/or object libraries into an executable binary file. The *.i and *.s files can be examined in your favorite text editor. The *.o file and the final binary file are both binaries, so you'll need a hex editor to view their contents.

      @siliconpenguin@siliconpenguin7 жыл бұрын
    • otool is an OS X program. On Linux, use objdump -d.

      @FUZxxl@FUZxxl7 жыл бұрын
  • to any one doing c++ exams on paper.. do a table with all variables and update their values like the code says.. this way you keep track of everything

    @troidberg@troidberg6 жыл бұрын
    • AKA "dry running", in the days when computer time was horribly expensive. It's still the best way to understand what's going on in code, and uncovering places for code optimisation, if performance is a problem. Don't optimise code before you've considered the algorithm, though.

      @parrotraiser6541@parrotraiser65415 жыл бұрын
    • I had to do both courses of programming (Pascal and C) on paper, and there's no time to do that (if you want the highest grade)

      @dowrow6898@dowrow68984 жыл бұрын
    • @@dowrow6898 When writing code or answering what a block of code gives as an answer?

      @thewhitedragon4184@thewhitedragon41844 жыл бұрын
    • @@thewhitedragon4184 they give you a block of code with a lot of unusual stuff and you have to answer what it outputs, or what are some elements of an array or something similar

      @dowrow6898@dowrow68984 жыл бұрын
    • @@dowrow6898 I have the feeling we attended the same collage because it's the same garbage here 😂

      @thewhitedragon4184@thewhitedragon41844 жыл бұрын
  • This is by far the best series explaning how computers works inside. Amazing work!!

    @cyrillebournival2328@cyrillebournival23282 жыл бұрын
  • Just fantastic to see how efficient the code produced by the C compiler is. I spent years writing assembler as a kid and used to have competitions with other on how fast and small we could make our code..

    @MrChrismeenan@MrChrismeenan2 жыл бұрын
    • Spilling every value (including even the unused printf return value) on the stack isn't exactly the most efficient thing to do-however, that's exactly the thing to expect when compiling with optimization disabled.

      @user-yd7ds6po4l@user-yd7ds6po4l Жыл бұрын
    • ​@@user-yd7ds6po4l Well, with optimizations it managed to surprise me. It managed to compile: x = 3 * x + 1; into a single instruction.

      @forbidden-cyrillic-handle@forbidden-cyrillic-handle11 ай бұрын
  • Is it just me or you are feeling excited as well when you see machine language? I was learning python and working on stuff with for like everyday in 8 months. I started learning C and now it just feels a lot of fun language to work with! I even gave a break to python for the time being. Watching assembly feels interesting as well.

    @GodotEnjoyer@GodotEnjoyer3 жыл бұрын
    • Yeah same I'm having more fun learning assembly than the high level languages maybe that's because I'm a computers' nerd lol

      @thecoolnewsguy@thecoolnewsguy Жыл бұрын
  • I appreciate your effort to make this teaching video to share what you know and honestly say don't know to things you don't know. Well done. I'm not sure either what's the point of moving the contents of eax register on to stack.

    @garydunken7934@garydunken79347 жыл бұрын
    • so it can be formatted loaded and printed ... it has to strip the format out of the print ... the the data pointer then the data then print it ... and a stack is the best place to do that from as you can shift left and grab the format ... and then shift left and set format up then load the next chunk and shift left ... read data pointer ...and shift left ... load data .. shift left and finally print ...

      @0623kaboom@0623kaboom5 жыл бұрын
  • 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!

    @konstantinospalapanidis6414@konstantinospalapanidis64142 ай бұрын
  • This is a good example on why learning coding without understanding how computer technologies layer on each other seems so daunting. Just learning a coding language is not really that difficult. But coding is complexity built on complexity, and each layer down it become exponentially more complex. From an outside perspective, like when when I first started learning code, it feels like you don't just need to know the top layer of knowledge, be it python or c++, but you need to understand what makes that work and how something else makes that work. At the end of the day Id have the impression I was going to have to learn how electricity works to understand the chipsets or ram to understand the next layer to understand the next layer all the way up to my code. The great thing is that these languages were made so we don't have to do that. OOP and modern tech has almost made everything so independent and modular that you can learn the end result without knowing fuck all about how it works. You don't even need to know to code to write games anymore.

    @vanman118@vanman1183 жыл бұрын
    • if you want to know what hardware is doing, learn Computer architecture

      @nickharrison3748@nickharrison37483 жыл бұрын
    • Like the Techmen from Foundation. They knew how to work on nuclear power plants but had no idea how that shite worked

      @NormHen5413@NormHen54133 жыл бұрын
    • wrg, no such thin gas dauntingx

      @zes3813@zes38133 жыл бұрын
    • You are right but there is one thing.. I dont think learning OOP or coding language is easy .. They are also difficult because if you want to learn really well they steal a loot of time from you :(

      @MrFiyaka@MrFiyaka3 жыл бұрын
    • I was thinking this exactly today! I was wondering how much do I need to know about this stuff and how may It help me. Although I know I don't need to know all of this stuff is so interesting to me and I think It can give me a better understanding of computer science as a whole, so I'm planning on at least do some research. It's only been 8 months since I started learning Web Development but I am fascinated with everything related to computer science.

      @carocs1886@carocs18863 жыл бұрын
  • Remembering my first programming. You looked up the op codes and entered them on a keypad in Hexadecimal. This literally was writing the cpu instructions directly. I miss the 6502.

    @lochinvar00465@lochinvar004654 жыл бұрын
    • Way back when I was in school, we had a lab course working with the M6800 (6800, not 68000). I used to write my programs in C then hand-compile them into M6800 assembler. And of course, hand convert that into machine code, which then had to get toggled into the machine.

      @roysmith5902@roysmith59024 жыл бұрын
    • Hey me too man! Learned Basic on my Apple II and when I wanted to include some heavy-duty math subroutines, I'd POKE the hex code into a memory location then call it when needed. Even on that old 8-bit processor it ran blazingly fast!

      @GaryWirsching@GaryWirsching3 жыл бұрын
    • The 6502 instruction set was very nice and clear, as was the Z80's to some extent. The intel instruction set was ugly in comparison. ARM assembly language is even worse, it's not meant for humans. Every instruction can do something and can also do something completely different, depending on some weird prefixes. I hope no human being was ever forced to write ARM assembly code.

      @heinzk023@heinzk0233 жыл бұрын
  • This brings me good memories from my first semester in college when I worked with MIPS assembler code. Probably one of the most interesting things I have studied so far.

    @c0ldw1nd27@c0ldw1nd276 жыл бұрын
  • When I was a newbie programmer back there in 2000, playing around with assembler, memory and registers really helped me to get a grasp of what pointers and references are.

    @CheshireCab@CheshireCab7 ай бұрын
  • I always wondered how the C program looked in Assembly language. Today I got to understand how it all works. Great video!

    @neosmith166@neosmith1663 жыл бұрын
  • I'm studying IT, and coursing a few subjects that include C, C++, Assembler and Pentium processors architecture. And this is one of the best, and more interesting video that I've seen. Great work!

    @santiagotodisco2668@santiagotodisco26683 жыл бұрын
  • The compiler emits movb $0,%al because printf() takes a variable number of arguments. The ABI specifies that when calling such functions, %al must contain the number of floating point arguments. There are no floating point arguments passed to printf() in your example, so %al is set to zero.

    @FUZxxl@FUZxxl7 жыл бұрын
    • Which ABI are you referencing? I tried to look for an appropriate OS X ABI that would cover the cdecl calling convention, but nothing I found mentioned this approach to counting floating point arguments.

      @Hamled@Hamled4 жыл бұрын
    • @@Hamled Personally, I just assumed that the string has to be null terminated. But I have no idea what that %al stands for.

      @philippenachtergal6077@philippenachtergal60774 жыл бұрын
    • @@Hamled The System V ABI, I'm pretty sure

      @somebodyelse9130@somebodyelse91302 жыл бұрын
    • Too late in this discussion, but the zero inside "movb $0,%al" is just an information, that the printed value should go into stdout stream (in normal circumstances it means that it will be printed on the screen). Anyway, this video and discussion have returned back a lot of memories... And last but not least, If anybody would like to, source codes for printf() are available, but be warned this function is really complicated one, because of a posibility to use variable list of of arguments with all kinds of types, formats and architectures.

      @jardahybner9227@jardahybner92275 ай бұрын
  • This the piece of the puzzle I was looking for years, thank you.

    @simonkh7278@simonkh72785 күн бұрын
  • I did assembly the first 5 years or so of my 45 years in IT and SW dev. Great foundation. Your explanation is pretty good.

    @andyhawaii2819@andyhawaii2819 Жыл бұрын
  • Really enjoy your videos, started my programming journey, if you will, about 5 years ago with the idea of wanting to make video games. i later found assembly programming and electronics engineering FAR more interesting than game design. I have been learning 8086 ASM on DosBox lately hoping i can get enough experience to understand how computers work entirely, i am currently in the process of learning how different IC's work on a breadboard and hope to build my own 8bit computer soon. Thanks for getting me started on such a fun hobby i hope to make my job someday, keep up the excellent videos! Hope to see your channel continue to grow :)

    @redxonegaming5436@redxonegaming54367 жыл бұрын
    • Redxone Gaming How is your progress if you don't mind asking?

      @susanins1000@susanins10005 жыл бұрын
    • Yes I am interested to know too. I would like to build 8 bit computer too.

      @abiduzair183@abiduzair1835 жыл бұрын
    • Please answer us bro!

      @rojirrim7298@rojirrim72985 жыл бұрын
    • Maybe he figured out that using machine language in software makes your product un-portable. There are many reasons *not* to write in assembler. And there are distinct instruction sets for different CPU architectures, so you can learn one ISA (inst set architecture) or you can learn all of them; compilers *do* have their advantages. All digital computers work the same way (registers, storage, interrupts, etc) but the devil's in the detail level you can't avoid in assembler. Everybody should *know* what compilers do and appreciate that today's compilers (I've been doing this for 40 years) are very, very good. You should also understand the overhead of interpreted languages like Java & Python (and the list goes on) before you make an implementation/design decision. Knowing the heart of how most of your customers' machines work (x86_64 for {lap,desk}tops, ARM ISAs for phones/tablets) is a valuable datum, should motivate us all to write code that's as efficient as possible. I still check my assembler output most of the time, but I'm about ready to retire ... probably an "old skool" type. But today's typical bloatware sucks. *Fight it.* Take pride in your work, know what you're delivering :-) _and good luck on your autodidactic journey!_

      @8a41jt@8a41jt4 жыл бұрын
  • In my last year of college. I now finally understood this! Thank You! What I realised is that the teaching (at my was good but they didn't put enough efforts to link this to higher level of programming we were practising daily. But now it makes sense. Thank you again!

    @coenfuse@coenfuse3 жыл бұрын
  • gz on the video, man. i like how you are humble to tell people when you're not sure about.

    @matheusrodrigues-kf6pj@matheusrodrigues-kf6pj3 жыл бұрын
  • Dude this has shed light on so much stuff amazing vid

    @Franschisco@Franschisco3 жыл бұрын
  • wtf am I doing here, I can't even code

    @oldskulziom@oldskulziom7 жыл бұрын
    • I don't know why, but this video is very satsfying to watch as a programmer. It's very logical and makes sense. Like if you'd suddenly have a partial look into a womans brain and actually start understanding something.

      @hellschatt@hellschatt6 жыл бұрын
    • Why, I think everyone learns backwards, If they would start at low level which is cold hard logic memory movement and work up the chain I believe they would learn how to program much faster. Lang like basic trigger bad habits that become hard to break such as never clearing your memory or initializing variables and things like C++ have turned into a cluster fuck due to the Total Over use of OPP everyone seems hell bent on these days. I would suggest if someone wants to learn to code go back to DOS, Get Turbo C and use that, It was a great lang with great documentation to help you telling what every single command did ect.

      @seditt5146@seditt51466 жыл бұрын
    • If he tried to learn Java before ASM hes going to be crying like everyone else on this video is about how hard ASM is to understand when its WAYYYYYYY easier to understand then any lang I have ever used including Basic. I think the Fail comes with most people because they don't comment their code and lose track of whats what but its simple top down programming that can be traced with ease.

      @seditt5146@seditt51466 жыл бұрын
    • I know I will catch a mess load of flak for saying it because I still get a lot of flak for using it from time to time but I honestly believe DarkBasic is one of the better things for a programmer to start in.... Hear me out before yall hate on me. Starting off a programmer wants results, ASAP. With darkbasic its as simple as Sync On Make Object Cube(1,10) Position object (1,0,0,0) Position Camera (0,100,0) Point Camera (0,0,0) do control camera using arrow keys 0,1,1 loop wait key That code above will draw a cube on the screen and point the camera at as well as allow you to look around with the arrow keys, it which is a great starting point for most hobby programmer since the will feel the excitement going right away with a 3d object they can manipulate. This same code in say C++ for instance would literally take hundreds or thousands of boiler plate code just to setup the engine to draw the cube and accept the input. Look into darkbasic. Its old but its effective and its fun as all hell to toy with.

      @seditt5146@seditt51466 жыл бұрын
    • I started on a TRS 80 Model 1 with 2k ram and a cassette tape player. Basic. Then a Commodore 64. Commodore Basic. Then C on my BSD systems at home, took online local community college courses for Visual basic .net and C - grew tiresome. Right about then it became evident that code monkeys had to compete with $3/hr dev teams in India. Writing on the wall was that the money would be in Java. I stuck with sys admin needs; Perl and C. FEAR of Java, FEAR of having to think about this stuff, FEAR of actually applying what I've learned in school... NEVER learned these basics. (been TAUGHT it many times!) Never formed this solid foundation. In other words; I can't code to save my life...but I have worked for years making money doing it. Flying by the seat of your pants every day...making it work, doing the seemingly impossible. There is reward in that, at least. It feels good to actually DO this stuff in the real world for real world paying client needs. I can't even last in a programming conversation for two minutes. My point? - Just *do* *it*.

      @skeggjoldgunnr3167@skeggjoldgunnr31676 жыл бұрын
  • Minor correction, because I used to program in 8080 and Z-80 Assembly: Those instructions from the disassembly are more properly referred to as assembly code instructions. Machine code would be represented by nice hex numbers for the opcodes and operands.

    @antonnym214@antonnym2145 жыл бұрын
    • Actually Z80 machine language is relatively easy to program by hand, for each opcode there are few bits of prefix and then register addressing etc. Then you convert all the bits in a hex number and done

      @AlessioSangalli@AlessioSangalli5 жыл бұрын
    • Early textbooks used to make a distinction between assembly mnemonics and machine code. Looks like those days are long gone and the terms are used interchangeably.

      @totallynotabot151@totallynotabot1515 жыл бұрын
    • Z80... My computer life started programming a TK-82C at 1982... Good times... 15 Minutes to load a 15 KB program from a cassette tape (after many attempts)...

      @RogerioDec@RogerioDec5 жыл бұрын
    • Since we're being pedantic here about the difference between assembly code and machine code, it doesn't HAVE to use 'nice hex numbers'. Some CPU architectures were more suited to OCTAL representations, and technically, binary would be equally valid! Footnote: Check out the MODR/M byte in x86 code and you'll see how well-suited it is to use octal in this specific case! Having said that, I willingly admit that I'm predominantly a binary and hex man... LOL

      @trevorvanbremen4718@trevorvanbremen47184 жыл бұрын
    • The mnemonics directly represent those hex numbers. If he did print out the instructions in hex, you may as well then complain that it's not really machine code because it's not stored electrically in a computer, but printed with ink. It doesn't matter how you represent something, it's the same thing.

      @iosefka7774@iosefka77744 жыл бұрын
  • I loved every second of this. Ive been recently learning C++ and viewed the asembly code and was lost this helped so much to see whats actually happenning

    @Chevifier@Chevifier11 ай бұрын
  • 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@ccgm_harpy3 сағат бұрын
  • Nice video bro!

    @realchrishawkes@realchrishawkes3 жыл бұрын
    • Chris!

      @jimhalpert9803@jimhalpert98033 жыл бұрын
    • why your not verified

      @andrewtate4635@andrewtate46353 жыл бұрын
    • I like it too!!!!!!

      @Vegabrielml@Vegabrielml3 жыл бұрын
  • THATS SO COOL, i always programmed in C and was thinking about how it worked inside of the processor

    @VithorCasteloTutoriais@VithorCasteloTutoriais5 жыл бұрын
  • as someone who works on high level programming, your channel really brings me back and piques my interest again

    @kuroexmachina@kuroexmachina3 жыл бұрын
  • That was awesome! This is something I was never ready to dig in, and now this explanations is so good, that it makes it look easy!

    @ivanangelov8825@ivanangelov88252 жыл бұрын
  • 8:15 I believe that line puts tge x value to the aex, where it can set a flag. The next line sets the flag, and the next line uses it to determine wether to jump or not.

    @noway2831@noway28315 жыл бұрын
  • Simple and interesting explanation, I have experience with assembler, and C ++ is my main language, but I tried to watch this like i'm a beginner. And in my opinion, that was very easy to understanding. Big respect!) Sry for my bad eng)))0

    @user-bk8wg7hk2b@user-bk8wg7hk2b2 жыл бұрын
  • Gives a true appreciation for compilers! So many layers built upon layers to translate everything into machine code.

    @vishnuvithala6902@vishnuvithala69022 жыл бұрын
  • We need more of this maybe for every instruction that you know

    @LuisMolinaAl@LuisMolinaAl3 жыл бұрын
  • I don't know C nor assembly but I watched this from start to finish with my mouth hanging open. So interesting.

    @BigBadWolf1st@BigBadWolf1st7 жыл бұрын
  • Compilers were invented in 1952. People in 1951:

    @MSTendo64@MSTendo643 ай бұрын
  • finally ! i can understand some assembly code now. Thank you for this

    @blackboxlearning@blackboxlearning26 күн бұрын
  • After ignoring 5 video ..I subscribed this guy . He's worth sharing and learning from.. thanks bro

    @ikartikthakur@ikartikthakur2 жыл бұрын
  • Your channel is awesome. Ta chaîne est géniale. Merci

    @JustinParrot@JustinParrot7 жыл бұрын
  • I miss programming in assembly. The first code I ever wrote was 6502 Assembly on an Atari 600xl. I also programmed in the following assembly languages over the years: 8088, 80286, IBM 360, R10000 and MIPS. After 20+ other languages over the years, assembly is still the one I liked best. It just felt natural. When I first learned C and was using the Turbo C compiler, I often wrote the function headers and variable declarations in C, and just inlined the guts in assembly. Those were the days...

    @kenmolinaro@kenmolinaro5 жыл бұрын
    • I don't. At all. I wrote Railsounds II in Assembly because the processor (Microchip 17C42) had 2k code space and 160 bytes of ram. It ran at 4MIPS and at the time (93) was the fastest micro on the market. I couldn't wait until I could rewrite in C. Which we did. The hardest part was convincing Neil Young, my client, that we needed to do that. The rest is history. Over a million units sold.

      @photopicker@photopicker5 жыл бұрын
    • Agreed. Very creative, very obedient. CPU does exactly what you tell it; nothing more, nothing less. If errors exist nobody to blame but yourself; and maybe the standard libraries which for assembly are minimal and usually just the startup code. I also wrote assembly for Honeywell DPS 8 mainframe; now THAT was programming!

      @thomasmaughan4798@thomasmaughan47984 жыл бұрын
    • @@thomasmaughan4798 Not so much on the obedient part. I remember seeing in a presentation that intel's 486 was the last x86 processor to simply run the instructions, in their order. After that came the out-of-order execution optimisations. And things like processing both outcomes of a check in the time the required value is fetch from memory and then simply using the correct outcome. So, nowadays, you don't really know what and how are things actually executing inside of a processor. Sometimes a less optimized code can be better optimized by the CPU optimzer.

      @Winnetou17@Winnetou174 жыл бұрын
  • I found your teaching so understandable by non programmers and beginners. I dont know to do programming and wanted to learn. I have interest in c programming and now assebly. Thank you for video you are great teacher

    @qwertyuiop-gn5vi@qwertyuiop-gn5vi9 ай бұрын
  • For a person very interested in how computers manage to function through tasks, you really pleased me.

    @Palexite@Palexite2 жыл бұрын
  • rax is a 64-bit register eax is a 32-bit register which refers to the lower 32-bits of rax ax is a 16-bit registers which refers to the lower 16-bits of eax ah is an 8-bit register which refers to the upper 8-bits of ax al is an 8-bit register which refers to the lower 8-bits of ax gcc -S -masm=intel program.c ATT syntax is ok, but I prefer Intel personally... you’re welcome and thanks for the good video!

    @g00dvibes47@g00dvibes474 жыл бұрын
    • where do u learn all of this? any good books or websites as I want to understand how the machine runs c programs better

      @wh7988@wh79884 жыл бұрын
    • AH, ok

      @b4n4n46@b4n4n464 жыл бұрын
    • @@wh7988 Pick a processor, read the documentation, the documentation will tell you what commands there are and what they do. You can look up youtube videos or books for the processor and how to program in assembly for the processor. The class I am taking right now has us using code-warrior (ide) for programming the HCS12 (mircro-controller). I am assuming going with an arms processor would be a better idea though, they are more popular.

      @architvis3243@architvis32434 жыл бұрын
    • School! A good (but expensive) Assembly book is "Assembly Language" by Kip Irvine. You can use Visual Studio, admittedly a "long" process to set up, to write, run, and debug MASM. Give it a go.

      @g00dvibes47@g00dvibes474 жыл бұрын
    • T-rex is a dinousaur-bit

      @manda3dprojects966@manda3dprojects9664 жыл бұрын
  • This actually makes sense. As mainly a C# dev, C isn't actually hard, first off. Pointers and such can get a bit complex, but they make sense. This code is certainly simple. The assembly makes sense too. It is beautiful how simple it is and how it uses such sinple functionality in order to create more complex end results. This helped my understanding of Assembly and it might be one of the things that help me finally make a PS2 game one day.

    @TheBcoolGuy@TheBcoolGuy4 жыл бұрын
    • Not to be the party stopper but ps2 is a dead thing of the past

      @Alberto-sv1ou@Alberto-sv1ou4 жыл бұрын
    • Sure it is all simple. But it takes a genius to appreciate the simplicity. Shamelessly paraphrased.

      @1pcfred@1pcfred4 жыл бұрын
    • It seems simple, until you have to do implement data structures in C; then you find yourself crying for days on end, because you can't seem to resolve the clobbered memory errors that keep popping up on you!

      @IM-qy7mf@IM-qy7mf2 жыл бұрын
    • @@IM-qy7mf structs are very trivial....... if you have massive experience

      @mariocamspam72@mariocamspam722 жыл бұрын
    • @@IM-qy7mf AddressSanitizer makes this significantly easier to debug, though. It's like a plugin for compilers that instruments code using the compilers' own semantic information. You should also get in the habit of writing asserts for potentially incorrect or dangerous code.

      @sourestcake@sourestcake Жыл бұрын
  • Thank you so much and very beautiful way of making things clear

    @hkhj139@hkhj13910 ай бұрын
  • Thank you so much for this tutorial. Thanks to you i understand those concept now. Please make more of those C vs Assembly Tutorials. You are explaining it so good :D

    @DrakenRolle@DrakenRolle3 жыл бұрын
  • Using paper. I've gotta give you a thumbs up.

    @cagedtigersteve@cagedtigersteve5 жыл бұрын
    • @LoveLiveKillBillLife Paper is a technology bruh

      @mtutoriales@mtutoriales3 жыл бұрын
  • This guy is beyond words. Cannot describe how grateful I am; I found the video channel I have been looking for

    @fezkhanna6900@fezkhanna69003 жыл бұрын
  • This is so cool. This makes me want to learn the basics of assembly and be able to make simple programs like this in assembly.

    @smrtfasizmu6161@smrtfasizmu61612 жыл бұрын
  • i didn't understand much but i really liked your approach of going to the roots of the system,hope you gonna keep continue doing this.Thanks a lot.

    @tahmidhussain6035@tahmidhussain60353 жыл бұрын
  • "Back in my day we had to compile code by hand"

    @lowellthoerner1209@lowellthoerner1209 Жыл бұрын
  • This is the kind of programming videos I've been looking for, how programming in a language converts to machine instructions, awesome! THAT BEING SAID, your handwriting is abysmal oh my god xD What have you done to that 0x8 at 4:29!?

    @Madcowe@Madcowe4 жыл бұрын
  • as a beginner I understood more than I expected. Nice video, thanks!

    @gabrielroani8252@gabrielroani82523 жыл бұрын
  • Incredible video, the most useful channel on KZhead for computer science students

    @ninamira5755@ninamira57552 жыл бұрын
  • this also nicely demonstrates how intelligent the c compiler is written. the last line that contains the "jmp" order to go back to the infinite while(1) loop doesn't check any conditions...the compiler knows that this is an infite loop and thus just places a jump command. Also, its nice to see how all the programming textbooks tell you to "AVOID GOTOs! OMG GOTO IS THE WORST!" ... when under the hood of the compiled machine code, all the nice and orderly loops, and ifelse and break and continue statements...are just GOTOs :D

    @severusfumizuki9934@severusfumizuki99347 жыл бұрын
    • Severus Fumizuki The textbooks advise against goto statements is that they're less readable than higher level structures. Of course it ultimately all compiles down to gotos - the program has to live back and forth through memory - but it's not useful to have programmers wasting time chasing around opaque labels or constantly updating line references.

      @TheJamesM@TheJamesM7 жыл бұрын
    • It is not GOTO's but how you use GOTO's that is the problem. Using while and for is using GOTO's in a disciplined manner.

      @miroslavmalesevic9659@miroslavmalesevic96596 жыл бұрын
    • +Severus Fumizuki: yeah, I kinda wish he addressed that in the video, as it's a nice illustration of your compiler optimising the program rather than translating straight from C to machine code.

      @EvenTheDogAgrees@EvenTheDogAgrees6 жыл бұрын
    • Juan Rial: this is not a matter of optimization. There is no such thing as a "while" instruction in any computer architecture - "while" is just a way of specifying a loop, and the normal, un-optimized way of constructing a loop is with a jump back to the beginning of it.

      @BrightBlueJim@BrightBlueJim5 жыл бұрын
    • In high level languages, there's almost never a usecase where you need a goto. Most use cases are covered by the basic IF, WHILE, DO-WHILE, SWITCH, FUNCTION, FOR, CONTINUE, BREAK, RETURN statements. In some languages BREAK will even take an argument that says how many layers to escape from, but languages that don't, that is one of the few last surviving use cases for a GOTO provided you have a good paragraph explaining why you are using a GOTO in a comment next to it. It all goes back to documenting your code, and high level constructs are self documenting code, a goto is a wildcard and does anything so you need to document it

      @SinZ163@SinZ1635 жыл бұрын
  • Almost a year late... On x86-based computers, eax is usually for return values. Don't forget that printf is not void, it returns a length. The compiler is a macro-assembler so it stores it on the stack anyway. What you can do is ignore the stack & use only the registers ebx, ecx & edx to store x, y & z, so in theory, it should execute faster. If i remember well, if you only want 8 bits, you can use even bx, cx & dx, or even b, c ,d

    @jticklemaker1265@jticklemaker12657 жыл бұрын
    • ax, bx, cx, dx are 16 bit, the lower and upper half registers al, ah, bl, bh, cl, ... are actually 8bit. Obscure knowlege FTW!

      @plaisthos@plaisthos6 жыл бұрын
    • Came in the comments to find out what this line did. Thank you sir.

      @mdlindsey@mdlindsey6 жыл бұрын
    • you can use the register keyword in C then it will compile like that

      @xCwieCHRISx@xCwieCHRISx5 жыл бұрын
  • Oh man! This is awesome. This takes me way back to early software engineering classes at Purdue in the 90s. We used C. Great to understand how it compiles into machine code!

    @shivabreathes@shivabreathes11 ай бұрын
  • I feel great and happy with this analysis. Good job indeed.

    @adeyemijames1582@adeyemijames15827 ай бұрын
  • Wonderful, keep it up bro. For "%eax, -0x14(%rbp)", it's keeping backup of eax in a memory location as cmp command changes ax register and set flags.

    @janibsoomro3440@janibsoomro34405 жыл бұрын
    • Cmp changes only flag register and nothing else, that has always been the case since the 8bit processors.

      @ZincSpray@ZincSpray4 жыл бұрын
  • 0x0f's where given on that day

    @joschahenningsen5204@joschahenningsen52045 жыл бұрын
    • @strontiumXnitrate It was a joke referring to "0 fucks given"

      @inx1819@inx18194 жыл бұрын
    • @strontiumXnitrate ok booomer

      @user-tq9do5ss7j@user-tq9do5ss7j4 жыл бұрын
    • @@user-tq9do5ss7j why you gotta do em like that

      @unifiedcodetheory8406@unifiedcodetheory84064 жыл бұрын
    • inxane有害な wooooshhhh

      @nanashi3711@nanashi37114 жыл бұрын
    • @@user-tq9do5ss7j Where the hell did that come from?

      @mattr2238@mattr22383 жыл бұрын
  • I like your teaching style, keep it up and thanks.

    @nishantloan2618@nishantloan2618 Жыл бұрын
  • i wish i had this video in 1991 while i was going through CS undergrad. great stuff. i'm buying one of your kits for my kids as a xmas present

    @Rak6829129012@Rak68291290122 жыл бұрын
  • MORE ASSEMBLER PLEASE, LOVE IT VERY MUCH

    @TheMrBarabashka@TheMrBarabashka7 жыл бұрын
  • Thanks for the video! Glad to find others who think this is super cool. I just finished my assembly course and I'm sad its over. I'm pretty sure I'm the only student who actually did my assignments and didn't just find code to poach on stack exchange. I'm even more sure I was the only one who really enjoyed the class and preffered it over C++ and way more than Visual Basic. My C++ teacher has been giving me a hard time. Assembly is "neat" he says, but VB can make "real world programs" Humph. I figure if I love something that most people dislike, even if I don't do it directly, there's a market for doing that kind of thinking....???????

    @jessicahaines7263@jessicahaines7263 Жыл бұрын
    • Visual Basic, ewww!! :)) Yes there is a big market for assembler and c programmers - think hardware controllers and other fancy things.

      @Michael-iw3ek@Michael-iw3ek Жыл бұрын
    • Tell your C++ teacher he is an idiot (you can quote me). VB is the worst for making real world programs. Create a Hello WOrld program in VB and compile it. You get a program that is >10K. Do it in assembly and it is 128 bytes..... He must have stock in storage manufacturers.... I'm CIO that used to teach machine code/Assembly when the first PC's came out. Wrote games on C64's until the C compiler couldn't comile them anymore and switched to (macro) assembler. You don't know programming until you have done that at least once for a larger project.

      @jjc75019@jjc75019 Жыл бұрын
    • visual basic is dead. it hasn't had a real application in literally decades

      @snesmocha@snesmocha Жыл бұрын
  • Amazing, I did hundreds of translation for C to Assembly back in high school amd during the first year of uni. I miss doing this

    @serenad1271@serenad12712 жыл бұрын
  • This was very informative, thank you so much

    @ExplosiveLizard@ExplosiveLizard2 жыл бұрын
  • I like how he can explain this so well and is barely able to write :)

    @keyserxx@keyserxx4 жыл бұрын
    • No need to write when you can type :)

      @martinhawes5647@martinhawes56473 жыл бұрын
  • Sorry for the noob question, but isn't this actually assembly? I thought machine language was basically just ones and zeros?

    @MaartenRonteltap@MaartenRonteltap5 жыл бұрын
    • Yeah, you're correct; machine code is literally just binary. Otool seems to be a disassembler; it tries to format the machine code into something a little easier for a person to read Trying to read an executable written for an operating system through a hex editor or something would leave all the header information and such in the output; making it a little more difficult to see what's going on

      @xfivezerofive@xfivezerofive5 жыл бұрын
    • I could be wrong, but the actual machine code would be 1s and 0s of the low level language the CPU uses. The code shown in the video is that code translated into a kind of assembly.

      @coolbrotherf127@coolbrotherf1275 жыл бұрын
    • Assembler code is human readable, the assembler program turns it into machine code.

      @heyarno@heyarno5 жыл бұрын
    • Machine Code is binary ... The nemonic we use LDA ... etc is assmebly language and in hex because 255 ones and zeros take up a ton space on a line ... while ffff doesnt converting from binary to assembly you run an ASSEMBLER and to convert a langauge like C++ you compile it into assembly language then assemble it in to machine code ... because sending ffff is easier to handle than 255 ones and zeros in a line

      @0623kaboom@0623kaboom5 жыл бұрын
    • It is x86 (-64) assembly. Machine code is literally just bytes.

      @iProgramInCpp@iProgramInCpp5 жыл бұрын
  • Thank you so much for this video. Incredibly interesting!! Best regards :)

    @Algovibes@Algovibes3 жыл бұрын
  • When I was a C developer I always used the compiler's option to output the assembler code it was creating to check it was creating good code. There are lots of ways of coding and hints that you can give the compiler to help it understand what you want and to help it create good code.

    @TesterAnimal1@TesterAnimal13 жыл бұрын
    • Could you elaborate on those ways? or like name something i could look up to read more about this?

      @Noah-nj5ct@Noah-nj5ct3 жыл бұрын
    • @@Noah-nj5ct add `-S` to gcc, like `gcc -S hello_world.c` ; it will write the asm to `hello_world.s`

      @w300x@w300x3 жыл бұрын
KZhead