I re-created the game of life in Assembly

Поделиться
HTML-код
  • Опубликовано: 18 июн 2024
  • github.com/tom-delalande/lear...
    This video is for entertainment purposes only, you probably shouldn't do as I say or as I do.
    I wanted to do something a little more significant than a 'Hello world' in Assembly so I decided to tackle the game of life. I took the opportunity to try and recreate some of my favourite programs in low level languages. Including a Vi clone in C and a file manager in C++.
  • НаукаНаука

Комментарии • 114

  • @JaredFL
    @JaredFL 5 дней назад +202

    Assembly is high level. If you haven't manually applied electricity to the individual grains of sand, you aren't a senior developer.

    • @WifeWantsAWizard
      @WifeWantsAWizard 3 дня назад +8

      Grains of sand are high level. Hey, everyone! Jared doesn't know about robust qubits on super-cooled semiconductor platters. Senior, indeed!

  • @tanko.reactions176
    @tanko.reactions176 7 дней назад +111

    now.. start writing some macros for common coding tasks, like for loops.
    call it "for"..
    repeat writing such macros and you will end up with C

    • @daniel_77.
      @daniel_77. 6 дней назад +3

      I know this is meant to be a joke comment, but is it accurate?

    • @jan.tichavsky
      @jan.tichavsky 6 дней назад +5

      @@daniel_77. Not really. Macros are afaik fixed substition rules, you still end up with straightforward translation to machine code at most with two passes of the file. Now compiling C to machine code is a dynamic process which you can tune and the result depends on context of the rest of your program.

    • @daniel_77.
      @daniel_77. 6 дней назад

      @@jan.tichavsky is the speed similar?

    • @kashperanto
      @kashperanto 6 дней назад

      ​@@daniel_77. Not even close to accurate. Compilers are typically very complex pieces of software that parse your code and convert it into an intermediate representation (an abstract syntax tree) and then use some fancy algorithms to optimize out redundancies (and more). Then you've got the linker that figures out how to combine all of your files/classes with libraries you use.
      An assembly macro system is more like the C preprocessor. A few of the assembly statements in this video are macros.
      it is very unlikely that you'd beat a compiler in speed or code size with hand-written assembly code (compared to a low-level compiled language like C).

    • @noelgallagher3646
      @noelgallagher3646 5 дней назад +4

      ​@@kashperantoI don't know why people keep repeating this. Handwritten ASM is faster and the binary is smaller. for example, compilers suck at SIMD and intrinsics are ugly as hell to work with. Advantage of higher level languages is portability. No need to write ASM targeting x86, ARM, whatever

  • @ashutoshj
    @ashutoshj 7 дней назад +49

    I graduated last year, seems like my CS degree wasn’t just for writing code-it was also my secret decoder ring for getting those cryptic tech stuff. Awesome vid!

    • @markamber1480
      @markamber1480 7 дней назад

      They teach computer engineering, assembly, etc in CS yes?

    • @ashutoshj
      @ashutoshj 6 дней назад

      ​@@markamber1480 Yes, I had a course on Microprocessors and Microcontrollers where we had to write some programmes in assembly and verilog.

    • @m33r61
      @m33r61 6 дней назад

      @@markamber1480they teach computer engineering in computer engineering

    • @user-xj8qy9dj7t
      @user-xj8qy9dj7t 6 дней назад

      Its hard to answer for all universities globally, but in my country at least every university has a couse in which you will learn assembly although its not the main focus of the course​@@markamber1480

    • @osayemeokwechime2456
      @osayemeokwechime2456 4 дня назад +1

      @@markamber1480 I was taught computer architecture and assembly in my CS program.

  • @EdwinMartin
    @EdwinMartin 6 дней назад +24

    What do you mean there's no "if". A conditional branch instruction in assembler is the same thing but with more words.

  • @iCrimzon
    @iCrimzon 7 дней назад +30

    Now make a tutorial for a neural network in ASM x86 pls bro

    • @Takyodor2
      @Takyodor2 6 дней назад +11

      It's funny because the x86 part is much scarier than the neural network part 😂

    • @enricofischer1330
      @enricofischer1330 5 дней назад

      ​@@Takyodor2 True, one comand compiles to different oppcodes lol

    • @notsojharedtroll23
      @notsojharedtroll23 5 дней назад

      This, but unironically

    • @Takyodor2
      @Takyodor2 5 дней назад

      @@notsojharedtroll23 I'm not sure it would be a good idea. Most use-cases for neural networks I can think of involve images (or other complex file types), and I think writing ASM to unpack the training data would be both tedious and hard.

  • @Grahamaan27
    @Grahamaan27 5 дней назад +8

    "to me [classes] just look like meaningless boilerplate"
    What did you just say?

  • @mahakleung6992
    @mahakleung6992 4 дня назад +2

    As a retired software engineer who grew up in the analog age, I say BRAVO! I always thought OO was way too much abstraction. I have coded in hex embedded processors and worked with data scopes. BTW, you can do assembly directly in C via macros. You can interface assembly into anything using a linker or DLLs. Efficient coding is a long since dead art if you are not doing RTOS like missile guidance.

  • @cvabds
    @cvabds 5 дней назад +10

    Can you do that but in TempleOS?

    • @white_145
      @white_145 2 дня назад

      isnt templeos just funny c?

  • @Slicudis
    @Slicudis 5 дней назад +5

    I hate x86, ARM and RISC-V so much, leading me to design my own architecture lol (I'm not joking)

  • @thenameisluk
    @thenameisluk 7 дней назад +8

    nice video

  • @d3adstarr
    @d3adstarr 7 дней назад +1

    cool video man

  • @naghs2726
    @naghs2726 6 дней назад +3

    with assembly sometimes it can help to write equivalent C code then paste it into godbolt to see the assembly at different optimization levels and how you might code it in assembly

  • @denissorn
    @denissorn 7 дней назад +4

    Java AoT... There are options like GraalVM, but normally you only AoT compile to bytecode.

  • @uuu12343
    @uuu12343 6 дней назад +4

    Big OO is a real Pain

  • @mou8842
    @mou8842 7 дней назад +1

    i really struggled to read the code in the c++ part, guess i'm addicted to colorschemes

  • @igorvasylchenko8293
    @igorvasylchenko8293 3 дня назад

    Python: gets ready working example of Conway's Game of Life with GUI in under 2 min. (including intro)
    Java: proceeds to write server with single GET endpoint
    C++: implements custom classes to handle routine file management
    C: writes text editor in terminal
    Assembly: spends more than a half of video to write terminal version of Conway's Game of Life (not including off-screen time which I suspect is SLIGHTLY bigger considering debugging mentioned bugs)
    Classic at its best)

  • @friedmule5403
    @friedmule5403 2 дня назад

    LOL, Oh the good old days:-)
    I have to say that your version of Assembler is a fairly high level, compare to the start 80s.
    You had no way to just add ASCII, you had to call the letters from the right memory, switch them, combine them and then start up the memory part that had to do with the screen, then set the screen up, tell the CPU to calculate, add the result to the address that you had made for a buffer and send it to the screen.

  • @tiaanbasson9092
    @tiaanbasson9092 6 дней назад +2

    I only use python for automating tasks. C/C++ for any intensive tasks.
    Microseconds to perform something is by far better than a second or few.

  • @subhradeepbera5645
    @subhradeepbera5645 2 дня назад

    Can you please bring a playlist on Kotlin and Htmx?

  • @Somfic
    @Somfic 6 дней назад +4

    pretty much anything is better than python

  • @AndrewTSq
    @AndrewTSq 5 дней назад

    Next we do it in Machine Code :) nice one

  • @Progaros
    @Progaros 6 дней назад

    Great comparison!

  • @ninetydirectory3798
    @ninetydirectory3798 3 дня назад

    Every software is open sauce once learned Assembly.

  • @zxuiji
    @zxuiji 7 дней назад

    5:29, The only time you should not be setting up the free() and fclose() call at the end straight away is if you're returning it or passing that responsibility to a specific thread. In all cases you should have a fallback free() and fclose() call.

  • @Cronay
    @Cronay 7 дней назад +1

    Liked the video! The repository is still private I guess.

  • @tempname8263
    @tempname8263 3 дня назад

    It'd be nice to see how fast can your program execute, it being plain asm with minimal memory access.

  • @brunojcm
    @brunojcm 7 дней назад +2

    so, you don't use any "heap", just registers and the stack? writing something without heap is pretty cool :)

    • @tom-delalande
      @tom-delalande  7 дней назад +2

      I am not ready for the heap yet, but I will try it some day

    • @batatanna
      @batatanna 7 дней назад +1

      ​@@tom-delalandeOnce you use it you can never go back

    • @thewholeworldisburningharry123
      @thewholeworldisburningharry123 6 дней назад +1

      I remember about Low Level Learning video on NASA’s procedure to writing safe code. And the 3rd rule is not using the heap !!

    • @brunojcm
      @brunojcm 6 дней назад +1

      @@thewholeworldisburningharry123 keen to what this one :) That's easier on arm, anyway, it seems to have plenty of registers. IIRC from my uni times x86 has AX BX CX DX and that's it.

    • @jan.tichavsky
      @jan.tichavsky 6 дней назад

      @@brunojcm x86 64 has more, then you can use all the different extensions and multimedia features, boom you have tons of rregisters to use. RISC based CPUs have at least uniform bank of registers which is easier to think about.

  • @F100cTomas
    @F100cTomas 5 дней назад

    I don't think your C++ code has any memory leaks. Shared pointers are just really smart. When you copy them a counter goes up and when you destroy them or reassign them the counter goes down. When the last shared pointer stops pointing at that address, the memory gets freed.

  • @NostraDavid2
    @NostraDavid2 7 дней назад +1

    I would argue that Haskell is the highest level language there is, since you kinda need to know Category Theory (very abstract math) before you can understand the Monad.
    But maybe that's just me.

    • @pdr.
      @pdr. 7 дней назад +1

      I would agree that Haskell is a very high level language but completely disagree that you need category theory to understand what a monad is in Haskell.
      By the way, @OP, when did C become a _low-level_ language? Basically, any language above assembler is considered high level.

    • @pdr.
      @pdr. 7 дней назад

      And to explain why Haskell is very high level, you can think of functional programming as a higher level of discipline. That is, you are more restricted in what you can do. This allows for easier analysis at the cost of being less verbose. Similar to how electrical engineers use discrete components and operate those components under strict conditions, like standardising what high and low voltage signals are which allow you to forget about voltages completely and start talking in 1s and 0s instead.

    • @vidal9747
      @vidal9747 7 дней назад +1

      ​@@pdr.C is lower level than most. Some people call it middle level even.

    • @willmungas8964
      @willmungas8964 6 дней назад +2

      @@vidal9747I think it’s fair to say C is high level from a systems and OS programming perspective, but low level for any kind of application programming. It offers useful abstractions to be just above assembly, but those who are familiar with assembly have a fairly easy time conceptualizing what assembly code will be generated by a given piece of C code because the abstractions are so direct.

    • @kehindeakiode2865
      @kehindeakiode2865 4 дня назад

      ​@@willmungas8964Very true. It was from learning C that I really understood what the processor was doing under the hood.

  • @timondalton8731
    @timondalton8731 6 дней назад

    Loved slapping HTML/CSS🤣

  • @sillybuttons925
    @sillybuttons925 7 дней назад

    Ha, I loved VIN! Looking forward to the release to switch off neovim.

  • @ahmedayman6402
    @ahmedayman6402 4 дня назад

    0:28 nothing like RUST.. most loved language XD

  • @replikvltyoutube3727
    @replikvltyoutube3727 6 дней назад +1

    Now write it in bash

  • @peterwilson7532
    @peterwilson7532 5 дней назад

    Assembler is too high level for me, I prefer to punch in a series of ones and zeros with a handheld switch! Machine Code baby, yeah. 😂
    My computer BIOS Bootstrap is made of diodes soldered to a motherboard. You have to get the soldering iron out to edit the code. I spend almost my entire life, programming my computer to add two numbers, outputting the answer on binary coded individual LEDS.
    It would only take me three months to input the code for ”The Game of Life". Drawing the output to paper for the first move would probably take a day. After three months I could clamp all the drawings along one edge and flick through them quickly, creating the animation of the screen on a regular computer.
    At 50Hz I would have 2 whole seconds of gameplay after 3 months, so fast, phew!

  • @xcoder1122
    @xcoder1122 6 дней назад +22

    "Assembly is better than Python" - Better at what? I'm pretty sure if you put two random people side by side, person A and person B, you can always say that person A is better than person B because there surely is at least one thing, person A will be better at than person B. But you can say the same for person B, as it surely also works the other way round. So the term "better" on its own is meaningless unless you also name a property that you are comparing.

    • @pro_gemer
      @pro_gemer 6 дней назад

      Python cccp brainwashing
      accept assembly as your superior and future manager

    • @no_nuts0614
      @no_nuts0614 5 дней назад +4

      it's better at coding

    • @baraka629
      @baraka629 4 дня назад +4

      "assembly is better" - 💪😎
      "b-b-better at what?" - ☝️🤓💬

    • @jorgedavid726
      @jorgedavid726 2 дня назад +1

      Now say it again without criying

    • @xcoder1122
      @xcoder1122 2 дня назад

      @@jorgedavid726 You seem to have posted to the wrong thread. Your comment doesn't even make sense in this context.

  • @whiskerskitten513
    @whiskerskitten513 7 дней назад +2

    Loved the vid, should try code in Windows batch file since its inbetween c and assembly.

    • @nou4605
      @nou4605 6 дней назад +4

      Wut no. Batch scripting is pretty high level. On the same level as Python.

  • @sidharthcs2110
    @sidharthcs2110 4 дня назад

    I guess 1s and 0s are even better

  • @vidal9747
    @vidal9747 7 дней назад

    7:55 let me tell you how godamn awful Fortran documentation is... Most of it is for stuff that is in the lengugae but is not good practice to use anymore.

  • @W0lfCL
    @W0lfCL 3 дня назад

    Pfft, Imagine not passing bits to the processor and just lazily coding in assembly

  • @brunojcm
    @brunojcm 7 дней назад

    I could smell something going wrong when you said shift right... but for some reason XOR came to my mind instead of AND, which is indeed the best option.

  • @xcoder1122
    @xcoder1122 6 дней назад

    It looks like you might have missed it, but Python is an object-oriented language. All data types in Python are actually classes. Even "int" is a class in Python, but "int" isn't a class in C++ or Java. Also, the NoneType is a class in Python, so even the thing that represents no value whatsoever is a class in Python. This means that Python is more object-oriented than C++ and Java, not less. Python is as object-oriented as Smalltalk when it comes to data types. Smalltalk goes one step further by making every instruction a method (even "if" and "while" are not language constructs, they are methods in Smalltalk). So it doesn't make sense to bash on Java and C++ for being object-oriented languages but not on Python.
    Python's OO approach just makes it seem less OO at first glance. E.g. you may criticize that in Java every function must belong to a class, while in Python you can have functions that don't belong to any class; but the reason for this is that functions are objects themselves in Python, so they don't need to belong to a class, they can exist on their own, but not in Java; Java functions are not objects, so again, Python is way more object oriented than Java.

    • @Chr0n0s38
      @Chr0n0s38 6 дней назад

      In all fairness with Java, int is a primitive but there is a class wrapper around it.
      Java doesn't have functions, but rather methods, for exactly the reason you stated. It is fully OO because of that. You never have to use a primitive in your code directly. It's a different approach to implementing OO, that doesn't make it less OO.

    • @xcoder1122
      @xcoder1122 6 дней назад

      @@Chr0n0s38 "Java doesn't have functions, but rather methods" - Methods are functions. There is no objective distinction between those two terms. In Swift for example. classes also have functions, yet those functions are basically what Java would call methods. Dito Rust. In JavaScript there are only functions, yet JS is an OO language with objects. The original idea of OO did not include methods but "messages". Objects would exchange messages but the concept does not define what a message looks like or how it is implemented. A static method in Java is conceptional no different to a function in C and if you use only static methods in Java and only primitives, you can do functional programming in Java, nobody is stopping you from doing that (just search Google for "functional programming in java" and you will find thousands of code samples).
      And yes, Java has wrappers, but that's not the point. The point is that it has primitives and that makes it less OO to a language where everything is an object. In Python, everything is an object, because in Python everything must be an object as Python only knows objects, in Java not everything is an object. The fact that you can wrap primitives in objects doesn't change the fact that in Java not all data types are objects.

    • @Chr0n0s38
      @Chr0n0s38 6 дней назад

      @@xcoder1122 There is a distinction. Functions exist outside classes, methods do not. That distinction does matter when you try to say that the lack of functions as objects makes Java less OO than Python. If anything, the fact Python lets you avoid OO makes it less OO (hence why it is called general purpose and not OO). If you're going to count primitive ints against Java when object wrappers exist, then you should count stand-alone functions against Python.
      All of this is ultimately purity spiraling though. Python works best when used as a declarative functional language, going against OO. OO is just bad design.

    • @xcoder1122
      @xcoder1122 6 дней назад

      @@Chr0n0s38 Again, not true for many languages where functions do live within classes or are parts of objects because what Java calls methods is called function in many languages and that is totally okay. Just because Java decided to call their functions methods does not mean that a function that is part of an object or a class must be called method. There is no such rule anywhere in the entire IT industry. When yo make you own programming language tomorrow, you are free to call your functions methods and you methods functions or call both by entirely different names and nobody will forbid you to do that. The term "function" existed in mathematics long before there even used to be programming languages. Swift always calls them functions, whether they are attached to class or not doesn't matter. Javascript always calls them functions, whether they exist standalone or are part of an object. Rust uses functions as a superordinate concept; there are methods and closures and Higher Order Functions (HOF) and Diverging functions, and those are all different types of functions according to the rust manual (so rust even literally says methods *are* functions). There is no rule that a function belonging to a class must be named a method, just because that's how Java names them.
      And no, Python does not let you avoid OO. You use a data type in Python, you use an object. You cannot write any Python code whatsoever that does not use objects. You seem to be under the incorrect impression that OO means your code must look in a certain way or you must design your code to OO principles. Just because you don't follow OO principles does not mean that you are not using OO. In Python you have no choice, you always use OO. Just because your code doesn't look that way means nothing. Did you perform the Google search I told you? If you did, you had seen plenty of Java Code that also follows no OO principles and does not look like OO code at all. You cannot use Python as a "a declarative functional language" because the moment you use any data type, that is an object and a a declarative functional language has no objects.

    • @Chr0n0s38
      @Chr0n0s38 6 дней назад

      @@xcoder1122 Again, that distinction does matter. Functions in classes are methods, even in other languages.
      Now that said, other languages may not choose to follow that distinction for themselves, but it doesn't mean the distinction isn't there. They just choose to ignore it.
      And yes, Python does let you ignore OO. OO isn't just "everything is an object" it's a programming style. Smalltalk forces, as does Java (seeing as how not even main exists outside of an object). When writing Python code you can choose to ignore that full feature set. I do that all the time, favoring a functional style instead. What the language uses under the hood doesn't matter, if it did then nothing would be OO because under the hood it's all actually procedural. Style is entirely in how you use it.
      You need to brush up on your vocab, badly.

  • @user-kn9oq9vo6g
    @user-kn9oq9vo6g 7 дней назад +4

    1st

  • @BinaryMaestro1
    @BinaryMaestro1 6 дней назад +1

    html and css are not programming languages bros honest at least also why didnt u try zig instead of C?

    • @willmungas8964
      @willmungas8964 6 дней назад +2

      Because Zig has barely been around and is relatively unknown, and C is only one of the oldest, most stable, and most well known languages still in use today

    • @jan.tichavsky
      @jan.tichavsky 6 дней назад

      CSS is complex and offers interactive features, conditions, complex selector options and so on. You can do multi level interactive menu with it as well as actuate stuff with simple checkbox (hide, show, move, etc.).

    • @zeektm1762
      @zeektm1762 5 дней назад

      @@willmungas8964Fortran

  • @marko9900
    @marko9900 5 дней назад

    Assembly is just a low low level language. You need to go deeper. Machine Code. only 1's and 0's. Its low low low level language :D

  • @atrbulldog5955
    @atrbulldog5955 7 дней назад +9

    Everything is better than python, most of its libraries are written in different languages lol

    • @zill150
      @zill150 6 дней назад +2

      The fact that people rewrite Python into libraries in different languages only to continue to use Python is pretty telling

    • @charlieking7600
      @charlieking7600 5 дней назад +2

      ​@@zill150well, some people don't get the concept of scripting language and the fact that not everyone is a professional programmer.
      Even scientists use Python, because they have already difficult work and low-level programming isn't going to help.

    • @pubdigitalix
      @pubdigitalix 4 дня назад

      @@charlieking7600 Some people are lazy. Most scientific programs for the 70s was writing in Fortran and most scientists of that time are not professional programmers either.

  • @xorxpert
    @xorxpert 3 дня назад

    Java is memory efficient? Haha, consult with the garbage collection department

  • @frytura
    @frytura 7 дней назад

    binary is not a programming language?

  • @Charlyzard_ssb
    @Charlyzard_ssb 7 дней назад

    you smell like a webdev

    • @zedev444
      @zedev444 7 дней назад +8

      bro coded GoL in ASM and that's what you extrapolate? Low T energy frfr

  • @m4rt_
    @m4rt_ 7 дней назад

    That C code is awful...
    though I guess it's fine since it gets the job done.