Classification of Programming Languages
In this group of videos Christine Swan explains the difference between high level code and machine code, and discusses the need for translators. Christine also describes the characteristics of an assembler, an interpreter and a compiler.
High level code and machine code | Part A
Hello! In this video, we’re going to look at how computers run programs. Computers are digital devices that can only represent two values: binary 1 and binary 0. Computers are rather stupid and they’ll only do what they have been programmed to do. Of course, learning binary code isn’t easy for humans, and we’d prefer to be able to program a computer using a language that’s close to the way we write and speak. For any program to run, instructions and data must be fetched from memory and then executed by the CPU.
High level code and machine code | Part B
We could program directly using binary code. Every instruction that the CPU can understand will be represented by unique code called the opcode. So we’d need to know the opcode for every instruction that we want to use in our program. The difficulty is we need to learn the code, and we also need to enter the correct binary codes for the data values to. Programming in binary is called machine code.
As computers became more complex, this wasn’t the most practical way of writing programs. Every CPU supports an instruction set that it recognises. It can be programmed using simple character sequences to represent the instructions called mnemonics. This is assembly language. A good way to learn about this is to use the Little Man Computer simulator. The Raspberry Pi has an ARM CPU, which has its own assembly language. You can find out more about that from the internet. If you wanted to add two numbers together, we need to use the instruction ADD, and then give labels to the data that we want to add. I have an example here on the board, and I have used some code that you could use in the Little Man Computer simulator to add two numbers together. What this does is allow 1 number to be input, it’s then stored in a memory location, a second number is then input and the first number that we’ve stored is added to it. We then output the results, and then stop the program. Assembly language programming is fine for simple programs, but if I want to write a complex program, such as a game, it would take us a very long time and involve many lines of code.
High level programming languages have built in commands that allow us to write code that is easier for humans to understand and carry out useful operations in just a few lines. It is important to spell the commands correctly, and to input them in the correct order in the correct way. This is called the syntax of the language. Like learning any new language, some are easy to get to grips with, and hard to make mistakes with, but others are a little bit more tricky.
We could program directly using binary code. Every instruction that the CPU can understand will be represented by unique code called the opcode. So we’d need to know the opcode for every instruction that we want to use in our program. The difficulty is we need to learn the code, and we also need to enter the correct binary codes for the data values to. Programming in binary is called machine code.
As computers became more complex, this wasn’t the most practical way of writing programs. Every CPU supports an instruction set that it recognises. It can be programmed using simple character sequences to represent the instructions called mnemonics. This is assembly language. A good way to learn about this is to use the Little Man Computer simulator. The Raspberry Pi has an ARM CPU, which has its own assembly language. You can find out more about that from the internet. If you wanted to add two numbers together, we need to use the instruction ADD, and then give labels to the data that we want to add. I have an example here on the board, and I have used some code that you could use in the Little Man Computer simulator to add two numbers together. What this does is allow 1 number to be input, it’s then stored in a memory location, a second number is then input and the first number that we’ve stored is added to it. We then output the results, and then stop the program. Assembly language programming is fine for simple programs, but if I want to write a complex program, such as a game, it would take us a very long time and involve many lines of code.
High level programming languages have built in commands that allow us to write code that is easier for humans to understand and carry out useful operations in just a few lines. It is important to spell the commands correctly, and to input them in the correct order in the correct way. This is called the syntax of the language. Like learning any new language, some are easy to get to grips with, and hard to make mistakes with, but others are a little bit more tricky.
High level code and machine code | Part C
We now need to look at things from the computers point of view. Unfortunately, computers
only understand binary, but that’s trickier for humans. High level languages, such as Scratch, and Python, are more convenient for humans, but computers can’t understand them. So, we
need to have a translator to convert the high level language into something that the computer can make sense of.
There are two ways we can do this. We can either check the whole program is correct and can be understood, and convert it into low level code ready to be run. This is called compiling. The problem is, if I find an error, I need to go back through the program to find it. Then I will need to compile it again. The other way is to check the program line by line. This is called interpreting. When we reach a line that cannot be interpreted, because it doesn’t make sense, we have to stop the program executing, and give an error. Compiling is preferable, because we find errors before the program is executed.
I have here a crazy mouse catching contraption. I’ve built the whole thing. If I test it, I can check that the whole system works. This is rather like compiling a program. The other way I could test it is I could build a small section and then test that separately, and then move onto the next section and test that. That’s like interpreting. An assembler is a program that specifically translates assembly language into binary machine code. Some programming languages use a combination of translators together.
We now need to look at things from the computers point of view. Unfortunately, computers
only understand binary, but that’s trickier for humans. High level languages, such as Scratch, and Python, are more convenient for humans, but computers can’t understand them. So, we
need to have a translator to convert the high level language into something that the computer can make sense of.
There are two ways we can do this. We can either check the whole program is correct and can be understood, and convert it into low level code ready to be run. This is called compiling. The problem is, if I find an error, I need to go back through the program to find it. Then I will need to compile it again. The other way is to check the program line by line. This is called interpreting. When we reach a line that cannot be interpreted, because it doesn’t make sense, we have to stop the program executing, and give an error. Compiling is preferable, because we find errors before the program is executed.
I have here a crazy mouse catching contraption. I’ve built the whole thing. If I test it, I can check that the whole system works. This is rather like compiling a program. The other way I could test it is I could build a small section and then test that separately, and then move onto the next section and test that. That’s like interpreting. An assembler is a program that specifically translates assembly language into binary machine code. Some programming languages use a combination of translators together.
High level code and machine code | Part D
In this section, we’ve looked at how computers can be programmed directly using machine code, and indirectly using assembly language and high level languages such as Scratch. The latter involves more work for the computer, as the code needs to be translated by either compiling, or interpreting before it can be run. Assemblers convert assembly language code into machine code. So now you’ve learned how computers run programs.
Thanks very much for watching!!
In this section, we’ve looked at how computers can be programmed directly using machine code, and indirectly using assembly language and high level languages such as Scratch. The latter involves more work for the computer, as the code needs to be translated by either compiling, or interpreting before it can be run. Assemblers convert assembly language code into machine code. So now you’ve learned how computers run programs.
Thanks very much for watching!!
High and low level code: Worksheet 1
High and low level code: Worksheet 2
Please Go to
Bitsize link
Programming Languages Introduction
Assembly Programming Tutorial
COMPILE AND EXECUTE ASSEMBLY ONLINE
DOWNLOAD MASM FOR WINDOWS7 | WINDOWS8
Bitsize link
Programming Languages Introduction
Assembly Programming Tutorial
COMPILE AND EXECUTE ASSEMBLY ONLINE
DOWNLOAD MASM FOR WINDOWS7 | WINDOWS8