This document covers the theory of three sections of the Higher Course:
Languages and Environments
Further Study: http://www.bbc.co.uk/education/subjects/zxmh34j
Languages and Environments
Digital computers are made up of from electronic switches which only have two states: on and off. Because of this they have to be given instructions using a language called machine code which contains only two corresponding characters: 1 and 0. For this reason the language used to directly control a computer is referred to as a low level language. Although we could give commands to computers using this code; it is not easy for humans to read or understand. For this reason why we use programming languages which are more like the languages we use to communicate between ourselves. The programming languages we use are called high level languages.
Low Level Languages
The two common low-level languages are assembly code and machine code.
Assembly code is a form of low-level language. Assembly code is created by the developers of processors. Assembly code does need some form of alteration before it can be understood by the processor. An assembler is the name given to the software that converts assembly code into binary instructions.
Assembly language is often used when high performance is crucial. The main drawbacks of assembly languages are lack of portability and the time that it takes to learn how to program.
Low-level languages generally allow for a one to one conversion into machine code (binary)
Assembly code is a low-level language
Assembly code is architecture dependent (different codes exist for different types of processor)
Assembly code is not fully portable because of architecture dependence
Assembly code needs to be converted to binary using an assembler
Low-level languages are hard to learn
Low-level languages are used for the following reasons:
Optimisation of code
Where no translator software exists
Greater control of hardware features (e.g. in small embedded computers such as home appliances)
Optimisation of code means creating code that places as little demand on system resources as possible. Low-level languages will place a much lighter load on RAM than a high-level language.
Most contemporary programming is carried out using high-level languages. High-level languages have the following characteristics:
Easier to read, write and maintain as commands are similar to English
Allow access to module libraries
Use data types and data structures, selection statements and repetition constructs
Use logic operators and functions that are built into the language
Procedural languages are designed to allow programmers to create code that will be processed logically and in a structured order. Code is contained within procedures (also called subroutines). Procedures will be created to allow a series of steps to be followed. Data can be passed from procedure to procedure using parameters.
Procedural languages rely on the process of passing data from one procedure to another. Procedures and the code within them exist independently of the data. They simply access data deemed relevant by the programmer as and when necessary. The data used is separate from the code.
Declarative languages were an attempt to create a programing language which more
closely matches how humans think than how a digital computer behaves. For this
reason, they are most closely associated with artificial intelligence programming. In
contrast to a program written in a procedural language, a program written in a declarative language will consist of a set of facts and rules (the knowledge base). When a program is run by entering a query, the solution is found by finding a match between the query and the facts and rules in the knowledge base. This is a quite different approach to how a procedural language is used, where a program would follow a set of commands in sequence (although that sequence may vary from one run to another depending on the user choices while it is running). A program written in a declarative language will not necessarily follow a specific sequence of operations.
Features of a Declarative Language:
A knowledge base contains a series of related facts (information) and rules stored in a knowledge base.
Rules Add meaning based on other facts which reduces need for repetition of facts and improves efficiency by reducing code
Declarative languages like Prolog allow for the use of self-modifying code. This means that during execution the program can modify the facts and rules that it holds if necessary.
Another key feature of declarative languages is the use of recursion. Rules are normally created to call other facts or rules. Recursion takes place when a rule calls itself until a simple base fact is identified.
Declarative languages tend to have fewer variable types and less control structures
than procedural languages.
Object-oriented languages treat data and code as part of the same object. Firstly a class is created. Objects are created within a class and will contain code and the data that the code requires. Data and code is not held separately. The name given to the concept of an object containing both the code and its related data is called 'encapsulation'.
The data associated with an object is referred to as its instance variables
sometimes known as attributes, and the procedures and functions which can
change that data are called its methods, sometimes known as operations.
Because objects in an object-oriented program are closed systems, they interact
with each other by sending messages to other objects. Messages are much easier
to manage and keep track of than the changing values of global variables.
Inheritance is an excellent feature of object-oriented programming languages. Inheritance means that a subclass will inherit the characteristics of the superclass, similarly an instance will inherit the characteristics of a sub class.
In essence this means that we could define attributes and operations for the super class shape. Each time a sub class is created it will automatically inherit the attributes and operations of shape. The programmer only needs to add attributes and operations that make that subclass unique.
If line thickness were regarded as an attribute of a shape then each time a new sub class was created it would automatically contain an attribute for line thickness. This makes it much easier to make changes to objects as a change to the characteristics of a superclass will be reflected in the same change being made in each subclass and instance.
Inheritance allows for the re-use of the same code when creating a subclass or instance, such code can be contained within a class library, further reducing implementation time. Only additional methods and attributes need to be declared for subclasses
Translating high level languages into machine code
High level programming languages always need to be translated into machine code
before they can be run on the machine they are being written on. There are two
approaches to the translation process.
Interpreters: An interpreter translates the program (or source code) into machine code line by line. This means that the interpreter can flag up errors in code as it is being typed. Unfortunately an interpreter will be needed every time the program is run and the translation process will slow down the execution of the program.
Compilers: Compilers translate the program (or source code) into machine code in one operation. Once translated the program can be run independently of the compiler and therefore it runs faster than an interpreted program, however if the programmer wants to change code as a result of testing, it will need to be re-compiled. Compiled programs are more efficient because no extra memory or processor resources are needed for the translation software.
Many modern environments provide the best of both worlds - an interpreter to write, test and debug the program, and a compiler to translate the source code into an executable machine code program once it is ready to distribute.
The main difference between an interpreter and a compiler is that compilation "requires the analysis and generation of machine code only once, whereas an interpreter may need to analyse and interpret the same program statements each time it meets them e.g. instructions appearing within a loop.
For example, consider the following code:
For i = 1 to 200
count = count + 1
Using a compiler, the source code would be analysed and compiled into machine code once only. Using an interpreter, the source code would be converted into machine code 200 times (once each time round the loop).
This has implications for error reporting. For instance, when the interpreter encounters an error it reports this to the user immediately and halts further execution of the program. Such instant feedback, pinpointing the exact location of the error, helps the programmer to find and remove errors. Compilers, on the other hand, analyse the entire program, taking note of where errors have occurred, and place these in an error/diagnostic file. If errors have occurred then the program cannot run. Programmers must then use the error messages to identify and remove the errors in the source code. Some compilers assist by adding line numbers to the source listing to help pinpoint errors and all compilers will describe the nature of the error e.g. missing semi-colon, expected keyword, etc. - although interpreting some compiler diagnostics is a skill in itself.
Ease of use
Interpreters are more suitable for beginners to programming since errors are
immediately displayed and can be corrected by the user, until the program is able to
be executed. On the whole compilers tend to be more difficult to use because they only give the programmer error messages once the code has been translated.
A compiler produces a complete machine code program which can be saved, copied, distributed and run on any computer which has the appropriate processor type. A programming language is said to be portable if recompiling it on different platforms is relatively easy. An interpreter does not do this. The machine code has to be generated each time the program is run. This means that the interpreter must always be present, and program execution is slower.
A computer solves a problem by storing a set of instructions (a program) in memory that are then fetched and executed one at a time to solve a problem. This is called the ‘stored program concept’.
The diagram below shows the basic components of a computer system.
The CPU (central processing unit) is made up of a processor chip and main-memory chips. The processor is responsible for fetching and executing instructions held in main memory, one at a time.
The processor is made up of three components:
1 Control unit
2 Arithmetic and logic unit (ALU)
The control unit is responsible for initiating the fetching, decoding and execution of instructions by sending out signals to other parts of the computer system.
ALU (arithmetic Logic unit)
The ALU carries out arithmetic operations (+, –, *, /) and logical operations such as AND, OR, NOT and so on.
Registers are individual storage locations on the processor which hold an instruction, data or the address of a memory location.
Processors were originally developed with only one core, which meant that they could only execute one instruction at any given instant. In recent years, there has been a move towards multi-core processors, i.e. a single chip with two or more processor components (called cores) which can independently execute program instructions. Multi-core processors can execute multiple instructions at the same time, thus increasing the overall speed of program execution. Manufacturers typically integrate several cores onto a single integrated circuit. A dual-core processor has two cores (e.g. AMD Phenom II X2; Intel Core Duo), while a quad-core processor contains four cores (e.g. AMD Phenom II X4; Intel’s quad-core processors). Eight-core processors and beyond exist which are suited to running applications where a high-performance computer system is required, such as high-resolution gaming.
Main memory stores the programs and data that are currently being executed. It consists of RAM and ROM chips.
RAM (random-access memory)
RAM is volatile (loses its contents when the power is switched off). RAM can be read from and written to. When a program is loaded from the hard disc to be run, the program instructions are written into RAM. There are two types of RAM: static RAM and dynamic RAM. Static RAM keeps its contents so long as power is maintained to the chip, but dynamic RAM requires to be refreshed every few milliseconds by rewriting its contents – as well as power being supplied. Dynamic RAM has simpler circuitry than static RAM and needs less power. Consequently, dynamic RAM is cheaper than static RAM. The main advantage of static RAM over dynamic RAM is that it has faster access.
ROM (read-only memory)
ROM is non-volatile (keeps its contents when the power is switched off). The programs in ROM are put into the chip when it is manufactured, and are permanent. The instructions in ROM can be read by the processor, but they are never written to. A small part of the operating system which is executed at start-up, called the BIOS (Basic Input/Output System), is stored in ROM.
This is an area of fast-access memory either between the processor and main memory or on the processor chip itself. The cache holds instructions and data that are used most frequently. Since these are in fast-access storage, it increases the overall performance of the system.
The CPU has buses, which are multiple wires/lines that connect the processor and main memory. They are used to carry data, to specify memory-location addresses, and to send signals between them.
This bus is used to transfer data between main memory and the processor. It is a two-way bus, since data can be transferred from a memory location to the processor and vice versa. Early computers had a data bus that was 8 lines wide and transferred 8 bits in a single operation. Modern desktop computers will typically have a 64-bit data bus. The number of bits that the processor transfers in one operation is called the word size.
This bus is used to specify the address of the memory location that is to be read from or written to. This bus is a one-way bus, since the processor will use it to specify which memory location it is going to use; but the reverse does not apply. Early computers had an address bus that was 16 lines wide. Modern desktop computers will typically have a 32-bit address bus.
Each of the control-bus lines has a specific function. Here are the functions of some control-bus lines:
Read – A signal down this line is used to initiate a memory READ operation, which reads the contents of a memory location into the processor.
Write – A signal down this line is used to initiate a memory WRITE operation, which writes an item of data from the processor into a memory location.
Clock – The clock line sends a regular series of pulses into the processor to synchronise events. The time interval between each pulse is called a clock cycle. For example, a memory read or a memory write takes place in one clock cycle.
Reset – A signal down this line causes the computer to stop execution of the current program and then to reboot.
Interrupt – Peripheral devices, such as printers, can send a signal on the interrupt line into the processor when they require attention. This causes the processor to deal with the interrupting device.
Memory read and write operations
A processor reads instructions from memory as part of the fetch–execute cycle, or reads items of data to perform a calculation.
Step 1 The processor sets up the address bus with the address of the required memory location.
Step 2 The processor activates the READ line on the control bus.
Step 3 The contents of the memory location are transferred along the data bus into the processor.
Step 4 If it is an instruction, it is decoded and executed.
Step 1 The processor sets up the address bus with the address of the required memory location.
Step 2 The processor sets up the data bus with the data to be written to memory.
Step 3 The processor activates the WRITE line on the control bus.
Step 4 The data is transferred along the data bus to the memory location.
An interface is a combination of the hardware and software between the processor and a device to allow for their differences in speed and operation.
Typically, this will be a wired connection; but wireless connections are becoming more frequent.
Data Format Conversion
The CPU stores data in a different format from the peripheral device. For example, the voltage levels representing 1 and 0 can vary, and analogue-to-digital conversion may be required. Data-format conversion can also involve the conversion of serial data to parallel data. In a serial interface, each bit of data is transferred one bit after another down a single line. In a parallel interface, multiple bits are transferred down parallel lines at the same time.
The interface provides an area to store data until the slower peripheral device is ready to accept it.
The interface provides information on the current state of the device. For example, a printer interface will provide information such as: ready to accept more data, printer out of paper, toner low and so on.
A protocol is a set of rules agreed between a sender and receiver so that they can successfully communicate with each other. The interface may require to convert protocols so that the CPU and the device can communicate.
Software development language trends
New programming languages are being created all the time. Development may be driven by industry need or result from academic research. Some of the current trends in programming language development include:
Increased methods of improving security in software.
Trend towards specialist languages – e.g. for Robots
Metaprogramming, in which programs are created to write other programs.
Extended parallel languages for coding supercomputers with thousands of processors.
An increase in open source languages created by an online community and distributed for free.
Languages which improve integration with databases.
Software development environment trends
In addition to new languages, new editing environments have improved programmers’ productivity by providing better editing, checking and debugging facilities.
A source code editor has features such as indentation, text prediction, bracket matching and syntax highlighting. These features speed up the inputting and editing of source code. Source code editors evolved from simple text editors that behaved as basic word processors. Source code editors now can check syntax while it is being entered, immediately warning the user of potential problems.
A modern debugger will feature a variety of debugging tools, including:
Single stepping – executing a program one line at a time with each step forward being controlled by the user.
Breakpoints – stopping execution at identified points.
Variable tracking – windows showing the current values stored in variables and data structures.
An integrated development environment (IDE) is a development environment that combines multiple tools, such as a source code editor, debugger, interpreter and compiler.
Intelligent systems developments
Key features of an intelligent system:
ability to learn
ability to make decisions without direct human input
presence of several aspects of human intelligence
An intelligent computer is an embedded computer with the ability to communicate with other systems via the internet. These computer systems are usually specialised machines built for a specific purpose.
Examples of intelligent systems are everywhere, from traffic lights to aeroplanes. Some theorists predict that in the future every object and person will be able to share data continuously and automatically, creating an ‘Internet of Things’.
Increasing use of robotics and autonomous unmanned vehicles
Common industrial applications are in car-manufacturing robots, underwater robots, demolition robots and surgical robots.
Autonomous unmanned vehicles have sensors and AI software that allow them to act independently rather than being remotely controlled by a human operator. They have a huge potential to work in environments that are dangerous for humans, such as deep-sea exploration, outer space and war zones.
It is highly likely that driverless cars will be on our roads within the next ten to fifteen years.
Increasing use of expert Systems
An expert system is a computer program that contains a knowledge base on a particular subject to offer advice or make decisions. Expert systems can save money by removing the need to pay for a human expert. Contemporary uses of expert systems are in areas such as medicine, helpdesk systems, machine repair and financial decisions.
Online systems developments
The convergence of database and website technologies has led to a significant rise in systems that are entirely online.
Booking systems now often have no human interaction. Users can log in to websites to book hotel rooms, train tickets, concert tickets and even doctors’ appointments. The online system will automatically generate an email in which the user may receive electronic tickets or a booking confirmation. This can be printed as evidence of the online booking. Some systems may take this even further and allow users to confirm their arrival by scanning a barcode or entering a purchase code into a computer system. Online booking systems have significant financial advantages to companies, as with fewer staff, their wage bill may be dramatically reduced, increasing their profits.
A particular area of rapid expansion is the number of users of social-media websites.
Online shopping is having an increasing impact on the way in which people shop, and is reducing prices by increasing competition and the recycling of second-hand goods.
Share with your friends: