Understanding Assembly Generated From C :: Bare Metal Programming Series 4.1

Поділитися
Вставка
  • Опубліковано 21 кві 2023
  • In this (micro) episode of the bare metal programming series, we're looking at different ways of expressing the same idea in C, and reading the resulting assembly code in order to make sense of any differences.
    Being able to read assembly (if not write it) is a valuable skill - and can help tremendously in both debugging and making sensible performance optimisations.
    =[ 🔗 Links 🔗 ]=
    🎥 Series Playlist: • Blinky To Bootloader: ...
    🗣 Discord: / discord
    ⭐️ Patreon: / lowleveljavascript
    💻 Github Repo: github.com/lowbyteproductions...

КОМЕНТАРІ • 14

  • @luzten
    @luzten 11 місяців тому +1

    Just incredible channel. Thank you again

  • @lonnybulldozer8426
    @lonnybulldozer8426 Рік тому +1

    Unrelated, but can you tell me what that VSCode theme is?

  • @aleksandr2245
    @aleksandr2245 Рік тому +1

    Could you please demonstrate how to use v8 to generate assembly or bytecode from JavaScript? It would be helpful to see what the code is compiled to and how we can identify and analyze any bottlenecks or slow instructions

    • @MrOnePieceRuffy
      @MrOnePieceRuffy Рік тому +2

      First lookup how LUA works to get an Idea how JS actually works and after realizing that this Request is stupid, delete it.

    • @gm112
      @gm112 Рік тому +4

      tl;dr - Don't bother trying to prematurely optimize your code, just run a profiler and see what the burnchart says.
      Rule of thumb with a language like JS is, where ever you have memory allocations, is where your performance issues will arise. Is your code recursive and spawning new closures(a new function) each iteration? Then maybe flatten it. There's also the case of .map, .reduce running slower on smaller datasets, but then out performing native `for...of` just because of the optimization the runtime can make from the nature of those methods giving enough hints to the runtime to optimize that type of recursion.

    • @LowByteProductions
      @LowByteProductions  Рік тому +3

      I don't know too much about V8 internals, but it could be a fun one to look into one day - I'll add it to the list.
      The tricky thing there is that JS is a JIT compiled language, meaning that while there is a bytecode virtual machine at play, code on the hot path is also compiled into native machine code. The rules about how and when this happens, as I understand it, are fairly complex, and not necessarily easy to reason about. I remember quite a few years back, V8 actually changed some of the internal workings, and a lot of the "conventional wisdom" that had been built up around performant JS code went out the window. Things that were previously slow and off limits were fast, and some tricks to speed things up become slow. So yeah, it's a lot less cut and dry than something like C, where the gulf of abstraction is a lot narrower.

    • @aleksandr2245
      @aleksandr2245 Рік тому

      @@LowByteProductions thank you!

    • @AliceErishech
      @AliceErishech Рік тому +2

      @@MrOnePieceRuffy You know, this sort of elitist mindset only drives people away. If someone is trying to learn and asks a stupid question, maybe you should explain why it's a stupid question so they understand where their reasoning went wrong instead of acting like a condescending jerk. Really, what were you even hoping to achieve by acting this hostile to a simple question? To make Aleksandr feel ashamed of asking a misguided question or...?

  • @whtiequillBj
    @whtiequillBj Рік тому +1

    @15:35 I've never found a satisfactory explaination of what a "magic number" is in computer science.
    There is 0xAA55 and there is 0x10b or 0x20b for PE32 and PE32+. You seem to be saying a magic number is a uint number used by the reset vector.

    • @GeorgeBratley
      @GeorgeBratley Рік тому +7

      To my understanding the term magic number can mean a few different things in computer science depending on the context. In the case of this video, I take it to mean "from the perspective of somebody looking at this code for the first time, they need to do work to understand why there's a '4' there". The 4 is magic because it's not immediately obvious to somebody looking at the code what it's purpose is and why specifically that number is important. The sizeof(unint32_t) representation removes the 'magic' because it makes it obvious the reason for the addition and it removes the ambiguity.
      There's also the different concept of magic numbers as an encoded way of saying 'we understand each other' - a kind if primitive handshake. For example a file format might start with a magic number as a quick initial check for the thing reading it to say "does the file start with 1234? If it doesn't, it's definitely not a valid file", or similarly a communications protocol might say "To confirm you're ready to receive data, send me the magic number '6789'". In this context it's a magic number because it's just an arbitrary number chosen by whoever designed the file format or protocol to mean something specific.
      Feel free to correct me if i've got this wrong.

    • @user-io4sr7vg1v
      @user-io4sr7vg1v 8 місяців тому

      a 'magic number' is an unnamed constant. For example, the terminal value in a loop may be 10 because you have ten ports. Instead of just putting 10 in the loop, name the constant #define PORT_COUNT 10 (this example is C preprocessor specific but I hope you understand the point).

    • @Mr8lacklp
      @Mr8lacklp 8 місяців тому +1

      A magic number is any unnamed number that's not -1, 0, 1or 2 that appears in your code. Also any ot those numbers if it's not very obvious why they have that value