Placeholder Image

字幕表 動画を再生する

  • I'm in the process of building a basic computer using a version of the 65 02 microprocessor, and so far I've just programmed it to blinks and led is like this and the program I wrote that's doing this is stored on this Ram chip.

  • Really, it's a programmable ram chips.

  • We can actually change the program, but if we pull the chip out, we could put it in a programmer and take a look at what's on it.

  • So this is an 80 28 c 2 56 chip.

  • So we just go to read here and read the device.

  • Here's the program that was running.

  • It was just a bunch of hex decimal numbers.

  • But of course they have meeting so a nine means to load the next bite into the register.

  • So this is gonna load FF into the register.

  • A.

  • D means to store the contents of the A register into the address in the next two bites here and so on until we get to this poor C 0580 which obviously means toe loop back and keep repeating this Well, if that doesn't seem so obvious to you, then you're not gonna be surprised to hear that no one actually write software this way, even for here, really low level stuff like this.

  • Now, my last video actually did write this program by writing out the machine code here by hand here with a little bit of pipe concho down here to sort of massage it into a binary file of the appropriate size.

  • But of course, you know just isn't practical to write machine code by hand like this for anything more complex.

  • Instead, the way to do this is to write our program using assembly language.

  • So we can actually just say low day FF in store a six year zero to or you know, whatever else we want.

  • And then we can use an assembler, which is just a program that will convert this to machine code without us having to worry about what all the different up codes are.

  • So, of course, we're gonna need an assembler.

  • And there are a number of different assemblers out there for the 65 02 I'm gonna use this thing called Bassam.

  • It's looks like it's actively maintained its written by Volker Bar Thurman and ah, a lot of work on the 65 02 stuff was done by Frank will.

  • But you can see you know, it supports the 65 02 family.

  • Supports a number of different syntax flavors.

  • I'm gonna be using the old eight bit style, Syntex, and it'll give us this raw binary output, which is what we need in order to write to our e problem.

  • But in any event, you can download the source code from the website here and compile it yourself.

  • I've got a downloaded here we used to make.

  • Um actually, we have to do ah, spew equal 65 02 And syntax is old style and we get a few warnings, but ah, that should generate this file here, which is the actual assembler.

  • And so if we run that you can see okay, wants an input file and take neither.

  • Compile this yourself or if you go back to the website, go to Volker's page here.

  • He's got, um, binaries here for Mac Windows and Lennox for the 65 02 So you can just download that And that ought to be what you need.

  • Once we have the assembler.

  • Now, let's run it to translate this Assembly language program.

  • Just this this to line thing I've written here into, ah raw binary file that we can put on the rahm.

  • So they save this.

  • Now, if we run the assembler with that file, there it goes.

  • And so what did it?

  • D'oh Well, by default, it puts its output into a file called a dot out.

  • So we take a look at that we could see is actually text file.

  • That has a bunch of stuff in it.

  • And it does have the up codes here spelled out in hex decimal.

  • But this is just a text file yet we can't put this on the prom directly like this, you know, we need we need a binary file.

  • But if we go take a look at the documentation for the assembler, you can see there's, ah, bunch of options.

  • And one of those options is dash F format to use a particular output format, and it says, see the chapter on upper drivers for more details.

  • But if we take a look at Thea, let's see, there's an output module here for simple binaries.

  • Let's take a look at that And here it says the simple binary output module could be selected with the dash f Been option.

  • So let's do that.

  • So run the assembler again with the dash f Been and her family.

  • Now if we look at a doubt out well, now it just looks like a couple unknown characters.

  • I guess this is This is the contents of the file, which is sort of what we expect, right?

  • It's just a binary file with a couple instructions in it.

  • Let's do a hex dump to see exactly what's in there.

  • And here we go.

  • We've got our program.

  • A nine is the out pop code for Load A F F.

  • And then a D is the op code for a story.

  • And then it's got the 6002 here.

  • And so that matches the program that we wrote.

  • A couple things I'll point out here in the program before I get too far is you see, there's a hash symbol here, and then the dollar signs and these have meaning to the assembler.

  • So the dollar sign here, for example, means that the number is Hexi decimal.

  • So if I left off this dollar sign and this would be address 6002 decimal Not address 6002 Hexi decimal, which is what we want.

  • And then that the hash sign up here means that this load A is a load immediate meaning It's loading the value FF into the A register.

  • And if I left off this hash symbol, then this would actually mean to load whatever data is at address F f or really address 00 ff load load whatever's at that memory address into a register.

  • So I actually let me leave the hash symbol off and save this and show you what that does.

  • So I go back in and just rerun the assembler and take a look at the hex dump you can see instead of having you know this instruction being a nine f f.

  • It's now instruction a five FF.

  • So it's actually a different up code, even though the only thing we changed was just leading leading off this hash symbol, it was here is that getting rid of that hash symbol actually changes the up code.

  • So we look at the data sheet for the microprocessor.

  • We can see a five is still in up code for the load.

  • A instruction just like a nine.

  • But where a nine is covered under this go figure it a hash column here that means them immediate data.

  • A five is E P, which is zero page, which means it's loading from an address that starts with 00 in this case would be 00 FF, which is very different from what we want.

  • So it turns out that hash symbol is pretty important here.

  • But anyway, now, if we want to recreate the rest of that blink program that we started with, we could just continue to do that in assembly language.

  • Here.

  • I could put a 55 hex into the A register, which is just the alternating ones and zeroes, and then store that out to address six years there.

  • Zero, which will put it on the ladies and then load a A, which is the other alternating mix and then store that toe to put that on the ladies and the bottom.

  • I had a jump instruction here to create a loop, so that's pretty much what we had before.

  • But instead of us having to look up and type in the actual hex up codes were using these pneumonic, so it's much easier to read and write now.

  • One thing I'll point out that that maybe isn't that obvious is that each line here has some spaces at the beginning.

  • It turns out to be really important that each instruction has some spaces or tab or something in front of it like this.

  • Otherwise, the assembler will give you all sorts of errors, and I'll get in tow.

  • Why?

  • That isn't a minute, but you definitely want to make sure you've got some blank space, the beginning of each line.

  • So let's save this and go ahead and assemble it.

  • And now, if we hex, dump the output, Here's what we get, and it's more or less identical to what we have in the rum.

  • In fact, if we take a look at that, you can see these 1st 18 bites here the first you know, the actual program itself is identical to what was in the room, but of course, the rahm images more than 18 bites.

  • Fact is 32,768 bites, and it has to be exactly that size because that's how big.

  • The EEC problem that we're using is also at the end here it at F f F C well, well seven F f c and F seven f f d In the wrong, which is going to appear at address F f f, C and F f, f T and memory.

  • This is the reset vector.

  • And you know, the 0080 is what tells the processor where to start executing code.

  • You know, at that address, 8000 So assemblers giving us this.

  • But we know we need all this padding here to get the file to be exactly 32 k long on.

  • We need the 0080 here.

  • So how can we do that?

  • Well, this is something the assembler actually makes really easy for us.

  • If we go back to our code, we can use the origin direction, which is dot org's.

  • And this origin directive tells the assembler where the following code goes in memory.

  • So at the very top here, I can say, you know, or GE 8000 and this says the next statement.

  • You know, this load A here is gonna be an address 8000 And the reason we want to say that the first instruction is that address 8000 is because even though it's the first instruction in the first bite of Rahm here, remember, the Rahm is only enabled when the processor sets the top address line a 15 when it sets at high.

  • And so if a 15 is a one.

  • But all the rest of these address lines are all zeros.

  • All these address lines here, all zeros, then that's what's gonna give us the first bite out of the wrong right.

  • The Rama is enabled, and we're and we're getting the first bite out of it.

  • But from the processors perspective, it's not reading address.

  • Zero.

  • It's reading address 80000 So this or directive at the top just tells the assembler, Hey, you know the process is gonna think that the code in this file starts it address 80 which is fine.

  • But now we can do another or directive down here at the bottom for address F F F C, which says that the next thing after this goes at address F f F C so right here after that or direct If we wantto just tell the assembler, just put the address 8000 Because that's the start address we wanna have at this F F F C position.

  • And we could do that with the dot word directive was just puts a word which is just a 16 bit value into the the output.

  • So it is a word hate 000 So if we save this and assemble this lips, assemble it, um, get some errors here.

  • So unknown demonic Sadat or got word it doesn't understand.

  • And that's because we actually need to tell the assembler we want to use these directives with dots in front of them.

  • So what we want to do is use Thea Dash doctor option here and okay, there we go.

  • Now let's take a look at the outputs.

  • We do a hex dump of a dot out and there we go.

  • We got the first, the 1st 18 bites of the same.

  • That's our program.

  • And then we have a whole bunch of zeros all the way up to F f f C and F f f D, which is now.

  • There's 0080 So this is Ah, almost exactly what we want is actually two bites short because we need two more bites here to get the file to be exactly 32,768 bites long.

  • But you know, that's easy enough.

  • We could just add another word to the end here.

  • Um, it could be whatever.

  • And now let's assemble this and do a hex dump.

  • And there we go.

  • So it's the right length, right?

  • So seven f f f is the last bite here.

  • It's got the 0080 in the right place for the reset vector, and it's got our program here at the beginning.

  • So of course now we could just write this file to the prom like like we have in the previous videos and run the program.

  • But there's still a few more things we could do to make things even easier for us.

  • Go back to our code.

  • One thing that's really tricky about this is we have this jump eight years or five here, and the goal of that is to create a loop out of this block here.

  • And so the easier is there five is supposed to be the address where this load A is.

  • But you know, I only know that because I know while we're starting at 88000 and the load A is one bite on this this f f is one bite and the story this is three bites.

  • And so then this must be 8005 But, you know, that's a just a bug waiting to happen.

  • Soon as anything changes this, the address of this instruction could change.

  • Since dead, we can actually have the assembler keep track of all that.

  • So I could put a label here called Loop.

  • And then instead of jumping to address eight years or five, I could just jump to that label loop.

  • And now that's way better.

  • So it's much easier to tell what's going on here.

  • So we have, you know, a loop here, Uh, and because we're not hard coating that address, if this code moves around in the future than nothing's gonna break.

  • And now you may have noticed that, unlike every other line in this file, this label here is not indented.

  • And that's very much intentional because that's how the assembler knows that it's a label now.

  • If we want, we can add another label at the top here for the initialization code and then down here at the bottom for a reset vector instead of hard coating that we can just use that reset label.

  • Let's save this and assemble it again, and we take a look at the output you could see.

  • It's the same as before, so that jump that for C 0580 is the same.

  • It's still using address 8005 But now you know, we didn't have to keep track of that and figure that out on our own.

  • And, of course, the reset vector here is still 0080 So that's so That's the same as well.

  • Hopefully, you'll find this code here to be much more legible and maintainable than just the raw listing of hex codes that we started with.

  • So, for example, we can actually change this program pretty pretty easily now.

  • So, um, let's let's make some changes here.

  • After we initialize the interface adapter here, let's let's output something right away.

  • I'll do 50 hex and output that and then in the loop.

  • What I'll do is they rotate right instruction and then this instruction just by itself will shift all of the bits in the register to the right.

  • You're rotating the right most bit back around to the left.

  • And then once we do that, what I can do is, uh, well, just store the modified A register back to address six years or zero to put it out on the L E.

  • D's and I'll get rid of the rest of this and that will actually just be our loop there.

  • So this whole program is You were initializing the interface adapter here.

  • We're out putting the 50 hex pattern to the ladies and then in our loop were just essentially just shifting that pattern to the right and rotating it around.

  • So we should see something kind of interesting in the ladies.

  • With that, let's save this and I'll run the assembler again, and then do hex dump of the output there.

  • And if we look at what I've got here, I've got a nine, which is low day FF, and then we have our 80 which is store a 0260 which is Actually, another nice thing about the assembler is you know, it's figuring out how to put this in the little Indian format, that sort of backwards format, because his address 6002 And, of course, in our code, you know, we just type six years or two.

  • We don't have to think about the fact that it has to be stored in this sort of backwards format in the In the X File anyway.

  • Then we've got load a 50 store, a six year 00 Then this six a up code.

  • That's gotta be the up code for rotate, right, and then another store a 6000 and then our jumps of force.

  • He has jumped.

  • But this time we're jumping Thio.

  • Well, it's gonna be 800 a.

  • But of course, we don't have to worry about figuring that out.

  • The assembler just knew, you know that's the right place to jump, to get back to the loop label, which, which I guess, would be sort of here ish.

  • So let's see what this program does.

  • Let's write it to the problem.

  • There we go.

  • I'll put the problem back in our circuit here and powered up.

  • We'll reset.

  • Okay, there's five.

  • And yep, there it goes.

  • So it's got those two bits from the 50 and it's rotating them right?

  • Which it looks like it's going left because I've got the bit sort of swapped around here on, you know, physically.

  • But it's rotating it right and you'll see this bit now goes into the Kerry bit, and then the Kerry bit comes back.

  • So there's actually sort of, ah, hidden ninth bit in this rotation, which is the Kerry bit.

  • But otherwise, that's what our program supposed to do.

  • And of course, now, being able to write programs in assembly language for this little computer we're building means that we'll be able to do something more complex than just blinking.

  • Some led is really still be easier for us to write programs that are a little bit more complex.

  • Not to say that blinking eh, ladies can be fun, But in the next video, I'm gonna hook thes control signals up to this LCD display, and we'll be able to write a program little bit more easily to control it and actually display some more interesting text.

  • And remember If you want to follow along with these videos and build and program your own little computer, I have gathered all the parts together that you'll needem and you could buy him on.

  • My website is as a kit comes with everything you need to build the basic computer, and I also got a kit for the clock that I'm using here is well, so you can check out eater dot net slash 65 02 for more information on all of that and, as always, thanks to all my patron, since your support is also critical in making these videos possible.

I'm in the process of building a basic computer using a version of the 65 02 microprocessor, and so far I've just programmed it to blinks and led is like this and the program I wrote that's doing this is stored on this Ram chip.

字幕と単語

ワンタップで英和辞典検索 単語をクリックすると、意味が表示されます

B1 中級

アセンブリ言語とマシンコード - 6502 パート 3 (Assembly language vs. machine code — 6502 part 3)

  • 4 0
    林宜悉 に公開 2021 年 01 月 14 日
動画の中の単語