Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Тексты по англ.doc
Скачиваний:
8
Добавлен:
12.11.2019
Размер:
833.02 Кб
Скачать

IV. The computer's software programming a computer

Each family of processors has its own instruction set which is likely to differ from' that of other processors. This means that a particular processor is only capable of understanding its own set of instructions in binary code.

The computer's memory can be considered as consisting of a number of cells capable of storing binary patterns representing program instructions or data. Each of these cells is uniquely numbered so that reference can be made to particular memory cells, either to select a program instruction or data, or to write data into a certain memory cell.

As an example of how programs are written in a computer's own code (machine code), it will be assumed that2 two numbers are held in memory cells 5 and 6, that these are to be added together, and the result stored in memory cell 8. The addition will be per­formed in a storage location called the accumulator, so the first instruction needs to load one of the numbers into the accumulator. The second instruction adds the other number to the number in the accumulator, which will then contain the sum of the two numbers. The third instruction stores the contents of the accumu­lator in the required memory cell.

The binary codes for these instructions for a typical processor are shown in Table 4.

is likely to differ from чаще всего отличается от it will be assumed that предположим, что

In one program run, memory cells 5 and 6 could have been set to 70 and 25, respectively- After the three instructioas in Table 5 have been obeyed, cells 5 and 6 would still contain 7,6 and 25 and cell 8 would now contain 70 + 25, i. e. 95. The same program could be run again2 with different data in cells 5 and 6 (?ay, 43 and 12), which would result in cell 8 having its previous value of 95 replaced by the new value of 55.

Programming languages

Programming in the computer's own machine code requires that the instructions and data are given to it in binary. Writing down and keying in a series of Is and Os is time-consuming and prone to error. An alternative way of expressing the instructions is to use mnemonic codes. For example, the command to load a number from memory cells could be writteh as LD A, (5) instead of the binary equivalent. Also the memory cells could be given symbolic names instead of referring to them by their actual numeric (binary) addresses.

This type of programming language is used when it is necessary to have close control over the functions of the computer. Languages which use such mnemonic codes are known as assembly languages. Each assembly language instruction usually corresponds to an equivalent machine code instruction. The translation of the assembly language program into machine code is carried out by a machine code program called an assembler.

High-level languages have been devised which allow several machine code instructions to be expressed in one statement. BASIC is such a programming language, as shown in the example below:

LET С == A + В

is a BASIC statement which causes the two numbers, held in memory cells A and B, to be added together and the sum stored in memory cell C. This is the same problem which previ­ously required several machine code or assembly language instruc­tions.

However, neither assembly language nor3 BASIC programs can be understood directly by the computer. BASIC programs need to be translated into machine code using a compiler or in­terpreter. The basic difference between these two is the stage -at which the translation from BASIC into machine code is performed.

' In one program run, memory cells 5 and 6 could have been set to 70 and 2.^,

respectively,— Пусть по ходу программы п. ячейки памяти 5 и ti ^.'шжеии

соо'п“'тетпен“<| символы 70 и 25. г could be run again - может быть запущена вновь •' neither... nor - ни,... ни

4G

Usi^g a compiler, the translation is done before the program is executed; this gives speed advantages' over an interpreter whicni performs the translation process as it executes the prog­ram. \

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]