{"id":222,"date":"2016-12-29T22:22:08","date_gmt":"2016-12-29T22:22:08","guid":{"rendered":"http:\/\/teachcomputerscience.com\/?p=222"},"modified":"2024-07-24T13:04:47","modified_gmt":"2024-07-24T13:04:47","slug":"programming-languages","status":"publish","type":"post","link":"https:\/\/teachcomputerscience.com\/programming-languages\/","title":{"rendered":"Programming Languages &#8211; High-Level Code &#038; Machine Code"},"content":{"rendered":"<div class=\"gb-container gb-container-03750d5c upsell-block\"><div class=\"gb-inside-container\">\n<div class=\"gb-grid-wrapper gb-grid-wrapper-b48202b9\">\n<div class=\"gb-grid-column gb-grid-column-ff70a03e\"><div class=\"gb-container gb-container-ff70a03e\"><div class=\"gb-inside-container\">\n\n<h2 class=\"gb-headline gb-headline-e0d2f8bf gb-headline-text\">KS3 Programming Languages (14-16 years)<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>An editable PowerPoint lesson presentation<\/li><li>Editable revision handouts<\/li><li>A glossary which covers the key terminologies of the module<\/li><li>Topic mindmaps for visualising the key concepts<\/li><li>Printable flashcards to help students engage active recall and confidence-based repetition<\/li><li>A quiz with accompanying answer key to test knowledge and understanding of the module<\/li><\/ul>\n\n\n<div class=\"gb-button-wrapper gb-button-wrapper-4eb2799f\">\n\n<a class=\"gb-button gb-button-6fb8272b gb-button-text\" href=\"https:\/\/teachcomputerscience.com\/ks3\/programming\/programming-languages\/\">View KS3 Programming Languages Resources<\/a>\n\n<\/div>\n<\/div><\/div><\/div>\n\n<div class=\"gb-grid-column gb-grid-column-24d5d7b1\"><div class=\"gb-container gb-container-24d5d7b1\"><div class=\"gb-inside-container\">\n\n<h2 class=\"gb-headline gb-headline-4d5eacd7 gb-headline-text\">A-Level Procedural and Object-oriented Languages (16-18 years)<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>An editable PowerPoint lesson presentation<\/li><li>Editable revision handouts<\/li><li>A glossary which covers the key terminologies of the module<\/li><li>Topic mindmaps for visualising the key concepts<\/li><li>Printable flashcards to help students engage active recall and confidence-based repetition<\/li><li>A quiz with accompanying answer key to test knowledge and understanding of the module<\/li><\/ul>\n\n\n<div class=\"gb-button-wrapper gb-button-wrapper-35d22eb2\">\n\n<a class=\"gb-button gb-button-6f939080 gb-button-text\" href=\"https:\/\/teachcomputerscience.com\/a-level\/software\/procedural-and-object-oriented-languages\/\">View A-Level Procedural and Object-oriented Languages Resources<\/a>\n\n<\/div>\n<\/div><\/div><\/div>\n<\/div>\n<\/div><\/div>\n\n\n\n\n<p class=\"wp-block-paragraph\">Candidates should be able to:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>explain the difference between high level code and machine code<\/li><li>explain the need for translators to convert high level code to machine code<\/li><li>describe the characteristics of an assembler, a compiler and an interpreter<\/li><li>describe common tools and facilities available in an integrated development environment (IDE): editors, error diagnostics, run-time environment, translators, auto-documentation.<\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">What is machine code?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Machine code is the lowest level of programming language because the instructions are executed directly by a computer&#8217;s central processing unit (CPU). It is important to understand that every CPU or CPU family has its own machine code instruction set.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Machine code instructions are simply numbers stored as a <strong>binary pattern of bits<\/strong> i.e. <strong>10101001<\/strong>01000000.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A machine code instruction is typically made up of two parts:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>an <strong>operator<\/strong> (OP code) which is the instruction part that the CPU executes (carries out). i.e. <strong>10101001<\/strong> could be an instruction for the CPU to load from memory.<\/li><li>an <strong>operand<\/strong> (typically a <strong>memory address<\/strong> where data is read from or written to, depending on the operator). i.e. <strong>01000000<\/strong> could be memory address 64.<\/li><li>Some OP codes such as the one to END a program do not require an operand.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Writing programs directly in machine code would be tedious and error-prone as all the numerical addresses for branch instructions and data locations would need to be calculated manually. Assembly language was an initial solution to this problem, followed by increasingly sophisticated higher-level programming languages.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Because machine code instructions are the only ones the CPU can execute, the source code for ALL other programming languages must be converted into machine code before it can be executed. This translation is carried out by special programs called <strong>compilers<\/strong>, <strong>translators<\/strong> or <strong>assemblers<\/strong>.<\/p>\n\n\n\n<div class=\"callout\">\n<p>The Little Man Computer (LMC) is a simulator that models a simple Von Neumann architecture computer. It can be programmed in assembly language or machine code and includes a basic guide and some example programs.There are two versions available:<\/p>\n<ul>\n<li><del>The JAVA applet version &#8211; an online version recommended by OCR<\/del> &nbsp;Most web browsers block JAVA applets now<\/li>\n<li><a href=\"http:\/\/teachcomputerscience.com\/revision\/lmc-simulator\/\">The VB.NET version<\/a> &#8211; based on the above version, it can be downloaded and installed on a Windows computer<\/li>\n<\/ul>\n<\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">What is high-level code and why does it need a translator?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">High-level code uses <strong>words that are designed to be read by human programmers as well as a computer<\/strong>. Statements written in high-level languages such as Visual Basic, C++, Python, Delphi and Java are therefore understood far more easily than programs written in machine code or assembly language.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">High level code is also <strong>portable between different computer operating systems<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">High level source code will make use of some or all of the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Keywords<\/strong> &#8211; reserved words such as SORT, IF, FUNCTION etc. which are simple to understand and would involve a lot of programming using machine code.<\/li><li><strong>Syntax<\/strong> &#8211; rules for the use of keywords and the arguments that go with them.<\/li><li>More complex <strong>iteration<\/strong> and <strong>conditional<\/strong> programming structures than just simple branches<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>The CPU can only execute machine code instructions<\/strong>. This means that <strong>code written in any other programming language has to be translated into machine code<\/strong> before it can be executed. This translation is carried out by two types of program:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">An interpreter<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>An <strong>interpreter<\/strong> allows the programmer to run the source code but only within the interpreter. It does this by translating the source code into the equivalent machine code <strong>line-by-line, as the program is running<\/strong>. This makes the program run relatively slowly as each instruction has to be translated before it can be executed and <strong>an error will cause the program to stop at that line<\/strong>. However, it is ideal during the <strong>development stages<\/strong> as it allows the programmer to quickly <strong>test<\/strong> their source code and <strong>resume the program once an error is fixed<\/strong>.<\/li><li><strong>Advantages<\/strong> of using an interpreter:\n<ul>\n<li>It is <strong>easier to check for errors<\/strong> than with a compiler because the error can easily be traced to the line of source code that generated it.<\/li>\n<li>It is <strong>faster to develop software<\/strong> because the whole program does not need to be compiled every time something needs to be tested.<\/li>\n<\/ul>\n<\/li><li><strong>Disadvantages<\/strong> of using an interpreter:\n<ul>\n<li>The program <strong>cannot be executed without the source code<\/strong>.<\/li>\n<li>Because the source code needs to be available and is usually just text, the program to be executed is <strong>less secure<\/strong>.<\/li>\n<li>An <strong>interpreted program will execute more slowly<\/strong> than a compiled program due to the line-by-line translation.<\/li>\n<\/ul>\n<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">A compiler<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>A <strong>compiler<\/strong> is used once the source code has been <strong>fully developed<\/strong> and <strong>tested<\/strong> using an interpreter. It <strong>translates the completed source code into machine code<\/strong> and creates a new file which can be executed by the CPU as a <strong>stand-alone program<\/strong>. This translation can involve several stages and may take a considerable amount of time because one source code instruction may translate into hundreds of machine code instructions.<\/li><li><strong>Advantages<\/strong> of using a compiler:\n<ul>\n<li>The source code is not included so compiled machine code is much <strong>more secure<\/strong> than interpreted code.<\/li>\n<li>It produces an executable file so the program <strong>can be run without the source code<\/strong>.<\/li>\n<\/ul>\n<\/li><li><strong>Disadvantages<\/strong> of using a compiler:\n<ul>\n<li>It is a <strong>slow process translating<\/strong> the source code into machine code.<\/li>\n<li>Even the smallest change means that the whole compilation process has to be done again.<\/li>\n<\/ul>\n<\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">What is assembly language and what is an assembler?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Because each machine code instruction is just made up of numbers stored as a binary bit pattern it is very difficult for humans to read or develop software directly using machine code. <strong>Assembly language<\/strong> was the original attempt to solve this problem (followed by increasingly <strong>advanced high-level programming languages<\/strong>).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Assembly language is a very simple programming language that uses <strong>mnemonics<\/strong> (memory aids) to directly represent machine code instructions. It uses <strong>labels<\/strong> to represent the memory addresses of branch destinations and data.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>An assembler translates assembly language instructions into machine code instructions.<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There is nearly a one-to-one match between assembly language instructions and machine code instructions. This means that a machine code program translated from assembly language is <strong>very efficient<\/strong> and therefore tends to <strong>require less memory<\/strong> and <strong>run faster<\/strong> than a machine code program translated from a high-level language using a compiler.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The table below shows some examples of assembly language mnemonics and the 16-bit machine code instructions produced when they are assembled. Each machine code instruction is made up of an <strong>operator<\/strong> (op code) and an <strong>operand<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-table rcp-table\"><table><tbody><tr><th>Assembly language mnemonic<\/th><th>Machine code<\/th><th>What it does<\/th><\/tr><tr><td><span class=\"style6\">LDA<\/span> <span class=\"style7\">#64<\/span><\/td><td><strong>10101001<\/strong><span class=\"style7\">01000000<\/span><\/td><td><span class=\"style6\">Load*<\/span> the accumulator with the number <span class=\"style7\">64<\/span><\/td><\/tr><tr><td><span class=\"style6\">ADC<\/span> <span class=\"style7\">#64<\/span><\/td><td><span class=\"style6\"><strong>01101001<\/strong><\/span><span class=\"style7\">01000000<\/span><\/td><td><span class=\"style6\">Add<\/span> the number <span class=\"style7\">64<\/span> to whatever is in the accumulator<\/td><\/tr><tr><td><span class=\"style6\">LDA<\/span> <span class=\"style7\">64<\/span><\/td><td><strong>10100101<\/strong><span class=\"style7\">01000000<\/span><\/td><td><span class=\"style6\">Load*<\/span> the accumulator with the data&nbsp;<strong>stored<\/strong> in memory address <span class=\"style7\">64<\/span><\/td><\/tr><tr><td><span class=\"style6\">ADC<\/span> <span class=\"style7\">64<\/span><\/td><td><strong>01101001<\/strong><span class=\"style7\">01000000<\/span><\/td><td><span class=\"style6\">Add<\/span> to the accumulator the data&nbsp;<strong>stored<\/strong> in memory address <span class=\"style7\">64<\/span><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">*The machine code instruction to load a fixed number into the accumulator is different from the one to load a number from a memory address, even though the mnemonic is the same. In assembly language, the # symbol is used to denote a number rather than a memory address.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Advantages of writing programs in assembly language:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>It usually <strong>creates fast running programs<\/strong> because the one-to-one match means that the machine code program created will tend to be very efficient.<\/li><li>The <strong>translation into machine code will be very fast<\/strong> due to the one-to-one match between assembly language instructions and machine code instructions.<\/li><li><strong>Easier to understand compared to machine code<\/strong> due to the use of mnemonics.<\/li><li><strong>Labels can be used to label memory addresses.<\/strong> Without these, adding or removing an instruction means all the memory addresses referred in the program need to be recalculated.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Disadvantages of writing programs in assembly language:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Different versions of an assembly language are often required for different processors making it <strong>difficult to transfer programs between processors.<\/strong><\/li><li>Assembly language programs are <strong>often written for specific hardware<\/strong> which means they are often incompatible with different hardware.<\/li><li><strong>A lot of assembly code is needed to do relatively simple tasks<\/strong> so complex programs require a lot of assembly instructions and it will take a lot time to write the program.<\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">What common tools and facilities are available in an integrated development environment (IDE)?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">An integrated development environment (IDE) is a software application that provides a complete set of facilities for a computer programmer to develop a software application in a high-level language, test it and then convert it into a stand-alone machine code application.<\/p>\n\n\n\n<div class=\"wp-block-image size-full wp-image-225\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"450\" height=\"324\" src=\"http:\/\/teachcomputerscience.com\/wp-content\/uploads\/2016\/12\/ide_screenshot.png\" alt=\"Programming Languages: A screenshot of an IDE used to write programs in C++\" class=\"wp-image-225\" title=\"\" srcset=\"https:\/\/teachcomputerscience.com\/wp-content\/uploads\/2016\/12\/ide_screenshot.png 450w, https:\/\/teachcomputerscience.com\/wp-content\/uploads\/2016\/12\/ide_screenshot-300x216.png 300w\" sizes=\"auto, (max-width: 450px) 100vw, 450px\" \/><figcaption>A screenshot of an IDE used to write programs in C++<\/figcaption><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">An IDE will be specific to a certain high-level language and will normally consist of:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>an <strong>editor<\/strong> &#8211; to allow source code to be entered and edited.<\/li><li><strong>build automation tools<\/strong> &#8211; to automate a wide variety of tasks such as entering source code with the correct <strong>syntax<\/strong>, managing variables etc.<\/li><li><strong>error diagnostics<\/strong> &#8211; to produce error messages that highlight <strong>what<\/strong> an error is and <strong>where<\/strong> it has occurred (either by highlighting it or indicating the line number of the error).<\/li><li>an <strong>interpreter<\/strong> &#8211; to allow source code to be translated <strong>line by line<\/strong> into machine code instructions so they can be executed from <strong>within the IDE<\/strong>.<\/li><li>a <strong>compiler<\/strong> &#8211; to translate the <strong>completed<\/strong> source code into machine code so it can be executed as a <strong>stand-alone program file<\/strong>.<\/li><li>a <strong>run-time environment<\/strong> to allow the programmer to test the program <strong>while it is running<\/strong>. This allows the program to be run in an environment where the programmer can track the instructions and variables being processed by the program and diagnose any errors that might occur. If the program crashes, the run-time environment keeps running and can provide information about why the crash occurred.<\/li><li><strong>auto-documentation<\/strong> to create reference manuals in such as text or HTML files by extracting the comments where available from the source code. Such comments can be written by the programmer as they create and modify the source code, making it much easier to keep the documentation up-to-date.<\/li><\/ul>\n\n\n\n<div class=\"callout action\">&nbsp;<\/div>\n\n\n\n<h3 class=\"gb-headline gb-headline-6b86f789 gb-headline-text\">Further Readings:<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/en.wikipedia.org\/wiki\/High-level_programming_language\" target=\"_blank\" rel=\"noopener\">High-level programming language<\/a><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Candidates should be able to: explain the difference between high level code and machine code explain the need for translators to convert high level code to machine code describe the characteristics of an assembler, a compiler and an interpreter describe common tools and facilities available in an integrated development environment (IDE): editors, error diagnostics, run-time &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Programming Languages &#8211; High-Level Code &#038; Machine Code\" class=\"read-more button\" href=\"https:\/\/teachcomputerscience.com\/programming-languages\/\" aria-label=\"Read more about Programming Languages &#8211; High-Level Code &#038; Machine Code\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_monsterinsights_skip_tracking":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[14],"tags":[204,47],"class_list":["post-222","post","type-post","status-publish","format-standard","hentry","category-programming","tag-article","tag-hide-old-upsell","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50"],"acf":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/posts\/222","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/comments?post=222"}],"version-history":[{"count":1,"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/posts\/222\/revisions"}],"predecessor-version":[{"id":605736,"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/posts\/222\/revisions\/605736"}],"wp:attachment":[{"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/media?parent=222"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/categories?post=222"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/tags?post=222"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}