lecture 2 high level vs low level languages

5

Click here to load reader

Upload: api-3739389

Post on 11-Apr-2015

12.503 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Lecture 2 High Level vs Low Level Languages

Prepared by: Khurram Tanvir 1 CS203 HO#2

Kingdom of Saudi Arabia د�����ا ��� ا����� ا�Royal Commission at Yanbu ���� �����ا ����ا University College – Yanbu ������ا ����ا-���� Department of ACS & AIT Yanbu Al-Sinaiyah

���� ا������

2ND Semester 2007-08

CS-203 HANDOUT 2

HIGH LEVEL VS LOW LEVEL LANGUAGES

1. Programming Languages

Languages are used to communicate between different entities. Computer language makes it possible to talk to the computers and ask the computer to perform specific work. Computer language produces programs which are executed by CPU, and then CPU instructs all the other parts of computers to perform work accordingly. Computers only understand programs in their own machine language. Machine language is the language of 0’s and 1’s. It is difficult to write program in machine language so what is the solution to this dilemma? The answer is in what are called high-level languages i.e. Computer programming languages that look like natural language.

2. High-Level Languages (HLL)

HLLs are programming languages that look like natural language text. Their advantages are:

1. They make programming easier and more abstract, i.e. the programmer does not need to come up with the detailed machine instructions

2. HLL programs are machine independent. They can run on different hardware platforms (i.e. different computers with different instruction sets):

To run a HLL program on a specific machine, it has to be translated to its machine language. This is done through the use of a compiler. A Compiler is a program that translates a HLL program to a machine language program of a specific platform. The Machine language program produced by the compiler is usually referred to as the executable program. Hence by using the appropriate compiler we can execute our HLL programs on any platform.

Page 2: Lecture 2 High Level vs Low Level Languages

Prepared by: Khurram Tanvir 2 CS203 HO#2

2.1 Mapping Between HLL and Machine Language

Translating HLL programs to machine language programs is not a one-to-one mapping. A HLL instruction (usually called a statement) will be translated to one or more machine language instructions. The number of mapped machine instructions depends on the efficiency of the compiler in producing optimized machine language programs from the HLL programs. A machine language program produced by a compiler or an assembler. Usually, machine language programs produced by compilers are not efficient (i.e. they contain many unnecessary instructions that increase processing and slow down execution).

3. Assembly language

Assembly language is the most basic programming language available for any processor. With assembly language, a programmer works only with operations implemented directly on the physical CPU. Assembly language lacks high-level conveniences such as variables and functions, and it is not portable between various families of processors. Nevertheless, assembly language is the most powerful computer programming language available, and it gives programmers the insight required to write effective code in high-level languages.

Machine code for displaying $ sign on lower right corner of screen.

10111000, 00000000, 10111000, 10001110, 11011000, 11000110, 00000110, 10011110, 00001111, 00100100, 11001101, 00011111

The program above, written in assembly language, looks like this:

MOV AX, 47104 MOV DS, AX MOV [3998], 36 INT 32

Page 3: Lecture 2 High Level vs Low Level Languages

Prepared by: Khurram Tanvir 3 CS203 HO#2

When an assembler reads this sample program, it converts each line of code into one CPU-level instruction.

3.1 Advantages of learning Assembly language

1. Very useful for making efficient and fast running programs. 2. Very useful for making small programs for embedded system applications. 3. Easy to access hardware in assembly language 4. Writing compact code.

4. The Compiler

Compiler is a program that translates the high level programs to machine code either directly or via assembler.

Page 4: Lecture 2 High Level vs Low Level Languages

Prepared by: Khurram Tanvir 4 CS203 HO#2

5. The Assembler

The program that translates from assembly language to machine language is called an assembler. It allows the programmer to specify the memory locations for his data and programs and symbolically refer to them in his assembly code. It will translate these symbolic addresses to actual (physical) addresses in the produced machine code.

6. The Linker

This is the program that is used to link together separately assembled/compiled programs into a single executable code. The linker program is used to create executable

code which finally runs on the CPU.

7. Debugger and Monitor

These are the tools that allow the assembly programmers to:

1. Display and alter the contents of memory and registers while running their code. 2. Perform disassembly of their machine code (show the assembly language

equivalent). 3. Permit them to run their programs, stop (or halt) them, run them step-by-step or

insert break points. Break points: Positions in the program that if are encountered during run time, the program will be halted so the programmer can examine the memory and registers contents and determine what went wrong.

Page 5: Lecture 2 High Level vs Low Level Languages

Prepared by: Khurram Tanvir 5 CS203 HO#2

Example Test Questions

Fill in the blanks

1. High level language program has to be converted to ____________ language before execution.

2. ___________program is used to inspect and monitor the program minutely by stepping through the code.

Specify True or False

1. High level level languages are more close to the hardware (True/False) 2. Assembler is used to assemble the assembly language programs (True/False)

Choose the best answer.

The compiler is used to compile

a. High level language b. Assembly language c. Machine Language d. None of above

The linker is used to

a. Link a .obj file to other files b. Convert .obj file to .exe file c. Convert the high level language into machine language d. None of above

Question: Mention the advantages of assembly language.