💦 CREATE AND FUCK YOUR OWN AI CUMSLUT 🔥 TRY NOW ♥
Create AI Cumsluts 💦
January 29, 2020

What is a stack and how does it work?

Here it is: the next part in the 6502 journey!

I originally had planned for this video to include connecting the RAM and conclude with the stack actually working. But the video kept getting longer and longer and I was struggling to keep it concise without losing too much information. Ultimately, the whole discussion of RAM felt like a separate video, so this one just focuses on how the stack works.

I'm hopeful that the combination of cutting to make the original video shorter followed by deciding to give up and just make it two videos didn't result in losing anything important. I really would appreciate it if you let me know if I missed anything important or some part of the explanation doesn't quite make sense. I plan to release the video publicly this weekend, so I have some time to make adjustments.

All of that also means the next video is mostly recorded, so the wait until the next part will be much shorter this time! As always, I'll post it here as soon as it's mostly done.

As always, thanks for your support. These videos are time-consuming to plan out and produce, but thanks to you, I feel like I have the time to do it right.

Thank you,

-Ben

What is a stack and how does it work? (YouTube)

Comments (22)

G
Gary Collins · June 17, 2020

I have watched most of these videos on the 6502 and have learned some things. But I would like to know how I can get a copy of the Arduino code used? I am building a model using the TMS9995. Love the registers and CRU bus on TI chips and the Arduino is useful for both.

P
Phil Hystad · February 23, 2020

I have watched all the videos so far and I also have my Eater 6502 or maybe I should say Eater Apple-1 wired up per the diagram. I have written some assembly language programs to test that SRAM is indeed addressable and you can read and write to it succesfully. However, I am curious about the SP register (stack pointer). Does this need to be initialized. I have read thru all the docs I have on the 6502 and I can't find anything that says the hardware initializes the SP on reset. I see that the hardware will initialize the status register though. So, if the SP needs to be initialized, is the correct value 1FF or is it 200 (Hex). A push decrements the address prior to storing I assume so it seems like 200 should be the correct value to get the benefit of the full range of the stack.

T
Tony Bell · February 5, 2020

Hi Ben, watched this several times, excellent. But (isnt there always?) I have built my machine, and have seen this behaviour as you describe it, not having the RAM in play, so I added the RAM, wired as per the Schematic, double checked everything, all looks fine, but the code still doesnt work.... it writes the return address of the first subroutine to the Stack, but when it reads it back, it gets the 8D thing that it had before the RAM was fitted.... wrestling with this one for several days now.... I dont *think* I want someone to answer this, as I'm learning tons in the process of troubleshooting this, but was just wondering if there are any gotcha's coming in the next installment WRT to adding the RAM.... the only other explanation that I have is I have some duff SRAM. INcidentally, while troubleshooting with a Scope, I can see all the signals waggle up and down that I look, but I cant see the R/W LIne go high and low...... but withe LONG dirty piece of code ;-) the LCD works fine..... its only when I burn the SHoterned, elegant version with Stacks and subroutines, that it fails... anyway, this post is long enough now.... maybe someone else is having similar issues, but it might just be me..... Looking forward to the next installment...

B
Ben Eater · February 5, 2020

There are some gotchas to do with timing, but they've all been accounted for in the schematic, so you wouldn't necessarily need to understand it to get it working. But if you don't understand, e.g., why NANDing with the clock in U4C is necessary, perhaps the next video will give you some extra insight that will help troubleshoot whatever issue you are having.

B
Bob Perrin · February 4, 2020

This video is nicely done. I love the way you were able to single step the CPU and cycle by cycle examine the bus states. I'll have to scour some of your prior videos to see what 6502 variant you are using (maybe you are using a WDC 65C02S). I think this is a nice example that shows both hardware and software interacting. Well done! I was lucky enough to have spent a lot of time wire-wrapping a 6502 project back in 1985 or so. Very instructive project! Wrote assembly on a C64 and burned 27C16's in a PROM burner cartridge for the same C64. Used my money from working at the landfills in Spokane WA to buy the assembler from a little computer store on Sprague Ave out in the Spokane Valley. I mention this because I think young people today don't often have the chance (or inclination) to build these sorts of projects. It makes me a little sad. These type of projects were incredibly fun!

M
Matt Alexander · January 30, 2020

My only feedback would be that around 7:13ish, it felt a bit rushed and hard to follow what exactly was going on. You do highlight the opcodes and mention the associated assembly command or data values, but it's flying by quickly and my eyes were darting back and forth trying to figure out what was what. Other than that, I really enjoyed this video. These are deep topics that take a lot of time to understand and I appreciate you going slowly to explain each step along the way.

M
Michael Burke · January 29, 2020

The video certainly continues your excellent production trend. There are redundant parts of the video but they don't bother me. You've done that in the past and so this is in keeping with your past work. I generally find your redundant flashes as adding emphasis to important ideas or concepts rather than just repeating yourself. I wouldn't change any of them. However, I do find the ending a tad rushed. The discovery that memory is required is handled extremely well but the last bits are less than your normal clear and illustrative observations. You state that you need memory. But, you have memory. That's where you are storing the program. You've discovered you need some "other" memory. You've identified another specific address range (the reset address is another, for example) but what is that range? 0100 - 01ff is actually an odd range that could be explained as well. Perhaps explain why that range can't be in the 0000 - ffff range used by the program. Obviously, the program is in ROM (static memory) and now you need RAM (volatile memory) but I guess that is what I think is not made perfectly clear. That is the Ben Eater way!

