Why must programs written in a high-level language be translated into machine language

CPSC 124, Winter 1998


This is the first quiz given in CPSC 124: Introductory Programming, Winter 1998. See the information page for that course for more information.

The answers given here are sample answers that would receive full credit. However, they are not necessarily the only correct answers.


Question 1: One of the components of a computer is its CPU. What is a CPU and what role does it play in a computer?

Answer: The CPU, or Central Processing Unit, is the active part of the computer. Its function is to execute programs that are coded in machine language and stored in the main memory (RAM) of the computer. It does this by repeating the fetch-and-execute cycle over and over; that is, it repeatedly fetches a machine language instruction from memory and executes it.


Question 2: A program that is written in the Java programming language must be compiled before it can be executed. Why is this true? What does the compiler do with the Java program?

Answer: A computer can only directly execute a program if it is expressed in the machine language of that particular type of computer. Programs written in a high-level language must be translated into machine language before they can be executed. A compiler is a program that takes a high-level language program and translates it into an equivalent machine language program. Java is a bit unusual in that a Java compiler translates programs written in Java into "Java bytecode", which is not the machine language for any existing computer. A computer that needs to execute a Java bytecode program uses an interpreter to execute the program.


Question 3: Explain what is meant by an asynchronous event. Give some examples.

Answer: An asynchronous event is one that occurs at an unpredictable time, outside the control of the computer. An ordinary program that just proceeds step-by-step cannot easily deal with such events, so they are handled in a special way. When an asynchronous event occurs, the program that is being executed is interrupted while the computer responds to the event. Examples of asynchronous events are when the user presses a key on the keyboard, when the user moves the mouse, or when data arrives over a network connection.


Question 4: What is a variable? (There are four different aspects associated with variables in Java. Try to mention all four aspects in your answer. Hint: One of the aspects is the variable's name.)

Answer: A variable is a memory location that has been given a name so that it can easily be referred to in a program. The variable holds a value, which must be of some specified type. The value can be changed during the course of the execution of the program.


Question 5: What is HTML? What is it used for?

Answer: HTML, or HyperText Markup Language, is a language that is used to create Web pages. An .html file contains a description of the contents of a Web page, written in HTML. When you click on a link in Netscape, your computer downloads an .html file, and it displays the page that is described in the .html file.


David Eck, 15 January 1998

Depending on the task to be performed, computer programs can be written in high-level languages or low-level languages.  Most programmers write programs in high-level languages such as Java, Python, Visual Basic and many more.

High-level languages are portable and can be used on different types of computers.  They use English and mathematical symbols in its instructions, therefore requiring no knowledge of the computer hardware and enabling the programmer to focus on the problem to be solved.  High-level languages have several advantages insofar as they are easier to:

– read and understand

– write in a shorter time

– debug at the development stage

Low-level languages relate to the specific hardware of a particular type of computer.  They can refer to machine code, the binary instructions that a computer understands, or an assembly language that needs to be translated into machine code.  Few programmers write code in a low-level language because it is difficult to understand, but those who do, do so for the following reasons:

– to make use of special hardware

– to write code that does not take up much space

– to write code that performs a task quickly.

Low-level languages come in two categories:

– Machine Language – language that is directly understood by the computer (binary notation , 0s and 1s), and it does not need to be translated.

– Assembly Language – the first step to make machine language more readable by humans.  An assembly language consists of a set of symbols and letters.  It can be called the second generation language because it no longer uses 1s and 0s to write instructions, but terms like MOVE, ADD, SUM and END.  Many of the early computer programs were written in assembly languages, but they are still used for Operating Systems and electronic devices, which use very precise timing and operation of computer resources.  While easier to understand than machine language, assembly languages are still quite difficult to understand, which is why high-level languages have been developed.

Any high-level language program though, must be translated into binary before a computer can use it.  This process is done by a utility program called a translator.  There are several types of translator, each one performing a different task:

A compiler is a computer program that translates a program written in a high-level language to the machine level language of a computer.  Everything is translated and compiled once by the compiler, and then can be used many times afterwards.  One of the advantages therefore, of using a compiler, is that compiled code tends to be faster because it has all been executed in one step prior to its execution, and the source code (the high level language originally used) is hidden.

Why must programs written in a high-level language be translated into machine language

An interpreter on the other hand, interprets and translates a program written in high-level language to low-level language line by line.

Why must programs written in a high-level language be translated into machine language

An assembler translates a program written in a low-level language (assembly language) into machine code so that it can be directly used by a computer to perform a required task.  Once a program is assembled the machine code can be used again and again to perform the same task without re-assembly.

Why does a high

Just like low-level languages, high-level languages must be converted to machine code before a computer can understand and run them. This is done using a 'translator' Different translators convert the same high level code into machine code for different computers.

Why must a program written in a higher level language be either translated into machine language byte code or interpreted in order to be executed?

The program (source code) must be translated into machine language so that the computer can execute the program (as the computer only understands machine language).

Why do you need to translate a program written in a high

Answer: High-level language programs must be translated into machine language before they can be executed. (Machine language instructions are encoded as binary numbers that are meant to be used by a machine, not read or written by people. High-level languages use a syntax that is closer to human language.)

Why does a high

Because machine code instructions are the only ones the CPU can execute, the source code for ALL other programming languages must be converted into machine code before it can be executed. This translation is carried out by special programs called compilers, translators or assemblers.