The defining feature of modern computers which distinguishes them from all other machines is that they can be programmed. That is to say that some type of instructions (theprogram) can be given to the computer, and it will process them. Modern computers based on the von Neumann architecture often have machine code in the form of animperative programming language.
A computer program may be just a few instructions or extend to many millions of instructions, as do the programs for word processors and web browsers for example.
Replica of the Small-Scale Experimental Machine (SSEM), the world's first stored-program computer, at the Museum of Science and Industryin Manchester, England.
computer instructions are simple: add one number to another, move some data from one location to another, send a message to some external device, etc.
These instructions are read from the computer's memory and are generally carried out (executed) in the order they were given. However, there are usually specialized instructions to tell the computer to jump ahead or backwards to some other place in the program and to carry on executing from there. These are called "jump" instructions (or branches). Furthermore, jump instructions may be made to happen conditionally so that different sequences of instructions may be used depending on the result of some previous calculation or some external event.
The following example is written in the MIPS assembly language :-
begin : addi $8, $0, 0 # initialize sum to 0 addi $9, $0, 1 # set first number to add = 1 loop : slti $10, $9, 1000 # check if the number is less than 1000 beq $10, $0, finish # if odd number is greater than n then exit add $8, $8, $9 # update sum addi $9, $9, 1 # get next number j loop # repeat the summing process finish: add $2, $8, $0 # put sum in output register
individual instructions are stored as machine code with each instruction being given a unique number
While it is possible to write computer programs as long lists of numbers (machine language) and while this technique was used with many early computers,it is extremely tedious and potentially error-prone to do so in practice, especially for complicated programs.
Instead, each basic instruction can be given a short name that is indicative of its function and easy to remember- a mnemonic such as ADD, SUB, MULT or JUMP. These mnemonics are collectively known as a computer's assembly language. Converting programs written in assembly language into something the computer can actually understand (machine language) is usually done by a computer program called an assembler
Programming languages provide various ways of specifying programs for computers to run. Unlike natural languages, programming languages are designed to permit no ambiguity and to be concise.
They are purely written languages and are often difficult to read aloud. They are generally either translated into machine code by a compiler or an assembler before being run, or translated directly at run time by an interpreter. Sometimes programs are executed by a hybrid method of the two techniques.
Machine languages and the assembly languages that represent them (collectively termed low-level programming languages) tend to be unique to a particular type of computer.
For instance, an ARM architecture computer (such as may be found in a PDA or a hand-held videogame) cannot understand the machine language of an Intel Pentium or the AMD Athlon 64 computer that might be in a PC
High level languages are usually "compiled" into machine language (or sometimes into assembly language and then into machine language) using another computer program called a compiler.
High level languages are less related to the workings of the target computer than assembly language, and more related to the language and structure of the problem(s) to be solved by the final program. It is therefore often possible to use different compilers to translate the same high level language program into the machine language of many different types of computer.