Placeholder Image

字幕表 動画を再生する

  • hello.

  • Whilst chatting with a Web developer friend the other day, he asked the question What?

  • His assembly language And this took me back a little bit.

  • So I thought, You know your program.

  • But surely you know what's assembly languages?

  • Then it occurred to me.

  • Actually, there's probably many programming professions where people will never have any exposure or or reason to use assembly language.

  • Such obvious Web development database back ends that user interface designers, script writers.

  • And so I thought it might be worth to put together a little video on what is assembly language.

  • When I was working in academia, I used to work in a laboratory that designed processes right through from the conceptual stage to actually fabricating them on silicon.

  • When you develop your own processes, you also need to create your own framework and tools.

  • So we had to design assembly language, correct to design an instruction set, then build compilers, Andy booking tools.

  • Now, the thing with assembly languages there are many, many different flavors.

  • In fact, you could argue every different type of process architecture out there.

  • There is a unique assembly language for it.

  • I'm not going to go into the specifics for this video today.

  • This is really a word.

  • Is assembly language fit in the scheme of programming?

  • To understand the role of assembly language, we're going to need to look at the fundamentals of computer architecture.

  • Let's look at CP years and memory and how they talk to each other.

  • But before we get started at the end of this video, there's a couple of my thoughts about the recent events that have happened in Manchester.

  • I'd appreciate it if you stuck around to watch those two.

  • So let's get started.

  • When trying to classify assembly language, it's useful to look at the hierarchy of other languages.

  • No, I've chosen some naming see, which probably aren't conventional, but I think you'll see the gist of what I'm trying to get across.

  • So for declarative structures, these air the really high level things like, I consider that to be things like html Jason essentially languages, which don't really have an executed ble order but still nonetheless defying useful things.

  • These very high level language is that usually used to define things in scripting language is as well as other things, so scripting language.

  • I would consider things like python on JavaScript on oddball ones like Luis, I like Lou.

  • These languages usually execute line by line.

  • There are some fancy compiling techniques to make things run a bit quicker, but ultimately they are interpreted as and when they are required on.

  • Therefore, they run in something called a virtual machine, which is basically a software equivalent to a computer.

  • Now these virtual machines will be written in a more sophisticated language, usually along the lines off something like c++ Debatable E something like C.

  • Sharp.

  • I'll await some of the hate in the comments.

  • There, on the whole load of, ah, older language is the list of those is endless.

  • And at the very bottom we have assembly language, which is the language that the CPU speaks.

  • The problem we're trying to define a hierarchy of languages is some of them share bits and pieces with others.

  • So, for example, some could argue that C sharp here is actually a scripting language.

  • Because it's interpreted, it produces a bite code, which requires a virtual machine.

  • Ultimately, it's not black and white on The point I'm trying to get across is at the very top.

  • We usually have things that define stuff like what a website looks like.

  • And at the very bottom.

  • We have the instructions that tell the computer hardware how to display on the screen what that website should look like.

  • But this video is about assembly language, so we need to have a look at computer systems architecture.

  • Fundamentally, a computer consists off a central processing unit on Dhe RAM random access memory.

  • On between the two, the central processing unit will outputs and address on it can read or write to a certain location in the memory.

  • Let's start with a very simple one.

  • Ram is effectively an array to the code is out there.

  • There is usually on index on dhe.

  • There will be some sort of data.

  • Now.

  • The width of the data depends on the architecture.

  • We commonly here 32 bits, perhaps could be 128 bit could be 256 but it really does depend on the system.

  • This video is not going to go for any particular architectural.

  • We're just going to keep everything very, very high level.

  • Where is Ram is used to store data.

  • The CPU is used to manipulate data, and it does this by using several internal units, so I'll have a look at what these are.

  • The first thing is CPU usually contains registers, which are basically its own internal ram, and it'll only have a small number of these.

  • So in my simplified example, here we have four registers are a R, B, R, C and R D on the's will just store numeric values as we'll see later.

  • Some CPUs have specific registers for specific functions.

  • A CPU isn't very useful unless it has an arithmetic logic unit, otherwise known as an A L.

  • U V ale.

  • You is responsible for performing well.

  • Addition, subtraction on logic, ANS and oars on other sort of computations.

  • CPS will also contain a status flag register, which is a collection of bits, which tells us about the state of the CPU on theory Thematic logic Unit.

  • The program counter is used to store the address of where we're up to in our program.

  • So as the program is executed sequentially, the program counter increases the program.

  • Counter value can be set depending on the result of something in the status flags register, so we can use this to branch and we'll see an example of that later on on finally usually have a section of important output or communication.

  • So this is how we get data into an out of the CPU.

  • The purpose and sophistication of a CPU depends on what part has got inside.

  • It's that some see pews will have more registers, and some CPUs will have bigger and more complex arithmetic logic units.

  • These are known as extensions on on desktop computer architectures were very reliant on extensions for the processes to do lots of the wonderful things you expect them to do these days.

  • Now, for the purposes of today's video, we're going to assume we have one more module and you can't go into a shop and buy this on.

  • It's going to be program memory, so I'm going to keep this separate from random access memory.

  • On the program, memory is accessed when the CPU outputs, it's ah program counter and in return receives the next instruction that it needs to execute.

  • This configuration is not how it works on your desktop and in fact, that the random access memory is used to store the program as well.

  • However, on some embedded systems, the program memories frequently kept separate from the working random access memory.

  • I've decided to keep the two separate just for this video.

  • It clears things up through the worked example.

  • Later on, if you're familiar with basic programming, you'll be familiar with the function and they function takes arguments.

  • Well, an assembly language can be considered to be the same thing.

  • But if we use the correct parlance for assembly language, the function is not normally called on op code.

  • On each argument will be called on up around to demonstrate how assembly language works.

  • We're going to design a very simple process of just a handful of instructions.

  • Now, operations can be either registers as we saw before.

  • Registers A, B, C and D.

  • They can be memory addresses, location somewhere in memory, and they can be Constance numeric values.

  • How a simple process was only going to have four instructions, So the first is going to be moved.

  • Which moves is going to take to our friends on it.

  • These are going to be the destination on the source on the point of the move.

  • Command is it moves contents from the source location to the destination location Well, let's have some very simple mathematics, so we'll have, add and subtract.

  • These are up codes on Dhe, the first opera, and is going to be the Register, which were targeting with the addition on the second, our friend is going to be a value or register, and the fourth instruction is going to be a jump and the first opera and is going to be the condition on which we jump and second off brand will be the location of where we're going to jump to.

  • This will become a bit more clear when we start writing some code later on.

  • RCP could only move stuff at stuffs, obstruct stuff on job to a different location.

  • Is it very useful?

  • Well, probably not, but it is enough to do some more advanced functions.

  • So how can we multiply a couple of numbers together?

  • For example, if we had three times 10 well, we know that if we sit in a loop, we can simply add 10 to itself three times.

  • So let's have a look at the program for this.

  • Here's a little example program I've written using our new language to multiply two numbers together, but I'll need to explain some of the syntax to you first.

  • Clearly, here we have the op code and we have our two operations.

  • So the first opera and here is our A, which we saw in our CPU means register a second opera I've put in square brackets and this means we want the source of the move to be from memory address number three.

  • Unlike this one here, where I have not used the square brackets are what I'm implying by this thing.

  • This up around is that we want to move the value zero into register, see, so we can load in a constant value or we can read from memory.

  • Looking back at our ram, I'm going to assume that our memory has now been populated with some values.

  • Eso we can execute our program in this case, we want to multiply 10 by three.

  • So these air already stored somewhere in memory.

  • Now we're going to do something very old fashioned and execute this program by hand.

  • So we know the first thing here we're going to do is read from Location three, which has the value 10.

  • What's that puts into r A.

  • The value 10 on the next situation we want to read in from memory into registered Be, which we know is going to be three.

  • This time.

  • The next instruction was simply setting a counter to zero.

  • This is going to store our result.

  • The ad instruction here will take our A and add it to what's already in our C.

  • So in this case, we've got our C equals R C plus R A, which in this instance is, of course the same as saying zero plus 10.

  • So are sea.

  • After this instruction equals 10.

  • Likewise, the subtraction instruction here sub subtracts the value from the current register.

  • So here we've got a B equals B minus one.

  • But it's a value this time.

  • We're not using another register that equals three minus one equals do.

  • Now with the jump instruction, we're going to see something interesting.

  • Let's look at the aromatic logic unit in a bit more detail.

  • Simply put, it takes two values and an instruction on performs the operation.

  • So in this case it could be our registers or Constance.

  • The instruction is the add or subtract, and it gives us a result.

  • But it also updates the status register the state is registered contains some interesting things based on the result of the calculation.

  • It's just performed.

  • So if I do a little bit of pseudo code here, we could say if results is equal to zero, then set zero bit else don't.

  • In.

  • Our simple process in this state is registered only contains this one bit whether the results of the previous computation was equal to zero enough All the bits that are commonly found in stages registers include overflows carry bits past the result of the computation gone out of bounds of the number of bits allowed to start the result.

  • You can also include errors in the safest register.

  • So just divide by zeros going back to our program.

  • We can now try and understand the jump statement a bit more.

  • In this case, the condition is looking for not zero.

  • So remember the zero bit was set by the result of the calculation we can see in this case it was too.

  • So it is not zero.

  • So the jump condition is true on we tell it to jump back to address 13.

  • So this is going to loop background appear r C is now our C equals 10 plus 10 and I'll be is now to take warm.

  • But we can see this is still not a zero.

  • So again we jump background this situation weaken CRC equals 20 plus 10 which equals 30.

  • So we know we're getting close to a result.

  • Now on on the next line down I'll be is now one take one which is equal to zero.

  • And that's important because now on our jump instruction, the result waas zero.

  • But we're checking for not being zero.

  • So in this case we don't jump.

  • So on the final instruction we just carry on with the next one, which is finally a move instruction which says whatever is in register see here we're going to store in memory address five register See already contains our 30 which is the result on we're going to store that in memory address five somewhere in Ram.

  • So when the writer cares 30 the result is written to that address location.

  • So we've done a successful multiply on this program demonstrates what is typically assumed by most people don't really know assembly line, which is that they think it is hard must because we didn't have a multiply instruction to help us out.

  • So we have to do it the long way around.

  • If our little CPU did have a multiply instruction, we'd only need to call it the once.

  • We wouldn't need to set up a loop.

  • We wouldn't need to manage the registers as much.