UCL Department of Phonetics and Linguistics

Introduction to Computer Programming with MATLAB

Lecture 1: Introduction to Programming

Objectives

 

By the end of the session you should:

q       be able to name the basic components of a computer

q       understand that computers work with numbers for everything

q       be able to describe the basic operations of a computer

q       be able to explain how a computer is different to a large calculator

q       appreciate the 'software hierarchy' of machine code, assembler, high-level languages and scripts.

Outline

 

1.      Components

 

At the heart of a digital computer is the central processing unit (CPU) which performs the logical and arithmetical operations on streams of numbers as controlled by a “program” which is itself a stream of numbers.  The CPU has privileged access to the computer memory which can be thought of a large number of pigeonholes in which numbers can be stored and later retrieved.  The CPU can also send and receive numbers from a set of input-output ports.  These act as gateways from the CPU to other devices, such as keyboards, displays, printers, disks, analogue I/O devices, or network connections to other computers.  Collectively these external devices are called peripherals.  The CPU can select a peripheral and control its operation by sending appropriate number streams to the port to which it is connected.

2.      Working with numbers

 

The CPU can only manipulate numbers, so all pieces of information that we want the computer to manipulate must be stored as numbers.  Such information includes: numerical values, keyboard or display characters, arithmetic operations, the addresses of memory locations, the addresses of ports, and even the possible set of operations that the CPU can perform.  All these must be stored as numbers.

 

The philosophy of numbers for anything and everything is the basis of the power of the computer.  When the CPU does a calculation and generates a numerical answer, that number need not be just the size of something, but it can be a character, a memory address or even the next operation of the CPU.  It is like a calculator doing a calculation and coming up with a result that meant the calculator should next perform the square root calculation. i.e. producing a result that was an operation, not just a value.  Computers have programs, called compilers, which produce numerical results which are nothing less than other programs.

 

3.      Machine code

 

The essential operations of a CPU are actually very limited.  A CPU can

1.      Load from memory.  Given a memory address, retrieve the number stored at that address.

2.      Store to memory.  Given a memory address and a number, store the number at that address.

3.      Load from port.  Given a port address, get a number from the port.

4.      Store to port.  Given a port address and a number, send the number to the port.

5.      Arithmetic.  Given one or more  numbers, perform some basic arithmetic, such as add, subtract, multiply, divide and other logical operations such as less-than, equals or greater than.  Result is another number.

6.      Test.  Given a number, change the status of the CPU according to properties of the number,  e.g. equal to zero, less than zero

7.      Conditional jump.  Depending on the status of the CPU jump to a different list of operations stored in the memory.  For example, if the last test operation returned “equal to zero”, then start executing the instructions at memory location 1000, otherwise start executing the instructions at memory location 2000.

 

4.      Software hierarchy

 

The lowest level description of a computer program is just the sequence of numbers which encode the basic CPU operations.  This level is called machine code.   Machine code is specific to a given CPU manufacturer and often specific to a given model type (for example the Pentium CPU has some codes not used by earlier 8086 CPUs).  Machine code is very difficult for a human to read or write, so the lowest level of programming done by humans is in a language in which each basic operation is given a mnemonic code called assembly language.  Humans can read and write using assembly language which can be converted into machine code using an assembler.  Assembly language, like machine code is often specific to a particular CPU manufacturer or model. 

 

The development of high-level languages meant that humans could program using a formalism that was closer to their conceptual models of the data being manipulated: characters, real numbers, lists, tables or database records.  Such languages are easier for humans to learn and to use, and furthermore they tend to be available across different computers; with each manufacturer supplying a conversion program between the high-level language and the assembly language for their CPU.  Examples of high-level languages are Fortran, Pascal, Basic, C, C++, Java and MATLAB. 

 

Modern computer systems need to deal with complex tasks involving multiple programs interacting simultaneously, and the sharing of access to files on disks, to network resources and displays.  To cope with these demands, manufacturers supply operating systems (e.g. Windows, Linux), which are themselves programs which help the user operate the computer and run other application programs.  Often individual application programs need to work together to achieve an objective: for example a word processing application might call on a drawing package or on a spreadsheet program to do some specific processing within a document.  This idea of combining programs is called scripting, where the specifications for which programs are to be executed and how they should interact is specified in a script.

Reading

·        "Structure and Operation of Digital Computers", Encyclopaedia Britannica, 1995.

·        “Computer Architecture”, Computational Science Education Project. http://csep1.phy.ornl.gov/ca/ca.html.

·        “How microprocessors work”, http://computer.howstuffworks.com/microprocessor.htm


Exercises

1.      Obtain an account on the Departmental computer systems

2.      Log on to a PC in the department with your account name and password.

3.      Open the “Network Neighbourhood” folder and find the machine called “holtz”.  Find your two allocated folders (directories) on holtz.  The first should have your name, the second should be called “www”.

4.      Create a basic home page on the web for your account using Word, FrontPage or Mozilla Composer. Create a file called “index.html” and save it into your “www” directory on holtz.. Test out the page using Internet Explorer at

       http://www.phon.ucl.ac.uk/home/<your_account_name>/ 

5.      Create a second page.  Make a “hyperlink” between your home page and the second page.  Check that the link works in Internet Explorer.

6.      Find an image on the web that you like.  Save the image to your “www” directory.  Make a link to the image from your home page.  Check that it displays.