CHAPTER 13.5 ASSEMBLY LANGUAGE
A processor can understand and execute machine instructions. Such instructions are simply binary numbers stored in the computer. If a programmer wished to program directly in machine language, then it would be necessary to enter the program as binary data.
Consider the simple BASIC statement
Consider the simple BASIC statement
N = I + J + K
Suppose we wished to program this statement in machine language and to initialize I, J, and K to 2, 3, and 4, respectively. This is shown in Figure 13.13a. The programstarts in location 101 (hexadecimal). Memory is reserved for the four variables starting at location 201. The program consists of four instructions:
1. Load the contents of location 201 into the AC.
2. Add the contents of location 202 to the AC.
3. Add the contents of location 203 to the AC.
4. Store the contents of the AC in location 204.
2. Add the contents of location 202 to the AC.
3. Add the contents of location 203 to the AC.
4. Store the contents of the AC in location 204.
This is clearly a tedious and very error-prone process.
A slight improvement is to write the program in hexadecimal rather than binary notation (Figure 10.11b). We could write the program as a series of lines. Each line contains the address of a memory location and the hexadecimal code of the binary value to be stored in that location. Then we need a program that will
accept this input, translate each line into a binary number, and store it in the specified location.
accept this input, translate each line into a binary number, and store it in the specified location.
For more improvement, we can make use of the symbolic name or mnemonic of each instruction. This results in the symbolic program shown in Figure 10.11c. Each line of input still represents one memory location. Each line consists of three
fields, separated by spaces. The first field contains the address of a location. For an instruction, the second field contains the three-letter symbol for the opcode. If it is a memory-referencing instruction, then a third field contains the address. To store arbitrary data in a location, we invent a pseudoinstruction with the symbol DAT. This is merely an indication that the third field on the line contains a hexadecimal number to be stored in the location specified in the first field.
For this type of input we need a slightly more complex program. The program accepts each line of input, generates a binary number based on the second and third (if present) fields, and stores it in the location specified by the first field.
The use of a symbolic program makes life much easier but is still awkward. In particular, we must give an absolute address for each word. This means that the program and data can be loaded into only one place in memory, and we must know that place ahead of time. Worse, suppose we wish to change the program some day by adding or deleting a line. This will change the addresses of all subsequent words.
A much better system, and one commonly used, is to use symbolic addresses. This is illustrated in Figure 10.11d. Each line still consists of three fields. The first field is still for the address, but a symbol is used instead of an absolute numerical address. Some lines have no address, implying that the address of that line is one more than the address of the previous line. For memory-reference instructions, the third field also contains a symbolic address.
With this last refinement, we have an assembly language. Programs written in assembly language (assembly programs) are translated into machine language by an assembler. This program must not only do the symbolic translation discussed earlier but also assign some form of memory addresses to symbolic addresses.
The development of assembly language was a major milestone in the evolution of computer technology. It was the first step to the high-level languages in use today. Although few programmers use assembly language, virtually all machines provide one. They are used, if at all, for systems programs such as compilers and I/O routines.
Appendix B provides a more detailed examination of assembly language.
Tidak ada komentar:
Posting Komentar