video

Lesson video

In progress...

Loading...

Hey there and welcome to the last lesson of Computer Systems. I'm Mac your computing teacher for this unit.

In this lesson, we're going to be looking at assembly language programming again, but you are going to write, your own assembly language programme this time.

For this lesson, you're going to need a notepad and a pen, so you can take notes and answer questions while you're learning, and I'd also like you to make sure you have your assembly language toolbox from lesson 11 as you'll need it for the activities in this lesson.

Please, can you also remove all distractions from around you.

This includes your mobile phone.

For the last time I have my water here, so I can keep hydrated while I'm teaching.

And I'd also like you to make sure that you have some refreshments if you need it throughout the lesson.

If you want to pause the video here, go get everything you need.

I'll be here when you get back.

In this lesson, you are going to design and write your own assembly language programme, and also we're going to wrap up the Computer Systems unit as a whole.

let's get started, shall we? In this first activity, you are going to be the translator.

If you remember from lesson 11, one of the first activities I got you to do was to translate a piece of Python code into assembly language.

This was so you could use the familiar language Python as a touchstone before moving into the unfamiliar lands of assembly language, and I'd like you to do the same thing in this lesson.

So, here's a new Python programme for you that I'd like you to translate.

Make sure that you have your assembly language toolbox from lesson 11.

Let's do the first part together, just to get you started.

So, if we have a look here, I'm just going to describe the Python programme to you, and then we'll start translating it.

So, this Python programme takes in three numbers.

So, it does three inputs this time.

It then adds the first two inputs together to create another variable result, and then it checks if that result is greater than the first number that we entered, right? So we have a maximum, which is the first number, then two others.

And if the two added together a larger than our maximum, we're going to output the results of the two added together, right? So, this first line translates to two assembly language commands, and that is input and store, right? So, we take input from the user and then I store it in a data location that I've given the name, MAX.

Now, I've chosen MAX because it's shorter to write than maximum and I don't want to waste my time, typing superfluous letters and you can do the same, if you want to use maximum as the full variable name, that's absolutely fine, just make sure it's the same one that you put at the end.

Now, use this as an example, to translate lines two and three of the Python programme on your own.

Pause the video now, have a go at writing it in your notes and then come back when you're done.

Right.

Should we have a look at these next two lines and what they translate to? So, the next few lines, I'm just going to do them together because they're very, very similar.

We take input again and then we store it and we do that for both lines, but the only difference is the variable names that we use.

So, we want to make sure that we've got NUM1 for line two, and we want to make sure that we've got NUM2 for line three.

And if you have a look at my assembly language, you can see that I've used those three variables.

And I've just got to make sure that I use the same names going forward.

What command are we going to need for the next bit? So, the next bit adds the two numbers that we just entered together.

So, which command are we going to need? Have a go at translating line five on your own, on your worksheet, and then resume the video when you're done and we'll go over it.

Okay, let's have a look.

I'll just click.

So, what we did there is we added NUM1, because if you think the last number that we took in was NUM2, so that will still be in the accumulator because when we do an input, it lives in the accumulator even after we've stored it, it's still there.

So, we're going to add a NUM1 to the accumulator, which will give us the total, and then we're going to save that right, as another variable called RES.

Right again, I'm saving myself having to type superfluous letters.

My time is much more valuable than that, save yours as well.

So, I've added NUM1 and I stored the result.

So next, we have an if statement.

This means we're going to have to use branching, just like you saw at the end of lesson 11.

So, what kind of branch are we going to need to do? Or what do we need to do first in order to accomplish this if statement? Have a go at this on your own, you can pause the video to do it, and then resume when you're done.

If you need to, check back over your programmes that you did in lesson 11, to give you some clues.

Right, I'll see you when you get back.

Welcome back.

How was that? This one's a bit more complicated than just the inputs or saving and adding.

Let's have a look of what we do.

So first of all, we subtract the maximum variable from the result, which is already in our accumulator.