R
Richard Wells · January 29, 2020

I'm a community college CS instructor, and I'm teaching our Machine Architecture course this year while a colleague is on sabbatical. This semester we'll be building your 8-bit CPU (the kit should arrive today or tomorrow), and I think next semester - if I can find funds again - we'll build the 6502 project. I was actually ambivalent about that until this video, but I really like the approach of teaching something by first showing why it's needed, and this video uses that technique in a really unique way: what happens if we _don't_ have a stack.

B
Brian Epstein · January 29, 2020

Great job! Since you asked for feedback, you repeat yourself a little at 1:56 about checking out your last video. You can probably cut one of the sentences. I appreciate that you leave in some bloopers, like mistyping instruction. It makes this process approachable. I definitely like that you talked about denouncing the timer button with a little capacitor. This has been plaguing me, and I'd love to hear more about this issue. Lastly, I like how you explained and expanded on the stack, including seeing the counter, and saving the a register inside the subroutine. Keep it, it gets you thinking about other possibilities.

B
Ben Eater · January 31, 2020

Thank you! I did mean to cut one of those and just missed it during the editing.

N
Nevyn Bengtsson · January 29, 2020

This is an absolutely amazing video! Supposedly I understood the stack and the concept of a “bus” and assembly programming and like “how a computer works” and other stuff before, but this really clarified it for me!! Explaining the stack is also my favorite way of explaining how a computer works to new programmers, so your take is great to add to my teaching toolkit! I was going to say there’s nothing to improve because it’s perfect :) but one reflection that came to me: when you said you don’t have any RAM, my first reaction was, “but you already have memory? All that stuff from 8000 and on?” — it took a while to remember that that was ROM, not RAM! It was fun when it clicked, but I think it warrants an explicit mention. Maybe even a quick explanation of the difference. By the way, I also want to say how much I appreciate that you take no shortcuts at all. You’re really meticulous about showing every single step, and I think that’s what makes it so educational and easy to understand, even though it feels redundant and unnecessary at first. You are a fantastic educator, thank you for making these videos!

J
Johan Eriksson · January 29, 2020

Im interested in why the processor reads 5d from the address 0124 at 07:42, is it for a similar reason as explained at 13:10, that the processor probably inserts an extra clock cycle for internal stuff?

P
Paul Pluzhnikov · January 29, 2020

It might be worth mentioning why the processor reads 0x8d from 0x122, 0x123 and 0x124 at 13:30. It's not *completely* random.

M
Martin Edelius · January 29, 2020

I agree, it's relatively obvious but there's no harm in pointing it out.

D
David Bock · January 29, 2020

I’d love to know more about the process of creating and editing your videos. Like, when is this voiceover vs. being recorded with the action? (I noticed you sped up the refactoring of the code, but not your voiceover). How do you lay it out? Do you go back, create, and drop in the cut scenes where you reference the opcode sheet? The attention to detail in your storytelling shines through.

B
Ben Eater · January 29, 2020

I start with a very detailed outline; not usually a word-for-word script because I don't want it to feel scripted. But preparing that outline definitely takes the most time of any part of the process. Then I pretty much record everything start to finish, doing the voiceover at the same time as the action. In cases where I don't have as much to say relative to the time it takes to do something, I explain a step, right before I do it, then take however long it takes to actually do it. When I edit that part, I can then shorten or speed up the action and put the "spontaneous" explanation I recorded at the time on top of it so it all flows. Then the editing usually takes at least a week or so. At that point I'll occasionally record other clips to drop in (like quickly referencing a datasheet). Though usually I prefer to record that stuff as I go so it feels more natural.

D
David Bock · January 29, 2020

I’m hungry for these videos so I’m thrilled to see it! Since you asked for feedback, I think you could tighten the video by saving the discussion of pushing and popping your own data and wrapping around the stack to a ‘stack advanced concepts’ video, perhaps even starting by encountering a problem this would solve. You could cut starting at the discussion of PHA, pick back up right before TXS, and explain why you need that as an initialization step so the processor doesn’t start in the middle. Would this free up enough time to add ram to this so you can finish what you started in one video?

B
Ben Eater · January 29, 2020

Thanks for the feedback. This was one of the things I'd previously cut, but decided to try to squeeze in once I didn't feel so much pressure for time, so I'm not surprised it felt a little tangential. Cutting it definitely wouldn't help with adding RAM in this video. The RAM discussion motivates a deep dive into analyzing timing diagrams, so it really does feel like it ought to be its own video. Hence my desire to fit more stack basics into this video. Anyhow, I'm ambivalent about cutting the PHA/PLA stuff. I'd love to hear other who have thoughts one way or the other.

S
Silviu T · January 29, 2020

Thank you, it's a very thorough explanation of the stack and why you need RAM.

D
David Courtney · January 29, 2020

Just got done watching this one. Another great video Ben! Very interesting.

S
SkaveRat · January 29, 2020

quite the cliffhanger ending, but totally fine. having a RAM video added to this one would have made it a bit too long. Now it's nicely split

M
Michael McDonnell · January 29, 2020

as i am watching this video and he puts the ROM back in. I am saying to myself "did i miss the video where he added RAM? he needs that for the stack pointer".I like the way he did this, it shows how to troubleshoot. another well done video.