RAM & Addition - 6502 Assembly Crash Course 02

Поділитися
Вставка
  • Опубліковано 8 чер 2024
  • Learn all about saving data to RAM, Addressing Modes, and the Accumulator in the second part of my 6502 coding crash course!
    Support the channel on Patreon: / neshacker
    Github Code Along Project - github.com/NesHacker/Assembly...
    NES Development Environment - • NES Development Enviro...
    6502 Crash Course (Part 1) - • Basics - 6502 Assembly...
    Chapters:
    0:00 Introduction
    1:36 System Memory
    3:37 Example: Load & Store
    7:36 Addressing Modes
    10:24 Binary Addition & Carry Bits
    13:49 Example: Accumulator Addition
    17:51 Conclusion

КОМЕНТАРІ • 94

  • @andibausm
    @andibausm 2 роки тому +68

    This series is really great and so incredibly well animated. The level of detail you put into every snippet of code you show on screen (highlighting, zooming, bouncing letters etc.) is just amazing. Please keep up your great work and thanks a lot!

    • @NesHacker
      @NesHacker  2 роки тому +19

      It’s a bit of a time investment, but I think the little details can sometimes be the difference between a viewer understanding something or being completely confused. So I’m willing to invest that time :)

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

      @@NesHacker dude, I'd buy an extended version of this course for sure! do you have anything else on Patreon? (related to NES)

    • @BillAnt
      @BillAnt 9 місяців тому

      Best of all, the basic concepts learned here apply to any machine code programming. Sure, the opcodes and addressing modes may vary, but the logic stays pretty much the same.

  • @knghtbrd
    @knghtbrd 2 роки тому +6

    If you're following along at home, he said the 6502 had 51 instructions. Between this video and the last one, you now know LDA, LDX, LDY, STA, STX, STY, INX, INY, INC, CLC, and ADC. That's 11 instructions, you're 1/5 the way there in just two videos.
    Yeah, you can learn to do this. We all did, and many of us were kids when we learned it.

  • @Masta686Yamato
    @Masta686Yamato 5 місяців тому +3

    When I was 14, I've started learning 6502 assembly and was even able to write a simple game with basic collision detection, but later I've quit programming to pursue another career path (regretting it later!).
    Now, it is much easier to remind myself on how to program in 6502 assembly with a tutorial like yours. I also hope to learn even more! Thanks for your work!

  • @mykalimba
    @mykalimba 2 роки тому +18

    Good stuff. Just a couple of clarifications on addressing modes:
    1) For a given opcode, not only are zero-page addressing mode operations faster than their absolute addressing mode counterparts (faster meaning they take one less cycle to complete), they also take only two bytes of space (vs. three for absolute addressing mode) in the assembly output file (and thus in memory). To many people, one byte might not sound like a lot. But it could be the difference between fitting in 64K and not, or (much more likely) a branch instruction being able to reach a relative label or not.
    2) You stated that absolute addressing mode was denoted by using a "four digit hexadecimal operand". I'm pretty sure that you said that as a simplification for the example instruction, and what you mean is that you can usually identify absolute addressing mode if/when the operand is a four digit hex value. You touched on it earlier, so I'm sure you know that it is perfectly fine (in most assemblers) to use a decimal number (e.g. 768 instead of $0301) as an absolute address.

    • @NesHacker
      @NesHacker  2 роки тому +5

      Indeed, mostly was trying to keep it simple but you summarized those points quite well! Thanks for watching and posting :)

  • @robcumberland8089
    @robcumberland8089 2 місяці тому

    Although I'm not using this for the NES, I am learning to code a 6502 CPU, and as such, these videos are of a huge help.
    Thank you so much, for the time and effort that you've invested.

  • @kirby0louise
    @kirby0louise 2 роки тому +23

    Amazing video, no, all your videos are fantastic! While I personally have plenty of experience in NES/SNES/Genesis/etc.... bitmap console development and rom hacking, I get a lot of questions from people asking me how they can learn the basics of computer and console architectures. Definitely going to be recommending your channel as the first place any newbie should go from now on!!
    Cannot wait for part 3!

    • @NesHacker
      @NesHacker  2 роки тому +7

      That is so fantastic! I thought about it a lot before starting the channel and my target audience is exactly that: people who are interested in old-school game dev but don’t know where to begin. Thank you very much, I really appreciate you getting the word out :D

    • @kirby0louise
      @kirby0louise 2 роки тому +5

      @@NesHacker No problem, and it helps me too - I'm a graphics programmer in my free time and I'm working on a engine for modern PCs and consoles that has a developer-facing architecture that is based on old school bitmap graphics architectures
      So the more people who understand it, the less I have to worry about writing documentation ;)

  • @theAkaJefferson
    @theAkaJefferson 2 роки тому +12

    What an amazing series! Glad I found your channel, i've doing some research into retro game development myself and the 6502 assembly language seems like a good start, ngl I tried learning z80 assembly before and it was a complete disaster, this time I'm feeling like I can actually do it. Thanks man, keep the awesome work.

    • @NesHacker
      @NesHacker  2 роки тому +3

      Z80 weird, haha… I remember being confused by it back in the day when I was making TI calculator games. Hopefully my series on 6502 works well for you, if you have specific questions make sure to leave them down in the comments and you’re following along!

    • @makerofstartup7902
      @makerofstartup7902 2 роки тому

      @@NesHacker Thank you for first time in many years explaining Carry on flag and why it is there built it. Very good byte by byte explanation.

  • @vuurniacsquarewave5091
    @vuurniacsquarewave5091 2 роки тому +2

    You enter the next level when you start using less and less "raw" numbers. Most assemblers will allow you to name pretty much anything you want (variables or otherwise), so you will never need to type out and remember memory locations by number if you don't want to.

  • @user-uq2ks2dr4p
    @user-uq2ks2dr4p 3 місяці тому

    Oh yes and your crash course is super good. Please keep them coming.

  • @pcatgames6449
    @pcatgames6449 2 роки тому +6

    Just wanted to say that you're videos are amazing. Thank you!

  • @chaitanyabhatt7915
    @chaitanyabhatt7915 2 роки тому +2

    super high-quality content. insanely valuable and way underrated. thank you sir! i admire your skills

    • @NesHacker
      @NesHacker  2 роки тому

      I am glad you like it :)

  • @1stacbats
    @1stacbats Рік тому

    Another great episode, thank you. I have been trying to get my head around adding two bytes and storing, nicely done. Look forward to more content

  • @guillermodiazfloresvelderr7337
    @guillermodiazfloresvelderr7337 2 роки тому +1

    Great content, i think i finally understand how the carry behaves, thanks and i hope you can continue with this project!

  • @SuperSlackOff
    @SuperSlackOff 2 роки тому +1

    The editing man and transitions. Hmmm , this is quality stuff. Subbed. Thank you for this. Learning.

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

    Amazing content, a lot of time and effort invested here. Thanks a lot! For sure will recommend your channel for people interested in learning more about NES asm programming

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

    Hands down these are some of the best instructional videos I've seen in a long time! Doing a forray into 6502 will be my reward to myself once I finish my current project and don't have to spend 14 hours a day writing C# code :-) And when that glorious day comes, your vids will be right at my side :-)

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

      That’s great to hear :D, got another 6502 video coming out in January as well, I hope it helps!

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

      @@NesHacker very happy to hear! Have a great Christmas!

  • @Robert_Shmigelsky
    @Robert_Shmigelsky 11 місяців тому

    Another fantastic video! Thank you so much. On a small note, I had to google to understand what you meant by immediate. From my understanding, immediate addressing is "immediately" using the operand as a value, rather than fetching a value from memory location. I'm still fighting #10 being a constant, since we increment that value (it changes! lol). But good work.

    • @NesHacker
      @NesHacker  11 місяців тому

      Yep "immediate value" aka "not a value in memory, in the code of the program itself."

  • @Wineman3383
    @Wineman3383 2 роки тому +1

    Thanks for the great videos, they are really well put together.

  • @HylianEvil
    @HylianEvil 2 роки тому +1

    Fascinating! Thanks Ryan!

  • @torarinvik4920
    @torarinvik4920 2 роки тому +7

    Amazing stuff. I already know some 6502, but I need to learn some more. I code mostly in C++ and Python so assembly is a great challenge for a high level coder like me :) Once again... Fantastic stuff!

    • @NesHacker
      @NesHacker  2 роки тому +2

      I’m glad you’re liking it! Next episode in the series comes out at the tail end of next month, so there will be more content in the series soon :)

    • @torarinvik4920
      @torarinvik4920 2 роки тому +1

      @@NesHacker Can't wait!

  • @peteschmitz
    @peteschmitz 2 роки тому

    Love your videos so far. I've always wanted to make my own NES game since I got the NES in its release year, but I've never been a programmer. That's why I've been waiting on my NESmaker order from New 8-Bit heroes. Thus said, even though it is advertised as an program for which you won't need to code anything, I guess it will be very limited. So now I am trying to familiarize myself with how the NES actually works and maybe learn how to code in Assembly 6502 (at least somehow understand the basics) - and luckily I stumbled upon your videos that are very explained! Gonna have to rewatch the first one and download all the applications needed to reproduce what you do in your videos to make all the information stick in my memory ;) Keep up - love the bite-size videos.

  • @TylerDunphy
    @TylerDunphy 2 роки тому +1

    interesting stuff! I believe mixing up $/%/# was what caused NES tetris to increment to the next level after some "weird" amount of lines when it was originally supposed to be 10 times the level iirc! (Level 18 start increments at 130 lines instead of 180)

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

    Finally this is what ive been looking for. Thank youuuuuu!!!! :D

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

    This channel is nothing less than a gold mine 🤩👍

  • @8_BitKing
    @8_BitKing 2 роки тому +2

    yes i am ready

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

    Nicely explained. Straight forward, no faff!

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

      Yeah I’m pretty anti-faff tbh. New episode in the series coming out this week, so keep an eye out! Thanks for watching :)

  • @8_BitKing
    @8_BitKing 2 роки тому +2

    loved it, learned alot!

    • @johneygd
      @johneygd 2 роки тому

      Am i the only one who hate that he sounds too overanthusiastic along by splitting it’s subjects over several parts,because it’s getting really really annoying no matter how curious i am about learning something,it’s distracting no matter how hard i try to ignoire it.

  • @thehardcorezombie9444
    @thehardcorezombie9444 2 роки тому +1

    Your template work great out of box I was bored with high level programing so im going make games in assembly

  • @martinschader5859
    @martinschader5859 Місяць тому

    Thanks for good explanations and examples. Please continue. In this video at 16:33 there seems to be something wrong with the slide you show. You add B2 + B2 (and get the result F5).

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

    Can't wait to see how folks keep track of all these addresses. 😆

  • @claudiosettiart
    @claudiosettiart 2 роки тому +5

    Your videos are really amazing! I have just started learning about 6502 relating to NES development and your explanations are really helping the process. I have no programming experience - Are there any additional books you would recommend?

    • @NesHacker
      @NesHacker  2 роки тому +3

      Thanks! So you can always look for the MOS 6502 Programming Manual and Hardware Manuals online or get print copies on eBay. They are the definitive guide to the processor written back in the 70s. Other than that I didn’t use much in the way of books to learn NES programming, but one resource you can use is the NesDev wiki, it’s got a ton of information (though it can sometimes be a bit hard to parse).

  •  2 роки тому +2

    Love your videos.

    • @NesHacker
      @NesHacker  2 роки тому +2

      I really appreciate it! Thanks for watching, Frédéric :)

  • @cookiekixx
    @cookiekixx 2 роки тому +1

    Thank you!!

  • @twobob
    @twobob 9 місяців тому +2

    Pretty certain that is the first time in my life I actually clicked like when someone asked.

    • @NesHacker
      @NesHacker  9 місяців тому +1

      Thank you so much, I really appreciate it

  • @szaman6204
    @szaman6204 2 роки тому +2

    good video

  • @twobob
    @twobob 9 місяців тому +1

    you covered the highlights and intimated towards the other extended modes. Was digestible and that wa a great ADC example - with preamble included. I would adjust the lighting and frame you differently and cut down the intro length and other fluff nothing to do with code. But you already did most of those improvements already. and you moved the framing to hide the lamp , which was a good move for 90% of the video ;)

    • @NesHacker
      @NesHacker  9 місяців тому

      This is a very old video, I've significantly improved my lighting since then. That said, thanks for the critique, I am always looking to improve!

  • @thecout3170
    @thecout3170 2 роки тому +2

    Here is a pdf explaining how the 6502 works and its instructions: www.princeton.edu/~mae412/HANDOUTS/Datasheets/6502.pdf

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

    very useful.

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

    Not to draw any traffic away from this excellent channel, but Ben Eater also has a bunch of good videos on 6502 assembly programming including a bunch of binary math content.

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

    Thanks

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

    I was hoping to learn how to program the SNES once I finish learning the NES and I was wondering if there are any resources you would recommend?

  • @riyantan9237
    @riyantan9237 2 роки тому +3

    Great explanation, can’t wait to see the next video about this series. Thanks for sharing it man 🙏❤️…
    Btw, could you help to turn on the english subtitles for this video. I believe will need to revisit this more to fully understand all the technical stuffs.
    And it’s nice to have Vietnamese sub (I appreciate it coz that’s my country :D) but it seems not correct 😁

    • @NesHacker
      @NesHacker  2 роки тому +4

      Thank you for your kind words! And you’re watching my videos from Vietnam? That’s super cool! I had been wondering if people needed me to put in subtitles, because the language I am using is very technical. Since my videos are scripted I think I can put in my own subtitles for you and others who need them! I’ll let you know when I’ve added them to this video, and I’ll make an effort to add them to new videos on the channel when they are released. Thank you again!

    • @riyantan9237
      @riyantan9237 2 роки тому +1

      @@NesHacker That’s so nice if you can do it Ryan. For me, I see the auto-generated English caption of UA-cam (that’s u turned on for other videos) is quite enough precise, I guess it because your voice is very clean & clear :). You can consider continue to use it when having time constraint.
      I have IT background so can understand mostly what you explain about programming (even understandable for people who are not familiar with coding, I feel). Only hardware part I need to study more coz it’s quite important when coding with low level language like assembly. Your videos is helpful and enjoyable for me to learn the most difficult part 😁🙏

  • @oleschoolgamers
    @oleschoolgamers 2 роки тому

    Love the vids, but what video editor do you use to make these, I really like the format

    • @NesHacker
      @NesHacker  2 роки тому +1

      I use a Final Cut for video editing, Logic Pro for sound, illustrator for vector graphics, photoshop for raster work, and After Effects for motion graphics and some composition (such as zoom effects for the camera and such).

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

    This is an excellent tutorial. I’ve been meaning to learn assembly for ages and this is really helpful. I’ve been binging your channel all day.
    Quick question though: is there a good 6502 emulator that can run this code? Or should we just compile this into an nes file and run this on fceux link you showed in the previous video and use it’s debugger to inspect the values in memory?

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

      Fantastic question. I know they exist, but I’ve not really used them so I can’t recommend one off the top of my head. That said, I am planning on doing some tooling research for an upcoming video, so I’ll add it to the list and make sure to mention any good ones I find in the future!
      I’m very happy that you like the channel! Happy hacking :D

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

      @@NesHacker Thank you. That was such a quick response! I've just finished watching all the videos and look forward to your next upload.

  • @BillAnt
    @BillAnt 9 місяців тому

    At 6:23 threw me off a bit because decrementing 10 in location $01 would logically equal to $0F. But then I realized we loaded the decimal value 10 which was actually stored as $0A (#10 = $0A). Unless we're using BCD, my brain thinks better in hex. heh

  • @salvatorerestivo7245
    @salvatorerestivo7245 2 роки тому +2

    Thank you very much, amazing video! Why automatic sub are in vietnamense?

    • @NesHacker
      @NesHacker  2 роки тому +1

      You’re very welcome! I have no idea why the subtitles are like that… maybe I fudged a setting?

  • @user-uq2ks2dr4p
    @user-uq2ks2dr4p 3 місяці тому

    I am building a 6502 computer on a breadboard *Ben eater* Mine uses a 8k eeprom as my 32k one was sick. I use Linux and nano and vim are my editors. I have the emulator you suggested. Its great. I use vasm at the moment but I better learn to use cc65 as you do. I would like to make a Makefile to build these roms. I have a mini NES I dont know if that can be modded to run homebrew?

  • @XuryFromCanada
    @XuryFromCanada 7 місяців тому

    6:06 Does this chip allow you to just manipulate RAM directly like this? I thought you're supposed to move the value to a register, increment, and move it back? At least in x86, so I'm wondering how they did it here

  • @A.Svanidze
    @A.Svanidze 2 роки тому

    You create rare content! Thank you for a great job well done.👏👏👏
    Unfortunately, in this video, the language is defined as Vietnamese. This issue prevents the use of titles.
    Only the channel owner can change this. In the channel settings there is an item "Country of residence of the author of the channel", perhaps it is "Vietnam", and also each video has a selection with the language of the video when uploading or editing it through the "pencil" button in the UA-cam Creator Studio.

  • @dr.ignacioglez.9677
    @dr.ignacioglez.9677 Рік тому

    I LOVE C64 👍🥂🎩

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

    2:52
    So, these 3 mirrors aren't actually redundant memory, right? They are redundant entries in the CPU Mempory Map, which gives use 4 different entries from which we can access the same byte of memory. ...Right?
    Like, $0000, $0800, $1000, $1800 will all access the same first byte of memory on the 2KB RAM chip?

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

    I've watched the final sequence 4-5 times and I'm still having a hard time wrapping my head around the final arithmetic example. The carry flag (bit) can't represent the *contents* of the overflow without a loop, so how/where is that value being referenced and stored? Presumably, it's in the second address, but how/where/when does that happen?

  • @JiosX
    @JiosX 2 роки тому

    Wowww this is sooo useful. However I couldn't understand a lot of it without the proper subtitles because it was set to Vietnamese (Auto-generated which is much worse). Is there a way that this could be set to just English (Auto-generated)?

  • @inigoliz961
    @inigoliz961 2 роки тому

    I got curious about why is the RAM mirrored. Does anyone know the answer? Does it maybe have to do with error correction?

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

    It took me a second for me to realize that ADC both sets the carry flag to 1 if adding two bytes whose sum is greater than 255 and adds the carry flag to the sum of the two numbers you're adding. It feels really weird to me that the same instruction does both things! Is there a reason for having one complicated instruction instead of two simpler ones (one that sets the carry flag, another that adds it back in)?

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

      There probably is a reason, but I don't know it, haha. My guess is that it's an esoteric issue with the way the circuit was designed, or a hold over from older computers that did it that way in the past.

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

    In Regard of Page Zero: Does anybody know if this memory is part of the external memory? Or is this implemented inside the 6502 as some kind of fast SRAM - as we know from today’s Microcontrollers? I mean if one uses a 6502 with just a ROM attached to its External buslines then would it be possible to write a Program (located inside this ROM) which is able to run solely by using 6502 internal RAM for Stack and Storage?

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

      The zero page is in system memory, the 6502 doesn't have any internal memory or cache besides its registers (A, X, Y, Program Counter, Stack Pointer, and Status).
      The reason why zero page addressing is preferable is because it uses less cycles than absolute or indirect addressing modes.

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

    Why do you need to write ldx #10 and not just ldx 10?

  • @DevineInnovations
    @DevineInnovations 2 роки тому

    As someone who has only used scripting languages (and tried to learn C#) this doesn't seem as difficult as I thought it would be. Maybe I haven't gotten to the hard parts yet, or maybe it's harder to use than it is to learn. But this actually seems less confusing than C# or C++.

    • @NesHacker
      @NesHacker  2 роки тому +3

      Assembly is often previewed by programmers as being more “hardcore” or “difficult” when in reality it is actually much, much simpler than higher order languages. If equipped with a firm understanding of binary and the underlying hardware, programming is assembly is quite a bit easier than programming on top of a giant stack of abstractions, That said, assembly programming tends to be much more *verbose*. It often takes many tens of instructions to perform tasks that in high order languages can be accomplished in a few lines.

  • @anisometropie
    @anisometropie 2 роки тому

    5:00 Do I understand this correctly ?
    immediate values in decimal binary and hexa
    #100 #%1100100 #$64
    memory location in decimal, binary and hexa
    100 %1100100 $64

  • @maxgamers2944
    @maxgamers2944 2 роки тому

    hey, thats video was amazing, but i need your help so much, could you put subtitles in english?because I speak portuguese and it is difficult to understand the speech without a subtitle to translate, i will like it so much, will make my dream of making a game come true. I hope you understand

  • @JarppaGuru
    @JarppaGuru 4 місяці тому

    17:17 you did not clear carry so.... it will added

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

    Subtittles vietnamita????? whats

  • @or4cl3br
    @or4cl3br Місяць тому

    My god, what did they do with the subtitles in this video? It is difficult to translate into any language and its pronunciation is not easy for a non-native English speaker.This video is fundamental to understanding the use of memory. Tragic