Programming Language LevelsAs you saw in the previous section, the programming languages used with modern computers are divided into three levels:
High-Level LanguagesAs computer scientists and computer programmers, we prefer to use high-level languages like Python, C, or Java because they are easier to use. For example, suppose we want to evaluate the mathematical expression y = x × a + x × b Most high-level languages provide a simple way to write this expression using familiar notation. In Python or C, we might implement this expression as follows: y = x * z + x * b; Programs written in a high-level language are machine independent. That is, they can be used on different architectures without having to rewrite the program. A programmer can write the program without having to know or depend on the instructions of the given processor. In order to use these programs, however, we must use a compiler or an interpreter to translate the high-level language instructions into assembly language and then into machine code. Typically, this involves taking a single high-level language instruction and translating it into multiple assembly language instructions. A program written in a high-level programming language can not be executed directly by a computer processor. Some languages like C, C++, and Fortran are translated into machine code and executed directly on the computer. Other languages like Python and Java are translated into byte-code (a generic machine code) that is "executed" by a virtual machine on the actual computer. The virtual machine is simply a program written in a high-level language that has been compiled for a given processor. Although the source programs are machine independent, the executable virtual machine is dependent on a specific processor. Assembly LanguageAssembly language is a rudimentary programming language machine dependent or specific to each particular type of architecture. It provides a symbolic representation for the machine code of the processor. Typically, a single high-level language statement will result in multiple assembly language instructions. For example, the statement evaluating the mathematical expression from the previous section may translate to the following assembly language instructions MUL S, X, A MUL T, X, B ADD Y, S, T The assembly language instructions consists of a one-to-one correlation between machine code instructions and assembly language instructions. Most assembly languages also provide pseudo instructions, which allows the assembly language to be expanded to incorporate groups of machine instructions in one assembly language command. The assembly language instructions must be translated into machine code using an assembler. Machine CodeA processor is designed for a specific instruction set architecture, which are specified as a sequence of binary digits. This means the processor understands a unique binary language, and no other. As an electronic device, a processor can only interpret two values, on and off, which are indicated as electrical signals. Humans normally notate these values as 1 and 0. Machine code instructions are the binary representation of assembly language instructions. These instructions, which are machine dependent, are "executed" by the digital circuits in the processor. The assembly language instructions for our mathematical expression may be represented in machine code as 1010011000111011 1010101000011011 1000110010100000 Executable programs are simply files that contain machine code in binary form for a specific architecture. When the program is executed, the processor reads the binary instructions, one at a time, interprets them and then carries out the task using its digital circuits. ExampleBelow is a complete example of a function written in the C programming language that is compiled into MIPS assembly language and then assembled into machine code for a MIPS processor. Question 1.
For each of the following languages or program types, indicate whether the language is machine dependent or machine independent.
Select the correct answer by clicking on the appropriate button.
|