I made the same game in Assembly, C and C++

  Рет қаралды 617,194

Nathan Baggs

Nathan Baggs

Күн бұрын

#programming #gamedev #cpp #assembly #x86
I made the same game in x86 assembly, C and C++ to see how they compare.
💭 All views are my own 💭
Link to source: github.com/iris-engine-dev/as...

Пікірлер: 734
@nathanbaggs
@nathanbaggs 2 ай бұрын
Want early access to new videos and some behind the scenes content? Consider becoming a channel member kzfaq.info/love/QvW_89l7f-hCMP1pzGm4xwjoin
@blaser80
@blaser80 Жыл бұрын
This reminded me of the time a colleague thought he could rewrite his C code in assembly to get more performance, what he learnt at the end was that the C compiler optimisation was much better than his assembly coding skills.
@vintagewander
@vintagewander Жыл бұрын
yeah compiler nowadays are really smart though, normally when you write your C code and let the compiler optimizes it aggressively, then you compare to your asm code, it's just no competition
@nathanbaggs
@nathanbaggs Жыл бұрын
The optimisations in compilers are pretty crazy, I guarantee I’m not smarter than a compiler.
@g.4279
@g.4279 Жыл бұрын
Every time someone finds a cool way to optimize assembly code, they just add that optimization to the compiler. Modern compilers are just effectively 20+ years of knowledge packed into one little box.
@__jan
@__jan Жыл бұрын
Yeah, there are only very rare circumstances in which you could get any speed gain by rewriting something in Assembly. See for example Lua vs LuaJIT, where LuaJIT's interpreter is written in Assembly in order to store some important state in the same registers while the interpreter is running, and to speed up the fetch-decode-execute loop as much as possible. No C compiler can do that kind of thing at the moment.
@jaysistar2711
@jaysistar2711 Жыл бұрын
This is the kind of comment that I find very strange. I think that people just haven't thought through what can be optimized and what can't, but everytime that I _thought_ that I could out perform the compiler, I was correct. I don't feel like I can do any better most of the time, however.
@adamschlinker972
@adamschlinker972 Жыл бұрын
This makes the fact that Roller Coaster Tycoon was written in Assembly even more mind blowing.
@njbrx
@njbrx Жыл бұрын
worth it, last I recall, he has made 30 million dollars from that game
@camthesaxman3387
@camthesaxman3387 Жыл бұрын
Well, almost every console game of the 4th generation (SNES/Genesis era) and earlier was coded in assembly.
@whanggg
@whanggg Жыл бұрын
When atleast the person who programmed it has made a lot of money from it
@ulysses_grant
@ulysses_grant Жыл бұрын
I didn't know that. This is completely nuts. Thankfully the creator got paid.
@megax5000
@megax5000 Жыл бұрын
indeed but also note that pretty much every 8 bit and 16 bit game was programmed in assembly!
@JustinMasayda
@JustinMasayda Жыл бұрын
For his next trick, he writes it in transistors and binary
@ChrisM541
@ChrisM541 Жыл бұрын
Binary (i.e. machine code) = assembly language, or, to put it another way, assembly language is a 1:1 version of machine code using opcode mnemonics. Crucial note: all opcode mnemonics are known during the CPU's final design stage - writing in 'machine code' = writing using the numeric values of these opcodes. Assembly language is, essentially, writing machine code using the human-readable mnemonic text version of opcodes. No one writes in 'machine code' - it's all assembly, and always has been (on paper in the 'early days', with the machine code translated version along side ready to be loaded). Of course, an embedded system (e.g. space/satellite etc devices) will be pre-loaded with the 'assembled' (i.e. binary) version of a program.
@Martinit0
@Martinit0 Жыл бұрын
For the next next trick he builds his own CPU from basic gates. No luxuries like MMU, I/O or DRAM. Need to write your own operating system.
@delq
@delq Жыл бұрын
For the next trick he writes the program literally on sand
@Rudxain
@Rudxain Жыл бұрын
@@ChrisM541 You know there's a thing called hexadecimal, right? And there are assembly pseudo-instructions, so it's not a perfect 1:1 map
@mattmurphy7030
@mattmurphy7030 6 ай бұрын
@@ChrisM541”no one writes in machine code” That’s weird, in my FPGA class everyone wrote in machine code. Except me because I wrote an assembler, but an assembler doesn’t always exist. And even my simple assembler generated machine code that didn’t map 1:1 to assembly. You don’t know what you’re talking about.
@undisclosedmusic4969
@undisclosedmusic4969 Жыл бұрын
Admittedly, it's been some time since I last considered programming in C a "breath of fresh air" over something else 😂
@HonsHon
@HonsHon 4 ай бұрын
​@_batman_Fan_ Honestly, I like it better than C++ now. So much more simple. Not saying C++ is worse, but when appropriate, I would rather use C
@charlesabju907
@charlesabju907 3 ай бұрын
C is not that bad, and strong emphasis: *in rare cases and applications* it's still the best choice
@danielfrappier3378
@danielfrappier3378 2 ай бұрын
I can write something like this in C without ever looking at a line of doc or doing a Google search while I feel everything looks complicated in C++ and I spend a lot of time searching and doubting myself. The fact the author feels a class of library was helpful for this leaves me perplex as well... when all you need is a few structs and arrays.
@TenokiPoki
@TenokiPoki 2 ай бұрын
honestly i prefer C over anything else any day, truly a breath of fresh air
@rickintexas1584
@rickintexas1584 Жыл бұрын
I’m 59 and wrote my first program in an assembly type language in 1977. We are truly standing on the shoulders of giants. I am an aerospace engineer, but still need to write code to automate engineering tasks. Visual Studio is my environment of choice because it makes my job so simple.
@psltmtir
@psltmtir Жыл бұрын
Entering college for aerospace engineering next year & a total compeng nerd. I look up to you!
@rickintexas1584
@rickintexas1584 Жыл бұрын
@@psltmtir one day you will be 59 and look back on a successful life and career. Make it a good one.
@stewiegriffin6503
@stewiegriffin6503 Жыл бұрын
Visual Studio Code or Visual Studio ?
@Martinit0
@Martinit0 Жыл бұрын
I recently switched from Notepad++ to Visual Studio (not Code). I am surprised how bad it is at basic tasks, like search and replace (it's slow and half the time doesn't replace or skips one replace). It also takes up 700MB in memory when running.
@shorttimer874
@shorttimer874 Жыл бұрын
I'm impressed. My mom was an engineering aid working at the Boeing wind tunnel facility. She had the neatest pens for plotting out the results. She claimed she got sent to take Fortran classes because the engineers couldn't be bothered.
@Spartan322
@Spartan322 Жыл бұрын
What makes compiler optimization so great is its not just a single bit of contributed ideas from a single person whose smart in the field of assembly, but its a collection of all the smartest techniques anyone could functionally think of to optimize your code, as a result the compiler is the culmination of every idea of almost every geniuses' demonstrably proven optimization technique, its basically the collective execution of every single engineering wizard in a singular binary who also knows exactly how to evaluate your code most efficiently almost all the time. (granted we assume all compilers do the same optimizations to low level machine code, which outside of edge cases and small processing differences that's pretty much true)
@nathanbaggs
@nathanbaggs Жыл бұрын
Very true!
@MatVeiQaaa
@MatVeiQaaa 2 ай бұрын
I consider C/C++ compiler to be one if not greatest marvels of software engineering. It’s the culmination of thought of thousands people over decades.
@saksham2091
@saksham2091 11 ай бұрын
I was thinking about learning assembly, thank you for changing my mind
@nathanbaggs
@nathanbaggs 11 ай бұрын
It's still a fun challenge!
@whannabi
@whannabi 2 ай бұрын
That's a shame. You're the one losing something so whatever.
@hugofoltin5647
@hugofoltin5647 Жыл бұрын
good video, short and straight to the point. Nice!
@nathanbaggs
@nathanbaggs Жыл бұрын
Thanks, that’s kind of the style I’m going for (:
@jaydenm8106
@jaydenm8106 Жыл бұрын
I’m taking an assembly class right now. Really makes you appreciate c++
@petacreepers23
@petacreepers23 Жыл бұрын
i just took a look at your code and for some reason the assembly one looks way cleaner and simlper than the c++ one, at least for me. congrats on the readability of the asm version
@nathanbaggs
@nathanbaggs Жыл бұрын
Thanks for checking out the code, glad you found it legible.
@jlewwis1995
@jlewwis1995 4 ай бұрын
Well to be fair when writing assembly you obviously want to write as little code as possible, so naturally it's going to be cleaner because less code = less chance for spaghetti to cook 😂
@6754bettkitty
@6754bettkitty 3 ай бұрын
​@@jlewwis1995 "spaghetti to cook" 😂
@krafs6537
@krafs6537 5 ай бұрын
As a programmer myself, I'm really impressed at your level of knowledge. Very entertaining too. Keep making videos :D
@DesandSam
@DesandSam 16 күн бұрын
The advantage of assembly code is that you only write the code that is needed and the assembler turns mnemonics into machine executable instructions. Higher languages rely on libraries which are general purpose, parameterised routines that include a lot more code. Then libraries are written that rely on the inclusion of other libraries... Yes, it makes the coding easier (read "achievable"), but less efficient. Hence we need super-powerful 64 bit cpus and super fast memory just to present a desk top. I taught myself z80 and 6502 code in the '80s and progressed through a career in COBOL and similar 3rd gen languages in the '90s and '00s. I haven't written code in decades. But the fact remains that the nearer you get to the metal the more "immediate" the execution becomes. However, trade that off against the difficulties of coding at that low level (the Roller Coaster Tycoon that others have discussed). But you can write crappy inefficient code in any language, so speed of execution isn't just a property of the language. The driver behind current languages is speed to market, not speed of execution.
@ekaal-amin5996
@ekaal-amin5996 Жыл бұрын
cool video, its make me want to learn again about low level and assembly deeper
@icarvs_vivit
@icarvs_vivit Жыл бұрын
>Using a linked list to write a breakout clone What is it with you modern, high level 'programmers' that feel the need to shoehorn random memory structures into your programs? You can write breakout with just statically defined, bss memory - you can even use bits in a calculated grid system for the blocks to maximize cache utilization in the collision detection and make massive games that still run fine. This is the thing about assembly that many people don't seem to understand: you control exactly how complex it is; you control exactly how much useless abstraction you add to your system. It just so happens that simple solutions to simple problems are also usually much faster than complex solutions.
@nathanbaggs
@nathanbaggs Жыл бұрын
You are right, it was an active decision on my part to increase the complexity. I felt it told a better story of how each successive language made development easier by increasing abstraction, by having a common-ish design across all three. It also helped highlight how low-level and bare bones assembly is.
@icarvs_vivit
@icarvs_vivit Жыл бұрын
​@@nathanbaggs Maybe so but it also failed to highlight one of the largest benefits of programming in such a low level, namely the direct incentive and ability to write said program in as few instructions/using as little memory as possible. You, in fact, directly contradicted it by exclusively focusing on its flaws. The whole point of programming in assembly, these days, is to write extremely tight code with (optionally) tight memory constraints. Being bare bones is both a good and a bad thing but I saw very little good. In fact I don't think I saw any at all. It's quite one-dimensional, this analysis of assembly programming, and it comes off to me as forced, like you were trying to form the narrative to be only what you wanted it to be. I'm not saying go full jargon but misleading your audience just to tell an appealing story is exclusively targeting the lowest common denominator and is degrading to the heuristic knowledge of people who don't spend their days programming in assembly.
@gaza2322
@gaza2322 4 ай бұрын
I found this video extremely useful Nathan, thank you. I had to put a SDL_Delay(1) statement in the running loop as it was impossibly fast to play, and cpu usage was very high - unless I did something wrong? I also had a compiler warning in c_window_destroy line 79. “Potentially uninitialised variable” - fair enough! I commented this line out for expediency. The hardest part of this was installing the SDL lib. I was stupidly trying to build a Win32 using the 64 bit SDL lib - silly me!
@ChrisM541
@ChrisM541 Жыл бұрын
Interesting upload, thanks for this. Assembly language, while extremely simple in it's individual instruction code mnemonics, is incredibly extremely difficult to expertly program in. As you'll know, there's a lot of 70's-90's 'expert-level' assembly language programmers out there. Yes, of course, such expertise will be linked to specific CPU's and their instruction sets. It's also important for every programmer to know that every program in every language out there executes, ultimately, as machine code. You either write your machine code in assembly language (a 1:1 translation using opcode mnemonics and any associated operands), or, you write in a higher level language and put 100% of your trust in your 'translation process' e.g. compiler. Today, assembly language is never used for large projects (for obvious reasons), but when it is used (e.g. game loop optimisation) - and by an expert of on the target CPU - then the best a compiler can do here is to equal the hand-written version... --> Now, with that...if you compile the SAME C++ program with different compilers, you will get very significantly different machine code outputs with each compiler. Today's programmers badly need to think deeply as to why this is, and, what effects it can have on your program (hint: speed, size, bugs)... What this means if that there is very significant room for equally significant optimisation using assembly language.
@4lpha0ne
@4lpha0ne Жыл бұрын
Instead of forcing the use of linked lists in assembly, I'd go for different approaches, sometimes as simple as resw.
@nathanbaggs
@nathanbaggs Жыл бұрын
Yup there are always multiple solutions to problems. I wanted to implement something non-trivial in assembly, so opted for a dynamic memory structure.
@Italya3343
@Italya3343 Жыл бұрын
Many thanks aks for sharing your AMAZING project 👏👏👏🔥✌ Please consider making end-to-end tutorials for the whole project. 🙏 That will be extremely helpful for c cpp assemly learners. Maybe more similar projects in the future Many thanks in advance! 👍
@nathanbaggs
@nathanbaggs Жыл бұрын
Glad you enjoyed it. I’d like to try out some tutorial content in the future
@coolbrotherf127
@coolbrotherf127 Жыл бұрын
One thing you did in your code that I've never thought about doing is writing out the function logic as a comment block under each prototype on the header file. I could see how useful that would be for other devs who don't want to drive into the specifics of every function, only what they do and return in an abstracted way.
@nathanbaggs
@nathanbaggs Жыл бұрын
Glad you found it useful, I'm a sucker for writing code documentation (:
@monstereugene
@monstereugene Жыл бұрын
Bro I was just making breakout in JavaScript lol
@nathanbaggs
@nathanbaggs Жыл бұрын
Good luck!
@i.e.4961
@i.e.4961 3 ай бұрын
In our class we made breakout in c++ with qt framework
@mattreigada3745
@mattreigada3745 Жыл бұрын
I’m a bit lost as to why you would need linked lists for breakout. Breakout is a game that could be handled pretty easily using only the data segment to define your static array of bricks and player tokens. Biggest pain I foresee is the gameloop, graphics, and IO but none of that should require dynamic memory.
@nathanbaggs
@nathanbaggs Жыл бұрын
Sure it might be a bit over engineered, but I had a rough design that I wanted to implement three times - and that included a dynamic data structure. So maybe my phrasing wasn’t accurate, I didn’t “need” a linked list. If I was making a “real” game definitely I’d think a bit more about what data structures I used (:
@AbAb-th5qe
@AbAb-th5qe Жыл бұрын
A 2d array would be better than using linked lists
@amyshaw893
@amyshaw893 4 ай бұрын
​@@AbAb-th5qei mean, at the assembly level you could do it with a big int. If a bit is a 1, there's a block there. If it's a zero, there's no block
@AbAb-th5qe
@AbAb-th5qe 4 ай бұрын
@@amyshaw893 Yes of course. But it'll need an equivalent amount of bits either way. The only difference is how you interpet them. However, linked lists in this situation will make for more indirection, more work and more memory used. C doesn't have big ints AFAIK, but it does have character strings. These can be abused to do kinda pseudo big ints. Come to think of it, x86_64 asm doesn't have native big ints either right?
@amyshaw893
@amyshaw893 4 ай бұрын
@@AbAb-th5qe wouldnt a 2d array need a full byte for each element? im not sure if you can make a 2d array of single bits, plus that doesnt include the array overhead
@40NoNameFound-100-years-ago
@40NoNameFound-100-years-ago 4 ай бұрын
Thanks for the video, waiting for more like this video with othe programming languages
@CloudlessStudio
@CloudlessStudio Жыл бұрын
I thought I knew how to code a little at least, and then I watched this video lol! You’re a genius
@nathanbaggs
@nathanbaggs Жыл бұрын
I’m glad you enjoyed the video! I certainly don’t consider myself that, it’s just hard work and practice, good luck on your journey
@sorry4all
@sorry4all Жыл бұрын
You still code assembly faster than I do in python
@handleneeds3charactersormore
@handleneeds3charactersormore Жыл бұрын
Well that's kinda to be expected, assembly is compiled and one step from machine code and python is an inefficient interpreted language
@LevaniaMeyano
@LevaniaMeyano Жыл бұрын
@@handleneeds3charactersormore I think you're misunderstanding what op is saying and bringing up unrelated points to the comment at hand.
@fichko8513
@fichko8513 8 ай бұрын
@@handleneeds3charactersormore He meant That he isn't able to finish writing up Python scripts in as short amount of time as the creator can in assembly
@thehungrysage
@thehungrysage 4 ай бұрын
@@LevaniaMeyanothere's that one unwritten rule: whenever python is mentioned, the inefficiency of python must also be mentioned.
@saultube44
@saultube44 Ай бұрын
​@@handleneeds3charactersormoreTell that to Java
@khatharrmalkavian3306
@khatharrmalkavian3306 Жыл бұрын
Trying to wrap my head around how confused you would have to be to implement a linked list in assembly, or why you'd implement an allocator for a small dataset with a static maximum length.
@officialmichel4868
@officialmichel4868 Жыл бұрын
Nerd
@Vor10min.
@Vor10min. Ай бұрын
Linked Lists are trash. Because CPUs are not optimized for such unpredictable operations.
@abdox86
@abdox86 Жыл бұрын
Can’t be disagreed, when I first learnt assembly I fall in love with it, but as I go I was trying to build more complex stuff like floating point arithmetic, and visual stuff it just sucked , because I have to implement everything from the scratch. Any event it’s amazing work you have done , thanks for sharing.❤❤
@v01d_r34l1ty
@v01d_r34l1ty Жыл бұрын
^ That's how I feel with C lol
@abz4852
@abz4852 Жыл бұрын
Did somebody say Scratch????
@abdox86
@abdox86 Жыл бұрын
@@v01d_r34l1ty big reveal when u come to C after assembly, though when I first used python, I realized C still scratch 😂😂😂
@abdox86
@abdox86 Жыл бұрын
@@abz4852 scratch is my first name😅😅
@ME0WMERE
@ME0WMERE Жыл бұрын
@@abz4852 oh god, fuck that language it's a very similar experience to what the original comment has described, but it's many orders of magnitude slower and _incredibly_ restrictive
@mohammadalaaelghamry8010
@mohammadalaaelghamry8010 9 ай бұрын
That is very useful and impressive. Thank you.
@shorttimer874
@shorttimer874 Жыл бұрын
All this is way over my head, I used C in the past but that was in the eighties running on SCO Xenix. But I do remember the code for this same game written in the Basic that came with the first gen Apple 2, I doubt if it was much longer than 30 lines due to the graphics and paddle capabilities that Woz built in when he wrote the language. It ran seamlessly on a 1Mhz CPU with the 32k Ram I started out with.
@kpbendeguz
@kpbendeguz Жыл бұрын
Well if you code in assembly with a c++ mindset no surprise you'll find c++ more comfortable. Same happens if you come from python to c++. Not to care about pointers and memory allocations is a "breath of fresh air" in python after c++. However if you do care about efficiency you'll find python frustrating, since you can't controll what the computer is actually doing. So if you learn the c++ mindset you'll find python extremely limiting. The same applies to assembly: if you wanna squize the last bit of performance out of the computer you'll find c or c++ limiting after assembly. Of course it doesn't really apply to moder PCs but could be a real issue with programing microcontrollers, 8 bit retro computers or other devices with limited resources.
@jlewwis1995
@jlewwis1995 4 ай бұрын
Yeah for one thing I was like why TF do you need a linked list for a breakout game??? For the assembly part you could just do what people do for retro PCs and just take a big chunk of heap memory and slice it up into a memory map for the game to use with pointers for each part, one part of the memory can be for the ball, one part for the bricks, etc, there's no need for a linked list or any sort of fancy data structure like that for this simple type of game...
@01001000010101000100
@01001000010101000100 Жыл бұрын
Come on, you can use any C/C++ libraries with assembly too. Maybe it's not very easy, but coding in assembly doesn't have to mean coding every single part of the code in assembly. For me the most effective way to code something like a game is mix various languages. Where you need high complexity - high level languages, high performance - C++, C, assembly. I found C# is like perfect for some complex (or dynamic) data structures, high-level protocols handling, but it's not good to just push bits from one place to another with consistent timing. C is perfect for pushing bits reliably, but handling complex things with it gets tedious. C++ is something in between. The speed of C, but it's a little easier to add some more complexity without writing too much. BTW, C flavored C++ is a cool thing. You just use C++ like C with namespaces ;) That approach works surprisingly well in some scenarios.
@modolief
@modolief 4 ай бұрын
OUTSTANDING video. Thanks so much.
@ilbinek_
@ilbinek_ Жыл бұрын
Wasn't disappointed with this video, great work. I got a class this semester that specialises in the architecture of computing units. It's mainly aimed towards optimisation. Going from single thread unoptimised code to heavily multithreaded, optimised in all aspects, vectorisation, working with cache more effectively, reading less and what we need. Understanding how CPUs manage to do more per clock and how you can help it as a programmer with properly designed code. That's just something awesome. But yeah, you're not gonna expand your for loop, let it read 4 different values behind each other, because it takes three clock ticks to actually get it and work with it, so your code would do nothing. That's just a small part the work compilers do for us and I personally think that is awesome. They are written by smarter, more experienced programmers and are in development for longer than I am alive. No point in drag racing them. I got to say, had one class about assembly and I don't even know where I would start if I were to try to implement something in it, not to mention with GUI. Great video showing that going deeper doesn't always mean faster. Can't wait for the next one titled "I tried to write something in binary by hitting neutrinos with my HDD (just kidding, used Emacs plugin)"
@nathanbaggs
@nathanbaggs Жыл бұрын
Thanks! Glad you enjoyed it
@ChipterLP
@ChipterLP Жыл бұрын
Sounds a lot like the legendary APS class at CTU FIT
@ilbinek_
@ilbinek_ Жыл бұрын
@@ChipterLP You're remarkably close. But it's AVS class at BUT FIT :D
@MrHaggyy
@MrHaggyy 4 ай бұрын
A really useful challenge for me was taking something as simple as a linked list and go from Python to C++ to C and assembly. On the way i dropped a view things like C++ had a dynamic type and a static typed version. C and assembly only had static types. And i always used the the knowledge as well as the generated code from previous versions. This challenge really lets you think about what you are actually doing with high level features.
@techwithmatheusmello
@techwithmatheusmello Жыл бұрын
You are such a legend, well done.
@nathanbaggs
@nathanbaggs Жыл бұрын
Thanks! Glad you enjoyed it
@6754bettkitty
@6754bettkitty 3 ай бұрын
Despite not writing in it since college when i used these little embedded project boards, i think my experience with assembly is invaluable. It allowed me to better understand how things work under the hood when programming in higher level languages, like C and C++. I would love to program in assembly, but it is way too tedious to do so for the code i write. We should be thankful to the creators of higher level languages who abstracted away the tedium of assembly and made programming much less tedious. Great video, btw!
@sofiaknyazeva
@sofiaknyazeva Жыл бұрын
Wow this is awesome! Somehow you're so much underrated, anyway, I subbed.
@nathanbaggs
@nathanbaggs Жыл бұрын
Glad you enjoyed it!
@Dulge
@Dulge Жыл бұрын
man im so glad you getting recognition, keep it up
@nathanbaggs
@nathanbaggs Жыл бұрын
Thanks (:
@CarloObrad
@CarloObrad Жыл бұрын
100th like keep it up bro awsome content
@jamesbutcher3297
@jamesbutcher3297 Жыл бұрын
Great video, this is the kind of stuff I work with daily. How come you keep implementing linked lists? Would a normal array not work fine here? Linked lists are often more trouble than they are worth because of the memory overhead in each element and it is comparatively much more computationally expensive than a typical array.
@nathanbaggs
@nathanbaggs Жыл бұрын
I went for simplicity over efficiency. I didn’t have to worry about bounds checking, resizing and copying elements (for dynamic array). Just allocate a node and wire up the pointer!
@jppittman6067
@jppittman6067 Жыл бұрын
@@nathanbaggs there’s a realloc function on the c standard library that does the reallocation and copy (if necessary) in one go.
@samueldevulder
@samueldevulder Жыл бұрын
yeah: in ASM the only structure is array (possibly of records). You do not need memory management in ASM. You work on your own private array statically allocated with your program.
@drivers99
@drivers99 Жыл бұрын
You can also implement a linked list in an array. One node could have the array index of the next node.
@samueldevulder
@samueldevulder Жыл бұрын
@@drivers99 yes sure, index is just a local pointer relative to the array. But higher level structure aren't natural in ASM. Better use data structures better suited to your language. Low-level langage imply low-level data structure.
@captainswing4040
@captainswing4040 Жыл бұрын
1:09 about malloc you can use C library functions in assembly program perfectly well you just need to take care of the ABI
@nathanbaggs
@nathanbaggs Жыл бұрын
A valid point but I wanted to try without libc and just use syscalls
@captainswing4040
@captainswing4040 Жыл бұрын
@@nathanbaggs oh alright then great video very inspiring makes me want to start my own project
@noelbhe
@noelbhe Жыл бұрын
First of all probs for this cool interesting video. Secondly I need that theme xd
@nathanbaggs
@nathanbaggs Жыл бұрын
Glad you enjoyed it, the theme is Dracula
@noelbhe
@noelbhe Жыл бұрын
@@nathanbaggs Are you using the normal, or the Soft one?
@ferreirog
@ferreirog 21 күн бұрын
Always remember the costs associated with the coding and maintenance of the code. But that is part of losing knowledge, people are forgetting the basics learned from the 1960s through 2000. Great video again!
@megax5000
@megax5000 Жыл бұрын
you guys wanna REALLY have your minds blown? nearly all 8-bit and 16-bit games were designed in assembly let THAT sink in
@notvoidz
@notvoidz Жыл бұрын
i like the way he is so on point.
@nathanbaggs
@nathanbaggs Жыл бұрын
Thanks, my goal was to keep it succinct.
@leifhenriksen5779
@leifhenriksen5779 Жыл бұрын
I would love to see an in depth video on the x86 version
@SevenThunderful
@SevenThunderful 2 ай бұрын
In assembly you have access to all the standard Microsoft libraries and with a decent Macro Assembler like FASM, you have macros to handle those function calls. Moreover something like tail call optimization is usually just a jmp call in assembly, while impossible in C, unless the compiler provides it. Some of those macros are pretty powerful and you can actually be productive in assembly. The main problem is that it's not portable.
@tigros999
@tigros999 3 ай бұрын
i wrote a thing like this way back in Turbo Pascal, fun fact the pascal compiler was written in assembler, still amazes me to this day!
@jhoco7270
@jhoco7270 Жыл бұрын
Love the brevity of your video while also keeping it easy to digest! Keep it up! Also really like the theme that you're using, seems easy on the eyes. Mind if I ask what it is called?
@nathanbaggs
@nathanbaggs Жыл бұрын
Thanks for the feedback (: The theme is Dracula
@ZeptionT
@ZeptionT Жыл бұрын
Reminds me of the guy who programmed an entire roller coasters game in assembly.
@DemonixTB
@DemonixTB Жыл бұрын
hey man, first, congrats on making something that complex in assembly without years of experience in it! I feel like you took a very wrong approach to coding in it and C though. The first realization should have been that you don't need a linked list, or a malloc, you need only do the steps required to run the game, just mapping a few memory pages and getting a pointer to the window vram from the kernel is all you should really need (as well as communication messages between the os and you but you had to do that regardless). Ofcourse working without the niceities is tough if you've never done it before so it seems like the only thing to do in x86 assembly is to look at it and start your IDE with a normal language on it, but there are still very good uses for assembly programming, though not directly in assembly. What is done (most commonly in the games industry because that's one of the last places where getting everything out of your computer matters) is you take a very unoptimized problem, you shrink it down through regular optimization, and then you apply SIMD to it. What's that? Yeah there are special assembly instructions a C compiler will never use, unless you tell it to, and even then unless you structure your data right, it won't get to use them. These instructions can process whole arrays of numbers or even matricies of numbers at once, there are instructions for ray intersections, for regex filtering text 16 letters at a time, cryptographic functions, all these can be done by specialized wiring inside the cpu extremely more efficiently then any high level code could. And that's mostly the only place assembly should be used, because as you've discovered, it's a pain. Thanks for sharing it with us!
@nathanbaggs
@nathanbaggs Жыл бұрын
I might have over engineered the assembly design a bit, which has been pointed out in a few other comments. But I wanted to see how easy it was to create comparable solutions across the three languages, which includes dynamic memory allocations. I wouldn’t consider myself an assembly expert but I’ve read/written enough to get by. So I’m familiar with SIMD, etc.
@be1tube
@be1tube Жыл бұрын
You can use libraries and call functions in ASM. If I'd been writing in ASM, I'd have used SDL and libc. Just because you're writing in one language doesn't mean you can't call functions written in a different language.
@Moustafa59665
@Moustafa59665 Жыл бұрын
Damn I thought you had like 200k subs or even more judging by the qualities of your videos. You have earned your self a new sub Ps could you make tutorials for c++ :(
@nathanbaggs
@nathanbaggs Жыл бұрын
Thanks for the kind words! I've been considering making some tutorial content, do you have any specific part of C++ in mind you would like tutorials on?
@davidlean8674
@davidlean8674 4 ай бұрын
In the '80's it was easy to write apps in Assembly that were faster than C. Since then the microcode in microprocessors got far more sophisticated. The longer pipelines & similar sophistication are things that compiler writers spent a lot of time optimising their output to take advantage of. But you have to think of all that with you are also dealing with the logic of your code. Thats tough.
@bren007pie2
@bren007pie2 Жыл бұрын
This seems to be out of the scope of the video but I'd be curious to see some sort of performance benchmarks in terms of FPS comparison between all of them! Would be cool to see how little or much the pain of low-level programming is for speed.
@jorgeherrera1074
@jorgeherrera1074 Жыл бұрын
Language won’t give you any speed benefits considering today’s optimizations within the compiler. Listen to Lex Fridman podcast with Bjarne Stroustrup and he talks about this.
@jeffspaulding9834
@jeffspaulding9834 Жыл бұрын
@@jorgeherrera1074 Depends on your compiler, really. For Arm, Intel, Power, SPARC, etc. there's rarely any chance you'll outperform the C compiler. Some lesser-used architectures don't have any good C compilers (or charge a fortune for them), so there are still places where hand optimization is useful. PIC comes to mind here - I don't know how it is now, but back in the day the only free compilers available weren't very good. You could pay for better ones, but it wasn't cheap for a hobbyist. I suspect that's a major reason the ATMega got used for Arduino over the PIC, which was more common in the industry.
@bren007pie2
@bren007pie2 Жыл бұрын
@@jorgeherrera1074 Good to know this is generally the case and thanks for the reference. I'll check out the podcast!
@bren007pie2
@bren007pie2 Жыл бұрын
and @@jeffspaulding9834 also very good to know that this is not always the case. I'm curious to know what hardware has unoptimized compilers. I rarely write embedded software so hopefully I should be safe using the C compiler most of the time!
@jeffspaulding9834
@jeffspaulding9834 Жыл бұрын
@@bren007pie2 PIC is the biggie - if you don't pay for Microchip's compilers, you're stuck with unoptimized code. I looked around and things seem to be improving. Lots more microcontrollers have gcc or clang support these days. Some manufacturers still recommend commercial compilers, but gcc seems to be gaining a lot of traction.
@tricky778
@tricky778 Жыл бұрын
You didn't need a linked list (an array is plenty for your game) and you didn't need to implement x11 directly. C doesn't provide graphics libraries any more than assembler does so if you allow yourself to link libs in c then you can allow yourself to link them in assembler.
@allentchang
@allentchang Жыл бұрын
Yeah, I created a similar game in assembly and didn't use any exotic data structure
@FrozenKnight21
@FrozenKnight21 Жыл бұрын
Okay, I have to ask, why did you have use malloc in ASM? It sounds like you litterly reinvented the wheel, because of your familiarity with how you are used to doing things. Having coded in all 3 languages myself here is what I can say. Don't expect any hand holding in ASM, if you're doing things the same way you did it in a compiled language you're probably doing it wrong. Examples are, coding while using a compile anywhere mentality. ASM by definition is machine specific. Your targeting specific hardware, using a specific OS. Once you realize this you will find in every OS a specialized memory management API. You then have to think how that API is meant to be used. Then make it do what you want. At my peak I got to 50/50 when comparing my code to compilers. Half the time I could beat them in both size and execution speed. It only got better if I peaked at their output and used that to optimize mine. You probably have no idea how often compilers tend to add a ton of unessarry stack management. If your good you can manage your entire stack with math and free up your stack frame register to be used as a generic register. C is the baseline I compare all languages against. Its simple no nonesese calls and structure generally makes this one of the simpler languages to work with. C++ is what I use when I need lots of easy to implement data structures. Of the 3 languages this is the one where data management takes the foreground. This might be a bit overkill for a breakout game. As most of your data structures are ideally just arrays. So if I were to equate the languages as tools to move boxes. ASM is using tweasers, C is just picking them up manually, and C++ is the forklift. And don't get me started on what you can do when you realize you can export libraries in c and c++ to be used with ASM, and you can use inline ASM in both C and C++. These languages are litterly interchangeable.
@mityaboy4639
@mityaboy4639 Жыл бұрын
i might be the old one here but i remember writing a breakout game in ASM and i had no issues with memory to get more banks or issues with the data as i could get away using the video memory instead of an array of blocks. and a counter to know if we ran out of blocks. and it was running just fine - sure there was no windows / gnome (x) to worry about as it was dos based, but if anything it was TOO fast, so had to slow down the bounce to whatever millisec to be playable. (of course C compilers are making much more effecient compiles, but it does not make a difference at such a low complexity game and where you have to slow it down anyway) and we are talking about 8MHZ cpu speed and not 4.2GHZ with 16 cores :) i agree writing the code is easier on higher level languages, but i reject that there is no fun and excitement working in ASM. at least for me it was fun
@luicecifer
@luicecifer Жыл бұрын
True. What is hard to see here is the fact that writing in such a low level language as assembler in such a high level operating system feels very obsolete. I also think I sound like the old one here, but when you have nothing but a blazing fast 20 mhz machine and a brand new, 1000$ EGA graphics card, you'd LOVE this low level ability to manipulate any register to your likings, twitching and twisting the bits around, just for this one, little more of speed you MIGHT get out of it. It's like playing with lego blocks, a craft with a very hand made feeling to it.
@nathanbaggs
@nathanbaggs Жыл бұрын
I think I could have made myself clearer in the video. Instead of “I needed a linked list” I should have said “I wanted to write a linked list” - and the reason for that is I felt it told a better story of how each successive language made development easier. As you and others have pointed out, there are alternative/simpler ways of storing data.
@mityaboy4639
@mityaboy4639 Жыл бұрын
​@@nathanbaggs Don't get me (us) wrong we are not here to fight or lecture you :) the mere fact that someone is still attempting to do ASM is great :) But on one thing we are going to disagree :) Actually your attempt did not show the real picture of how each language made development easier. See forcing linked list on ASM is something absolutely not language 'correct' I would say using the standard ways of storing data would have showed how different and what benefits the new languages are bringing. I mean once you had your linked list library, its frankly no different on the surface than calling some high level functions in C / C++ since now you HAVE it thanks to your library. What your approach showed that ASM is capable of having whatever a high level language has, but it does not show the real progress. i mean this is a good example: call cls jmp $ cls: pusha mov ah, 0x00 mov al, 0x03 ; text mode 80x25 16 colours int 0x10 popa ret (copied from stackoverflow for easier reference) this is what you did with the linked lists. :) But now there is no difference between invoking a high level CLS or this here... So in fact you blurred the boundaries :) i think what would have made more sense is to show how you get data in and out from say the graphics card memory to handle collision detection and then show how much easier it is to use an array or a linked list. the same would go for keyboard handling, or writing text on the screen... etc :) anyway, it is a good video, so keep up the good work :) you are onto something here and i am sure great success is ahead of you :)
@mityaboy4639
@mityaboy4639 Жыл бұрын
@@luicecifer I agree, coding in assembly in the day and age when you have layers upon layers between you and the hardware is obsolete for "everyday coding". but it has the benefit of learning how actually the CPU is working under those layers. it might help someone to think when they write their highlevel code. (lets talk about the predictions the CPU makes and calculates ahead just to throw away everything it failed with the predictions - IF statement in a loop for example) For non everyday coding however where every cycle counts assembly is the best friend besides C / C++. (when maybe a millisecond decides between a disaster and a successful landing on Mars - and you can't afford running a multilayered system for limiting errors and resource eating) :) :) and ASM is such a highlevel coding compared to punchcards anyway :D :D
@nathanbaggs
@nathanbaggs Жыл бұрын
Thanks for the feedback, I can only make the next video better (:
@sussus4914
@sussus4914 Жыл бұрын
The asm version appears to run slower than C/C++ versions. That says alot about compiler optimization. I would try turning off optimization, compiling and running to see if that makes a difference
@BW022
@BW022 Жыл бұрын
More likely, it says things about data structures or algorithms build into C/C++ libraries. If it was code for code, compiler optimizations on a game like this would be minor.
@joaorocha8754
@joaorocha8754 Жыл бұрын
insightful experience. You should try to that similarly using Rust, it's not very different from C++ (you might need to "let go" some C/C++ concepts) but it's interesting language (kinda boring also, but the safety is worth it).
@nathanbaggs
@nathanbaggs Жыл бұрын
The amount of people in the comments mentioning rust was not unexpected. It’s on my todo list to learn, I want to spend some time with it before I can do a fair comparison
@joaorocha8754
@joaorocha8754 Жыл бұрын
@@nathanbaggs That's the best approach to Rust imo. You'll see why once you learn it ;). The official docs are great also
@jcamargo2005
@jcamargo2005 4 ай бұрын
You don't need linked lists. You have a memory buffer containing the bricks, you need one bit to activate or disable a brick
@JacintaDejohn
@JacintaDejohn 5 ай бұрын
very cool!
@khatdubell
@khatdubell Жыл бұрын
Love the bit about "the assembly can only be as good as i can write it" A lot of people seem to think that writing in asm is racing stripes to make the computer go faster. Humans should do the things humans are good at and leave the things computers are good at to computers.
@guytech7310
@guytech7310 Жыл бұрын
In the past using inline assemble did help when compilers didn't have the optimization they now have. In some instances a significant performance gains could be done. Usually instead of writing an entire application in assembly you wrote a few specific functions that are imported into C/C++.
@minneelyyyy8923
@minneelyyyy8923 Жыл бұрын
but assembly was made for humans to write. it's what the intel manuals for x86 programming cover. people have, and continue to write faster assembly than a compiler. usually because of them making use of certain instructions that the compiler doesnt.
@khatdubell
@khatdubell Жыл бұрын
@@minneelyyyy8923 So were punch cards. I don't see anyone stumping for that. As far as a human beating a compiler, maybe on a single function or optimizing work the compiler has already done, but toe-to-toe, human vs machine the machine will win every time on any non-trivial program. i'll bet my lunch money on that.
@minneelyyyy8923
@minneelyyyy8923 Жыл бұрын
@@khatdubell punch cards are a funny example considering that no modern computer can even understand them, thats very clearly an old technology. assembly, however, is often benefitial in small amounts. it is necessary, too, for things like osdev or writing low level code for the os.
@guytech7310
@guytech7310 Жыл бұрын
@@minneelyyyy8923 Compilers will used advanced instructions. It really depends on setting the compiler settings. About 25 year ago C compilers defaulted to the 386 or 486 instruction set, and if you wanted to use the extended instructions of i486, Xeon, you had to enable the compiler setting. The issue with using extended instructions was that a lot of machines had processors that didn't support the extended instructions. I believe today compilers all have the extended instruction sets enabled.
@fredg8328
@fredg8328 Жыл бұрын
Why would you need a malloc and a linked list for a simple breakout ? You only need a fixed amount of memory to store the level and the graphics. Just use data and bss sections. Anyway I never coded in assembly on Windows but I'm pretty sure there are Windows functions to allocate memory dynamically.
@nathanbaggs
@nathanbaggs Жыл бұрын
You’re right, you don’t need it, I think I could have been a bit more explicit with my choice of words. Also something I could have been clearer on is that this was written using WSL, so it’s all Linux syscalls.
@davidyoder5890
@davidyoder5890 Жыл бұрын
And then there's Tom who worte Rollercoaster Tycoon entirely in ASM. Wild.
@airstrike5062
@airstrike5062 7 ай бұрын
"In this video, we try to create linked lists directly in x86 to learn how painful that is"
@ChronicoOne
@ChronicoOne Жыл бұрын
I've been curious about the best way to implement graphics in assembly, and this video gave some great insight on the topic. Unfortunately, it also discouraged me from ever wanting to make anything in assembly. 😅
@nathanbaggs
@nathanbaggs Жыл бұрын
Glad it was helpful! For me programming in assembly was more for the challenge, but don't give up!
@ChronicoOne
@ChronicoOne Жыл бұрын
@@nathanbaggs Yes it is quite a good way to challenge yourself. And it's definitely a good way to get more familiar with hardware too.
@ipodtouch470
@ipodtouch470 Жыл бұрын
Look up what a bitmap is. Also there is a really nice mips assembly emulator that helps when learning assembly by the name of mars
@camthesaxman3387
@camthesaxman3387 Жыл бұрын
You can use the same libraries you use in C/C++. Just that you have to be aware of calling conventions when calling library functions.
@pokefreak2112
@pokefreak2112 Жыл бұрын
I'm curious why you implemented malloc for the x86 version? I've done some simple games targeting wasm without libc and had no issue just putting everything into a statically allocated buffer
@nathanbaggs
@nathanbaggs Жыл бұрын
You’re absolutely right I could have done that. I wanted to try and keep the three implementations similar - C and C++ used dynamic allocation so I wanted to see what it would take to do that in x86.
@PhilipBarton
@PhilipBarton Жыл бұрын
@@nathanbaggs Conceptually I understand, but as a counterpoint you have programmed in C like a C programmer, in C++ like a C++ programmer, and in x86 like a C and C++ programmer. You've made a good video. I was expecting to see a comparison of programming languages paradigms, and didn't find that.
@khatdubell
@khatdubell Жыл бұрын
@@PhilipBarton He also could have put everything into a statically allocated buffer in C and c++. Its not "thinking like a C programmer" to dynamically allocate memory. Its part of writing more than a basic program.
@marcossidoruk8033
@marcossidoruk8033 Жыл бұрын
@@khatdubell the simple approach is often the best one, a "basic program" is what you should aim for. If there is no need for dynamic allocation, doing it just makes you code objectively worse.
@maxoumimaro
@maxoumimaro Жыл бұрын
@@marcossidoruk8033 only using static allocation isn't a solution tho. It still makes things complicated, because you need to separate it into chunks. Same thing with dynamic allocation, using mmap gives you a page of memory (so 4096 bites) that you need to cut into chunks. You could very well just ask mmap for way more memory memory a single allocation and then do your thing. At the end of the day, mmap will return you consecutive memory because of the layer of kernel abstraction around memory.
@yash1152
@yash1152 7 ай бұрын
1:27 couldnt u link the .a files for these functions & use those as library?
@camthesaxman3387
@camthesaxman3387 Жыл бұрын
No idea why you'd need a linked list to implement Breakout.
@flameofthephoenix8395
@flameofthephoenix8395 3 ай бұрын
Every time the ball hits a brick you have to append a 1 to a linked list, this is necessity for Breakout. Otherwise, you can't really call it Breakout.
@sketchtheme
@sketchtheme Жыл бұрын
So good to watch it, I wanted to really learn asm, but it's so hard, I do c and c++ for my university's sake but work with python. How much time did you need to master asm? And what do you think should I learn it for cyber security?
@theforeskinsnatcher373
@theforeskinsnatcher373 Жыл бұрын
In my uni we learn assembly in the first semester lol. Many people dont even know how to code yet.
@LukasCobblerxD
@LukasCobblerxD Жыл бұрын
@@theforeskinsnatcher373 what uni?
@nathanbaggs
@nathanbaggs Жыл бұрын
I am by no means a master, just know enough to get by.
@sketchtheme
@sketchtheme Жыл бұрын
@@theforeskinsnatcher373 that's a ordinary thing, just focus on yourself ✊
@sketchtheme
@sketchtheme Жыл бұрын
@@nathanbaggs Oh, I see, still big respect!!!
@zipur3364
@zipur3364 Жыл бұрын
Wow, did not know about std::optional, that's awesome!
@nathanbaggs
@nathanbaggs Жыл бұрын
It was introduced in C++17 and was a real game changer for me in terms of API design. No need to bother with out parameters. It combines nicely with if statement initialisers, so you can do: if (const auto v = func_returning_optional() ; v) { }
@nathanfranck5822
@nathanfranck5822 Жыл бұрын
Yeah I was learning zig for highest performance generated assembly, but I've been drifting back to typescript for the comfort and ergonomics. Programming in assembly sounds like major lock-in to your hardware. I should really just be coding in c++ but I've got a huge contrairian streak.
@guytech7310
@guytech7310 Жыл бұрын
Depends on the application, but a good performing application written in C/C++ probably isn't going to be portable, & it also dependent on the libraries used. For instance if your code used Windows libraries on a Linux or non windows machine, its not going to be portable. Portabile application are usually very limited or are slow if the use cross platform libraries for GUI, or OS specific functionality.
@martinprochazka3714
@martinprochazka3714 Жыл бұрын
Yes, you're right but if you're using OS specific functionality there's no reason for it to be crossplatform. Like Java for example works everywhere because it makes it really hard to do platform specific things. Obviously you can always for example assume mounted sysfs and your windows build will fail at runtime no matter the language. What's good about C is that you can compile time branch the behaviour with preprocessor which effectively allows you to go crossplatform while using peculiarities of each supported platform. You have to design your application with the crossplatformness in mind from the getgo adding it later would be a pain in a large project.
@RickeyBowers
@RickeyBowers Жыл бұрын
There is a mindset for each programming language. Similar to how a spoken language has depth of expression with more experience.
@nathanbaggs
@nathanbaggs Жыл бұрын
Yes, I like the phrase “idiomatic usage”
@gustavcoetzee5018
@gustavcoetzee5018 Жыл бұрын
Awesome
@blastygamez
@blastygamez Жыл бұрын
Pretty cool nice job
@nathanbaggs
@nathanbaggs Жыл бұрын
Glad you liked it!
@mrpsychodeliasmith
@mrpsychodeliasmith 4 ай бұрын
Very interesting. Surely the next step is to code the game in C# (or Java) to exploit the next level of abstraction in terms of memory management?
@rolandmetivier4437
@rolandmetivier4437 5 ай бұрын
In NASM you can use “wrt ..plt” to call C functions. I think C/C++ is nicer though, you can use Intel intrinsics for SSE/AVX too.
@fahnub
@fahnub 3 ай бұрын
Didn't know about type safety before this vid
@TheRealWinsletFan
@TheRealWinsletFan 2 ай бұрын
If you approached the asm with an old school mindset you would have simply skipped the malloc and linked list for a project this simple. Neither would be necessary. In simple systems we used and reused static buffers defined in the assembly directly, and linked lists if used at all were usually using embedded pointers in the statically allocated objects. Though right enough larger systems typically ended up writing much of the same code a C runtime includes. FWIW once the C compilers evolved enough to generated decent code, everyone, barring a few stick in the muds, switched to using C with asm used only to enhance performance where it was most needed.
@TheEvertw
@TheEvertw 3 ай бұрын
There is a reason why C is still VERY popular and still the language of choice for creating Operating Systems and other low-level code (though Rust has become a viable alternative). That is what it was designed to do. But the creators of C never intended it to be the universal language. In fact, they didn't believe in a "universal programming language". They created a host of other languages for specific purposes, some narrow and some wide.
@areSOFT1
@areSOFT1 5 ай бұрын
While C/C++ compiler optimizations are usually faster than normal assembly code, note that optimized assembly code will be faster than C/C++ compiler optimizations.
@chrisdams
@chrisdams Жыл бұрын
It surprises me that you find namespaces an improvement. I would think that the program you are writing is small enough that you wouldn't get many, or even any, naming collisions.
@nathanbaggs
@nathanbaggs Жыл бұрын
I was writing each solution as if it were part of a larger project, in that sense I couldn't guarantee that Vector2, Window, List, etc names wouldn't clash with another library. So to me the C++ namespace is an improvement as it means I didn't have to add a prefix to all publicly exposed names.
@martinparidon9056
@martinparidon9056 3 ай бұрын
I'd be interested in a memory footprint and runtime comparisons of the 3.
@KhaziirEverflight
@KhaziirEverflight 6 күн бұрын
and now imagine creating an entire bloody theme park gamne that runs with thousaands of park visitors lategame in assembly :)
@JulenSanAlejoGonzalez
@JulenSanAlejoGonzalez 5 ай бұрын
in modern assembly u can define structs an access them very similar to what u do in C. Isnt malloc just a system call to sbrk ?
@PilaCiu
@PilaCiu Жыл бұрын
Assembly is my main programming language as a ROM hacker and reverse engineer.
@mig7287
@mig7287 Жыл бұрын
Long Live Assembly! 👍👍👍
@julianskidmore293
@julianskidmore293 Жыл бұрын
Why would you need malloc to code a version of Breakout in assembler? Surely everything would just be statically allocated and you don't need anything more than simple arrays to represent the set of bricks on the screen (e.g. 1 byte per brick with each brick within a grid: 14 column x 8 rows). An early assembly programmer wouldn't even do that, they'd allocate 1 bit per brick. Then you'd first check the location of the ball: ball_y>=brickmap_y; && ball_y
@nathanbaggs
@nathanbaggs Жыл бұрын
I think I could have been more explicit with my choice of words, I certainly don’t “need” malloc. I had a rough design that I wanted to implement three times and that included something non-trivial like a dynamic data structure.
@camengadisaputra
@camengadisaputra Жыл бұрын
Great video, and found plenty amazing comment, a lot of amazing people in comment section
@nathanbaggs
@nathanbaggs Жыл бұрын
Thanks! Yes I can’t believe the response and I’ve been enjoying working my way through the comments
@hassan7569
@hassan7569 Жыл бұрын
why were you using a linked list for the firs two then a vector (dynamic array) for the last one?
@euler4513
@euler4513 Жыл бұрын
“Stops @ 4:20” subbed
@danbance5799
@danbance5799 Жыл бұрын
30 years ago I was writing games in x86 assembly. I was 18 at the time and it was exciting to have a level of performance that I'd never been able to achieve with stock libraries that came with my BASIC and C compilers. But... yeah, that's a lot of extra work. I very quickly switched to writing my own graphics libraries in assembly and writing everything else in C. Kids today have it too easy. I could rewrite that entire project in C# in a weekend.
@EdwardChan.999
@EdwardChan.999 Жыл бұрын
I have a habit of coding Tic Tac Toe after I finished learning a new language, now onto making my 3rd one!
@punitharamasamy138
@punitharamasamy138 Жыл бұрын
Petition to release a full detailed video like a tutorial
@nathanbaggs
@nathanbaggs Жыл бұрын
I’d like to try a tutorial video, any ideas what you would find useful?
@punitharamasamy138
@punitharamasamy138 Жыл бұрын
@@nathanbaggs Any C, C++ or Assem based projects and you could walk us through step by step would be really helpful
@morizhar4836
@morizhar4836 12 күн бұрын
How did you represent the bricks in the memory ? How did you draw the bricks ?
@zin_the_one
@zin_the_one Жыл бұрын
Regarding assembly, malloc, printing, etc. are implemented by the operating system as syscalls which are a special interrupt, 0x80 on linux. Also, you can easily use any C libraries by declaring externals and linking your object files with libraries you wish to use. It's funny you said you needed malloc to have linked lists since malloc is usually implemented as a linked list in memory. Did the assembly version try to write to the drive instead of the RAM? If you didn't want to use any external code, could've simply reserved a decent block of memory for your malloc implementation
@mothcompute
@mothcompute Жыл бұрын
malloc is usually in libc or another userspace library, not the kernel
@zin_the_one
@zin_the_one Жыл бұрын
@@mothcompute True, without linking to libc, mmap or brk would have to be used, which are exposed by the kernel.
@mothcompute
@mothcompute Жыл бұрын
@@zin_the_one fair
@valizeth4073
@valizeth4073 Жыл бұрын
Thought it was gonna be one of those nonsense "writing the same game, using the same source code-ish to see the difference between C and C++" but the fact that you actually leveraged what C++ does so great (like RAII), anonymous namespaces, etc, makes it rather refreshing.
@nathanbaggs
@nathanbaggs Жыл бұрын
Glad you enjoyed it! I’ve been a C++ developer most of my career, so it’s the language I know the best
@yurkshirelad
@yurkshirelad 2 ай бұрын
It reminds us why the original Elite was mind glowingly incredible.
@yurkshirelad
@yurkshirelad 2 ай бұрын
(obviously that should be blowingly - the edit feature isn't working for me)
@Tiger_CZ
@Tiger_CZ Жыл бұрын
Did you use some custom font, or how did you get it to display the arrows and the "not equal" as one symbol? (in the VSCode)
@nathanbaggs
@nathanbaggs Жыл бұрын
I use a font called FiraCode (github.com/tonsky/FiraCode ) which includes ligatures - the funky symbols for “not equal” etc
@casualoutlaw540
@casualoutlaw540 Жыл бұрын
To add on to this, you might want to look into nerd fonts.
@Mankindux
@Mankindux Жыл бұрын
For such a simple project i'm not sure why you'd need dynamic allocation nor linked lists. Given that all levels are statically allocated on a fixed size grid.
@nathanbaggs
@nathanbaggs Жыл бұрын
You’re right I could have simplified it. I started off with a rough design which I wanted to implement three times, and that included something non-trivial like a dynamic data structure. It was fun seeing how each successive technology made development easier.
You Can Only Play This Game By Hacking It
12:03
Nathan Baggs
Рет қаралды 331 М.
LA FINE 😂😂😂 @arnaldomangini
00:26
Giuseppe Barbuto
Рет қаралды 20 МЛН
skibidi toilet 73 (part 1)
04:46
DaFuq!?Boom!
Рет қаралды 34 МЛН
0% Respect Moments 😥
00:27
LE FOOT EN VIDÉO
Рет қаралды 29 МЛН
Why Roller Coaster Tycoon is a Game Development Masterpiece
11:59
Tech Stories
Рет қаралды 954 М.
how Google writes gorgeous C++
7:40
Low Level Learning
Рет қаралды 715 М.
Making Minecraft from scratch in 48 hours (NO GAME ENGINE)
16:38
2 Years Of Learning C | Prime Reacts
22:24
ThePrimeTime
Рет қаралды 224 М.
Every Programming Language Ever Explained in 15 Minutes
15:29
Flash Bytes
Рет қаралды 212 М.
Why You Shouldn't Nest Your Code
8:30
CodeAesthetic
Рет қаралды 2,5 МЛН
Hacking a 25 Year Old Game To Make It Work
11:26
Nathan Baggs
Рет қаралды 290 М.
Projects Every Programmer Should Try
16:58
ThePrimeTime
Рет қаралды 311 М.
ЯЗЫК АССЕМБЛЕРА С НУЛЯ | #1 НАЧАЛО
54:43
When Optimisations Work, But for the Wrong Reasons
22:19
SimonDev
Рет қаралды 753 М.
LA FINE 😂😂😂 @arnaldomangini
00:26
Giuseppe Barbuto
Рет қаралды 20 МЛН