MICROPROCESSOR INSTRUCTION SET AND COMPUTER LANGUAGES

MICROPROCESSOR INSTRUCTION SET AND COMPUTER LANGUAGES

Microprocessors recognize and operate in binary numbers. However, each micro­processor has its own binary words, instructions, meanings, and language. The words are formed by combining a number of bits for a given machine. The word (or word length), as defined earlier, is the number of bits the microprocessor rec­ognizes and processes at a time. The word length ranges from 4 bits for small, microprocessor-based computers, to 32 bits for such large computers as the IBM ES 9000 series. Another term commonly used to express word length is byte. The ,byte is defined as a group of eight bits. For example, a l6-bit microprocessor has a word length equal to two bytes. The term "nibble," which stands for a group of four bits, is also found in popular computer magazines and books. (A byte has two nibbles.)

TABLE 1

Microcomputer Applications

MICROPROCESSOR INSTRUCTION SET AND COMPUTER LANGUAGES -17_03 

The instruction is defined as a complete task (such as Add) the microproces­sor can perform ; it can be made up of one or more words. Each machine has its own set of instructions based on the design of its CPU or its microprocessor. To be intelligible to the microprocessor, instructions must be written in binary lan­guage, also known as machine language. However, it is difficult for human beings to write programs in sets of Os and Is. Therefore, microprocessor manufacturers have devised English-like words to represent the binary instructions of a machine, and programmers can write programs using these words. These are called assem­bly language programs. Because an assembly language is specific to a given ma­chine programs written in assembly language are not transferable from one ma­chine to another. To circumvent this limitation, such general-purpose languages as BASIC, FORTRAN, PASCAL, and C have been devised so that a program written in these languages can be machine-independent. These languages are called high-level languages (HLL). This section deals with various aspects of these three types of languages: machine, assembly, and high-level. The machine and assembly languages are discussed in the context of the 280 microprocessor.

Machine Language

The number of bits in a word for a given machine is fixed, and words are formed through various ‘combinations of these bits. For example; a machine with a word length of eight bit scan have 756 (28) combinations of eight bits-thus a language of 256 words. However, not all of these words need to be used in the machine. The microprocessor design engineer selects combinations of bit patterns and gives a specific meaning to each combination by using electronic logic circuits; this is called an instruction .The set of instructions designed into the machine makes up what is called the machine language, a binary language composed of Os and Is. Its words, its instructions, and their meanings are specific to each computer. In this book, we are concerned with the language of the Z80 microprocessor from Zilog Corporation, a widely used microprocessor in industrial ·applications. The primary focus here is on the microprocessor, because it is the microprocessor that determines the machine language and the operations of a microcomputer.

Z80 Machine Language

The Z80 is a microprocessor with 8-bit word length .Its instruction set (or lan­guage) is upward compatible with that of the 8080; the Z80 has 158 instruction types that include the entire 8080 set of 72 instruction types. An instruction, as discussed earlier, is a binary pattern entered through an input device to command the microprocessor to perform a specific function. For example:

0011 1100           is an instruction that increments the number in the register called the accumulator by one.

1000 0000           is an instruction that adds the number in the reg­ister called B to the number in the accumulator, and keeps the sum in the accumulator.

The Z80 microprocessor has a variety of such bit patterns resulting in its 158 instruction types for performing; different operations, called the instruction set. The Z80 microprocessor also accepts data in 8-bit words as input from input de­vices, processes data according to the instructions written by the user, and sends out data in 8-bit words to output devices. This binary language with a predeter­mined instruction set is called the Z80 machine language.

However, it is tedious and conducive to error for human beings to recognize and write instructions in binary language. Therefore, for convenience, these in­structions are written in hexadecimal (or octal) code and entered into a single­ board microcomputer by using Hex keys.

For example, the binary instruction 0011 1100 (mentioned previously) is equivalent to 3C in hexadecimal. This instruction can be entered into a single ­board microcomputer system with Hex keyboard by pressing two keys: 3 and C. The monitor program of the system translates these keys into their equivalent binary pattern .

Z80 Assembly Language

Even though the instructions can be written in hexadecimal code, it is still not easy to understand such a program. Therefore, each manufacturer of micropro­cessors has devised a symbolic code for each instruction, called a mnemonic. (The word mnemonic is based on the Greek word related to memory aid.) The mne­monic for a particular instruction consists of letters that suggest the operation to be performed by that instruction.

For example, the binary code 001] 1100 (3C16 or 3CH (Hexadecimal numbers are shown with the subscript H in the text ) in hexadecimal) of the 280 microprocessor is represented by the mnemonic INC A:

INC  A                INC stands for increment, and A represents the accumulator. This symbol suggests the operation of incrementing the accumulator con­tent by one.