Remember, we've added NUM1 to it, but it's still in the accumulator, hasn't gone anywhere yet.

So, we're just going to subtract that max variable that we made on the second line of our assembly programme.

So, we've subtracted that value from the results, and we want to branch, if the cumulative value is positive.

So to do that, we're going to use the branch if positive command and give it a marker, BIGGER.

What will happen now is if a result is larger than our maximum, our programme will hit this part and then it will jump to the BIGGER branch marker, right? So, we're going to put that on the left hand side.

But before we do that, we just need to handle what happens if it isn't positive, right? So, if our if statement is not true, there isn't an else in this instance.

So, we just want to jump straight to the end.

How do we branch, regardless of what is in the accumulator? Pause the video here and have a go and see if you can remember what command we need to use.

Welcome back.

Now, hopefully you've got that we need to use the BRA command and then we want to send them to the END marker.

Now, we need to remember to put the END marker next to the HLT command in our programme.

So, next we've finished the sort of else bit.

Now there wasn't anything to do in the else, but we've handled it, just in case our if statement is not true.

So, now what we need to do is we need to load the RES value into the accumulator and then output it.

So stage one, how do we load data into the accumulator? Pause the video again, have look at your toolbox and put in the right command into your translation.

Resume when you're done and we'll go through it.

Welcome back.

So, hopefully you got that first, we needed to make sure to put that BIGGER marker in there.

Then we load our result variable using the LDA RES, and then we output that RES variable, which is now in the accumulator and we've covered line eight of our Python programme.

So, with that in place, we only have two things left to do.

We need to HLT the programme, remember that END marker, and we need to create the four data locations necessary for this programme.

Pause the video again here, have a go at doing these finishing touches and then come on back and we'll move on.

Hey ya, right.

Let's have a look at these last few changes.

So, you've got our END marker and the HLT.

Welcome back.

Now, let's have a look at these last few changes and we've got the END marker and the HLT command, which will stop our programme, and then we have our four data locations.

Now, make sure you've got all of these as well.

If you'd like to, you can pause the video here and load this into the LMC simulator.

You will find that ncce.

io/lmc.

If you want to have a go at running it through a few times and just see how it works, that's absolutely fine.

If not, resume the video or just keep watching and we'll carry on to the last activity.

Welcome back.

Let's head on to the last activity.

In this last one, you're going to be assembling a programme for yourself.

On your worksheet, you'll find a description of this task in which I want you to design and write an assembly language programme all your own.

And I've given you some requirements.

I want you to create a programme that inputs three numbers, just like you saw last time, then adds the first two together.

Then does an if statement.

So if the results, so those first two added together, which you'll need to save as a result variable.

If the result is larger than the third number that you entered, I want you to output the total.

Otherwise, or else, I want you to output the third number.

So, pause the video here, head over to your worksheet.

Make sure to use all of your previous programmes and your toolbox to assist you.

I'll see you when you get back and we'll step through it.

Welcome back.

I hope you got on well with that.

However, if you are a bit stuck, don't worry.

I'm going to step through it piece by piece, and I'm going to give you an opportunity to pause and carry on afterwards.

So, hopefully we can get past the bit where you're stuck and then you can keep going, right? Let's have a look at our first bit.

So, here is the same programme written out in Python.

It takes in three numbers, adds two of them together and saves as a result and then checks whether that result is larger than the third number.

If you'd like, if this was the bit that you were stuck on, you didn't know what the programme should look like.

Feel free to pause the video here and have a go and use this Python programme as inspiration to translate just like we have before.

Resume the video when you're done.

And we'll start going through each of the requirements step by step.

Right.

Let's have a look at this first requirement.

So, my programme needs to input three numbers.

Now, I'll have a look at the first one.

So, the first one is we do an input command and then we store it in a variable named data location, called NUM1.

And then we do the same thing for the next two numbers, right? So, I have three input statements and then we'll store each one of them as a separate variable.

So, we've got NUM1, NUM2, NUM3.

Now, we need to add the first two together.