Similarly, the binary code 10000000 (8016 or 80H (Hexadecimal numbers are shown with the subscript H in the text ) is represented as follows:

ADD A, B          ADD stands for addition, and A and B represent the contents in the accumulator and register B, respectively. This symbol suggests the addition of the contents in register B and the accumulator.

Even though these symbols do not sp~ the complete operations, they suggest the significant portions. The complete description of each instruction must be supplied by the manufacturer. The complete set of Z80 mnemonics is called the Z80 instruction set, and a program written in these mnemonics is called an assembly language program. Again, the assembly language is specific to each microprocessor. For example, the Motorola 6809 microprocessor has an entirely different set of binary codes and mnemonics from that of the Z80. An assembly language program written for one microprocessor is not transferable to a com­puter with another microprocessor unless the two microprocessors are compatible in their machine codes.

The machine language and the assembly language are microprocessor­ specific, and both are considered low-level languages. The machine language is in binary, and the assembly language is in English-like words; however, the micro­processor understands only the binary. How, then, are the assembly language mnemonics entered into a microprocessor system and translated into binary code? In a microcomputer, the mnemonics are entered as ASCIl code (explained in the next section) using the keyboard as an input device, and the translation is per­formed by a program called an assembler. In a single-board microcomputer, the user translates mnemonics into Hex digits by looking up the code manually in the instruction set and enters them into the system through the Hex keyboard. This is called hand assembly.

Alphanumeric Codes

A computer is a binary machine; in order to communicate with the computer in alphabetic letters and decimal numbers. translation codes are necessary. The commonly used code is known as ASCII-American Standard Code for Infor­mation Interchange. It is a 7-bit code with 128 (27) combinations, and each combination from OOH to 7FH is assigned to either a letter, a decimal number, a symbol, or a machine command (see Appendix C). For example, hexadecimal 30H to 39H represent 0 to 9, decimal digits, 41H to 5AH represent capital letters A through Z, 20H to 2FH represent various symbols, and the initial codes OOH to I FH represent such machine commands as carriage return and line feed. Devices that use ASCII characters include ASCII terminals, teletype machines (TTY), and printers. When the key 9 is pressed on an ASCII terminal, the computer receives 39H in binary, and the system program translates ASCII characters into appropriate bi­nary or BCD numbers.

Another code, called EBCDIC (Extended Binary Coded Decimal Inter­change Code) is widely used in IBM computers (except in lBM Personal Com­puters or microcomputers). This is an 8-bit code represent in 256 combinations; however, several combinations are not used.

Writing and Executing an Assembly Language Program

As explained earlier, a program is a set of logically related instructions written in a specific sequence to accomplish a task. To write and execute an assembly lan­guage program manually on a single-board computer, with a Hex keyboard for input and LEOs (or seven-segment LEOs) for output, the following steps are necessary:

1. Write the instructions in mnemonics obtained from the instruction set supplied by the manufacturer.

2. Find the hexadecimal machine code for each instruction by searching through the set of instructions.

3. Enter (load) the program in the user memory in a sequential order by using the Hex keyboard as the input device.

4. Execute the program by pressing the Execute key. The answer will be dis­played by the LEOs.

When the user program is entered by the keys, each entry is interpreted and converted into its binary equivalent by the monitor program. and the machine code is stored as eight bits in each memory location in a sequence. When the Execute command is given, the microprocessor fetches each instruction, decodes it. and executes it in a sequence until the end of the program.

The manual assembly procedure is commonly used in single-board micro­computers and is suited for small programs. However, the steps of looking up the machine codes and entering the program, which are tedious and object to errors, can be avoided by using an assembler on a microcomputer system.

The assembler is a program that translates the mnemonics entered by the ASCII keyboard into the corresponding binary machine codes of the micropro­cessor. Each microprocessor has its own assembler because the mnemonics and machine codes are specific to the microprocessor being used, and each assembler has certain rules that must be learned by the programmer. Assemblers are dis­cussed in detail new topic .

High-Level Languages

Programming languages that are intended to be machine-independent are called high-level languages. The list includes such languages as C, FORTRAN, BASIC, PASCAL, and COBOL. These languages have certain sets of rules and draw on symbols and conventions from English. Instructions written in these languages are known as statements rather than mnemonics .A program written in BASIC for a microcomputer with the Z80 microprocessor can generally run on another microcomputer with a different microprocessor.

Now the question is: How do words in English get converted into the binary languages of different microprocessors? The answer lies with another program called either a compiler or an interpreter. These programs accept English-like statements as their input, called the source code. The compiler or interpreter ~hen translates the source code into the machine language compatible with the micro­processor being used in the system. This translation into the machine language is called the object code (Figure 1.7). Each microprocessor needs its own compiler or interpreter for each high-level language. The primary difference between a compiler and an interpreter is in the process of generating machine code. The compiler reads the entire program first and then generates the object code, while the interpreter reads one instruction at a time, produces its object code, and ex­ecutes the instruction before reading the next instruction. Compiled programs are executed much faster than interpreted programs. M-Basic is a common example of an interpreter for the BAS]C language. Compilers are generally used in such languages as C, FORTRAN, and PASCAL.

Compilers and interpreters require large memory space because each in­struction in English requires several machine codes to translate that instruction into binary. On the other hand, there is a one-to-one correspondence between the assembly language mnemonics and the machine code. Thus, assembly language programs are compact and require less memory space; they are more efficient than the high-level language programs. The primary advantage of high-level lan­guages is in troubleshooting programs, also known as debugging. It is much easier to find errors in a program written in a high-level language than to find them in a program written in assembly language.

In certain applications such as traffic control and appliance control, where programs are small and compact, assembly language is suitable. Similarly, in such real-time applications as converting a high-frequency waveform into digital data, program efficiency is critical. In real-time applications, events and time should closely match with each other without significant delay. Therefore, assembly lan­guage is highly desirable in these applications. On the other hand, for applications

MICROPROCESSOR INSTRUCTION SET AND COMPUTER LANGUAGES 21_03

FIGURE 7

Compiler

Object

Source Code

or

Interpreter

Code

Block Diagram: Translation of High-Level Language Program into Machine Code

MICROPROCESSOR ARCHITECTURE AND INTERFACING

in which programs are large and memory is not a limitation, high-level languages

may be desirable. The advantage of time saved in debugging a large program may outweigh the disadvantages of large memory requirements and inefficiency.

Leave a comment

Your email address will not be published. Required fields are marked *