I'm going to let you have a go doing this bit on your own.

Just remember that the moment NUM3 is in the accumulator.

So, before you add the first two together, you're going to have to load NUM1, right? It's a bit of a hint.

Go back to your programme, have a go and then come back when you're done, either finished the whole programme or you get stuck again and we'll keep going through it.

Hey there, welcome back again.

Hopefully you're able to get a bit further this time, but let's have a look at the next requirement.

So, I need to add the first two numbers together.

So, first I need to load the NUM1, then I'm going to add NUM2 because when I load NUM1, it puts it in the accumulator, and then I'm going to add whatever stored in NUM2 to the accumulator to get my result.

I'm then going to store that result as a named variable RES.

So, that is the next step, right? I've loaded NUM1, I've added NUM2, and then I've saved it as the result.

Right.

If you'd like to pause the video again here and carry on going, that's absolutely fine.

Come back when you're done and we'll keep going through it.

Otherwise, we'll keep going.

Right, let's keep going onto the next one.

So, if the result is larger than the third number.

Now for this one, I'm going to show you the Python, so you know which bit we're doing.

So, we're doing this if statement here.

So, it says if result is greater than NUM3.

So, the moment my result is still in my accumulator.

So, the first step is for me to subtract NUM3 from it so that I can do some tests on the value left in the accumulator.

I'm then going to branch if the accumulator is positive, which means that if the value in the accumulator is positive, it means result is bigger than NUM3.

Because when I took on three away, I was still left with something.

So, when I see the BIGGER marker, that means that I'm going to be doing this line.

But before we do that, we actually need to do this line at the bottom, because if it hasn't branched now, we're going to do the else statement.

So, we need to print NUM3.

You want to pause the video here again, carry on going, keep working on assembling this programme yourself, resume when you're done and we'll go through it.

Welcome back again.

You may get sick of hearing me say that, but there's lots of pause points, just so you guys can get the support that you need.

So, the first thing to do, if I want to print NUM3 is I need to load it first.

So I need to load into the accumulator, then I output it.

I show it to the user and then I want to skip over the next bit.

So, if I've loaded NUM3 and I've output it, my programme should be done, right? So, I want to skip to the HLT command.

So, I need to do a branch, always BRA and then go to the END.

And that END marker, we need to make sure we put that in.

So, the next line that you need to do is this print result.

Now, remember to put that bigger marker in, so that when your programme branches, it jumps there.

So you need BIGGER first, and then you're going to load the result and output it.

Pause the video here, do those bits, come on back and we'll keep going.

Right, let's have a look at this bit.

So, the first thing is I put that BIGGER marker in there.

I say, if you've branched, branch BRP bigger here, I want you to jump to this part of the programme.

I'm then going to load the result.

Now just let me move my camera really quickly so that you can see that bit, right? I'm then going to load my result and I'm going to output it.

So, jump to the BIGGER branch, load the result and output it.

That's that line done.

Now, as you know by now, that's not the end of our programme.

We still have two things we need to do.

We need to finish our programme called the HLT command, and then we need to set up all of our data locations.

Now, this is the last pause point you're going to get.

So, I want you to go away and do those last two finishing touches and then come back and we'll just review Right, so now we've got all these memory locations.

I'm going to put my camera back in the corner here.

So, now we've got these last two tasks, right? We've got the end marker that we need to make sure to put next to our HLT command, and then we have our four memory locations, NUMs one through three, and then the result of the first two being added together.

Hopefully you got that.

I'm going to head over to the LMC now, and I'm going to load this programme into it.

And we're just going to run it one time to see how it goes.

I encourage you to do the same.

So, pause the video here, load this programme into the LMC, make sure you've got this version down on your worksheet and I'll see you there in a second.

Right, welcome back to the Little Man Computer.

As you can see here, I have loaded my programme into this by copying and pasting, and I encourage you to do the same unless you want to type it out, in which case I'm not going to stop you.

You do what you want.

If you want to copy and paste, its no skin off my teeth to be honest.

Right, let's have a look.

I'm going to run this programme now, and we're just going to go through it one time to make sure it does what I want.

So, what should happen is it should input three numbers.

It should add the first two together, and then it should check whether the result of that addition is bigger than the third number.

Let's go.

So, we got the first instruction executing here.

All right.

So 901, that's the first one.

Oh, I need some input.

So, I'm going to do 10 as my first input, as its classic, and then again, you can watch when these things happen.

It's really important to just watch what all the different components are doing and the role that they play.

So, you can see the buses at the moment are carrying those instructions and the data addresses to, and from memory and the CPU.

We've just saved that value in a memory location, 17.

It's going to keep incrementing up.

It's going to ask me for another input in a second, and I'm going to do 14, cause we're going to follow that example that we did in lesson 11.

So, I'm going to do 14 now, enter that.

It's going to come back.

Now, feel free to sort of be doing this as well while I'm running through it.

I might actually, once we do the third input, I might skip forward a little bit.

If not, we'll just sit here and watch it and we can kind of talk about it, right? So, we can see the arithmetic and logic unit really important, is doing all those mathematical operations.

So, just got to 901, which means it's going to ask me for some more input and I'm going to do 25.

Now 25, interestingly is larger, right? So, it's bigger than my 10 plus 14.

So, what we should see is 25 as an output.

So, it's going to keep making its way.

So now, what we should see is we should see it's going to save that in the memory location.

And now we're going to do some loading.

So, I'm going to pull NUM1 into my accumulator.

Perfect.

I'm just going to have a sip of my water while this is happening.

Make sure as well, like get hydrated.

It's a good excuse while you have things like this running to just take a moment, have a drink, keep watching it.

So now we're on line seven, which is our addition.

So, let's have a look.

We should see the arithmetic logic unit involved in this.

It's going to take whatever's in the accumulator and whatever's coming back from RAM.

It's going to add it together, there you go.

Look, wow, then we got 24.

So, remember my third number is 25.

So, it's bigger than what's in the accumulator.

So, we should see that we're going to do some subtraction now.

Oh no, it was saving the results.

Sorry.

Now we're going to do some subtraction, right? So, it going to go grab that location there.

Perfect.

And you can see down here, there's a little Android dude.

He's talking about everything that's happening.

So, you can read what's happening here as well as watch it as it's running.

So look, our accumulator is negative, right? So this branch, if positive is not going to ring true, it's going to just head onto this load, number three bit.

Okay.

Arithmetic logic unit is adding one to the programme counter, coming back.

Now we've got no branch that's occurred here, right? Look, we've moved straight on to number 12.

Now, we're loading the accumulator with that value.

Cool.

So, we're now in output 25, we're then going to branch.

Always, which has an op code of six.

We're going to go to the number 16 in the RAM, which you can see is three zeros.

And did you see then, that 16 was put into the programme counter, so that's how the branching happens.

We changed the value in the programme counter and that's it.

My programme has run.

Have a go doing this yourself.

Try different combinations of numbers, just to see if it's doing what you want.

I'll see you back at the slides in a second, and we're going to wrap up this whole lesson on the Computer Systems unit, see you there.

Hey there.

Right, welcome back to the slides.

Hopefully you were able to run that and get a few numbers going and see the different reactions that the programme had with the branches.

So, we've done this now, right? We've met all these requirements.

We've input three numbers.

We added the first two together.

We checked whether the result was larger than the third number.

If it was, we output the total and if not, we output the number.

Well done.

That is quite a complex assembly language programme.

I think with the stepping through you guys have done a really great job to get through it.

And that is all from me today and for this unit, I hope you've enjoyed it, cause I have had an awesome time sharing this knowledge with you guys.

My last thing is to ask you to share your work with Oak National.

If you'd like to, of course, please ask your parent or carer to share your work on Instagram, Facebook, or Twitter, tagging @OakNational and #LearnwithOak.

I'll see you in the next unit guys.

Have a great one, happy learning.