0% found this document useful (0 votes)
12 views

Unit 4 ( Programming Languae and Logic)

The document explains the differences between high-level and low-level programming languages, highlighting their respective advantages and disadvantages. High-level languages are user-friendly and portable, while low-level languages provide more control over hardware but are harder to understand. It also discusses the role of translators like compilers and interpreters in converting high-level code to machine code, and introduces Integrated Development Environments (IDEs) that assist programmers in development.

Uploaded by

winhtikeaung43
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Unit 4 ( Programming Languae and Logic)

The document explains the differences between high-level and low-level programming languages, highlighting their respective advantages and disadvantages. High-level languages are user-friendly and portable, while low-level languages provide more control over hardware but are harder to understand. It also discusses the role of translators like compilers and interpreters in converting high-level code to machine code, and introduces Integrated Development Environments (IDEs) that assist programmers in development.

Uploaded by

winhtikeaung43
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

High-level and low-level languages

What is Program.
Program
 is a set of instruction that tell computer what to do and how
to do a specific task.
 enables a single computer to perform many different types
of task.

Programming Languages
 A set of words and symbols used to write a program
 is a computer language that is used by programmers
(developers) to communicate with computers.
 High Level Languages
 Low Level Languages
High Level Language
 are written in a form that is close to our human(natural) language, enabling to
programmer to just focus on the problem being solved.
 require no knowledge of the hardware and instruction set of the computer that will
use the program.
 are portable and can be used on different types of computer
 Examples include: C++, Java, Pascal, Python, Visual Basic.

Sum := FirstNumber + SecondNumber

Advantages
❑ Closer to English Language/ human Language so that
easier to read/ write/ understand
❑ Easier to debug
❑ Less likely to make errors
❑ One lines of code can carry out multiple command
❑ Portable language
Low level Language
 are used to write programs that relate to the specific architecture and hardware of
a particular type of computer.
 are closer to the native language of a computer (binary) making them harder for
programmers to understand.
 Examples of low level language:
 Assembly Language
 Machine Code
Assembly Language
 Few programmers write programs in an assembly language.
 is easy distinguishable from a high level language as it
contains few recognizable human words but plenty mnemonic
code 4 First

Acc
LDA First
ADD Second 4 9 5 Second
STO Sum

9 Sum
LDA means load the value of the variable into the accumulator
ADD means add the value of another variable to the value stored in the accumulator
STO means replace the value of the variable by the value stored in the accumulator.
Assembly Language
Advantages
 Can make use of special hardware or special machine-dependent instructions (e.g.
on the specific chip)
 Translated program requires less memory
 Write code that can be executed faster
 Total control over the code
 Can work directly on memory locations

Limitation
 A very limited range of instructions is available
 Debugging is very difficult
Machine Code
 Programmers rarely write in machine code (binary) as it is difficult to understand
and it can be complicated to manage data manipulation and storage.
Advantages Disadvantages
High Level Independent of the type of computer Programs can be larger
Language being used (portable) Programs can take longer to
Easier to read, write and understand execute
programs Programs may not be able to use of
Quicker to write program special hardware
Programs are easier and quicker to
debug
Easier to maintain program in use
Low Level Can make use of special hardware It takes a longer time to write and
Language Includes special machine-independent debug programs
instructions Programs are more difficult to
Can write code that doesn’t take up understand
much space in primary memory
Can write code that performs a task
very quickly
Translators
Why translator is needed?
 The computer can only understand machine code low-level language
 But programmer used to write program in high level language.
 Thus, program (source code) need to be translated into machine code using
translator.
What is translator?
 Translator is a software that convert the source code into machine code (object
code).
 There are three type of translator
 Compiler
 Interpreter
 Assembler
Compilers
 is a program that translates high level language program (source code) into machine code, often
object code and saved as executable file to be executed later
 Translates (the source code) all in one go/all at once and produce an executable file of machine
code.
 Once compiled ,machine code can then be directly used by the computer.
 Compiled programs are used without the compiler.
 Error report produced once entire program is compiled. (error may cause program to crash)
 One high-level language statement may be several lines of machine code when compiled.

Error report

Object code (.exe file)


Source code Compiler
00100000
Sum = 1+2 10000100
Sum = 1# 2 11110000
Advantages and Disadvantages of
Compiler
Advantages Disadvantages
 The compiled program will run without  The source code must be re-compiled
compiler. To run it, the compiler don’t every time the programmer changes the
need to install on user’s computer. program.
 Compiled programs run quickly, since
they have already been translated.  Debugging a compiled program is
relatively difficult as all the errors found
 Compilers optimize code. Optimized are reported together.
code can run quicker and take up less
memory space.  It take longer time to test and debug
during development
 an executable file cannot be easily
modified which makes secure and
privacy.
Interpreter
 Is a program that translate a high-level language program into object code ,often
machine code and execute one statement(lines) at a time from.
 Translates (the source code) line by line/statement by statement
 No executable file of machine code is produced.
 Interpreted programs cannot be used without the interpreter.
 Error message produced immediately (and program stops at that point)
 One high-level language statement may be several lines of machine code
when compiled.

result 3
Source code Intepreter
Error report
Sum = 1+2
00100000
run
Sum = 1# 2 10000100
11110000
Advantages and Disadvantages of Interpreter

Advantages Disadvantages
 Easier and quicker to debug and test  Interpreted programs cannot be used
programs during development. without the interpreter.

 Errors can be quickly spotted - once an  Interpreted programs run slowly as the
error is found, the program stops running processor has to wait for each instruction
and the programmer is notified at which to be translated before it can be executed.
part of the program has failed.  Interpreters do not produce an executable
 Interpreter is easier to use, especially for file that can be distributed. As a result, the
beginner. source code program has to be supplied,
and this could be modified without
permission.
 Interpreters do not optimize code - the
translated code is executed as it is.
Assembler
 are used to translate a program written in assembly language into a machine code
(object code) file.
 An executable file of machine code is produced.
 Assembled programs can be used without the assembler.
 One low-level language statement is usually translated into one machine code
instruction.
 An assembled programs are used without assembler.
 An assembled program is usually distributed for general use.
(b) Write down the other three of the functions of a typical operating system
1 …………………………………………………………………………
 2 …………………………………………………………………………
 3 …………………………………………………………………… [3]
2.The programmer uses the high-level language or low-level language to write a program.
(a) State three benefits of writing a program in a high-level programming languages.
[3]
1 ………………………………………………………………………
2 …………………………………………………………………………
3 ……………………………………………………………………………
(b) Explain why a programmer would not choose to write a program in a low-level programming language.
[2]
……………………………………………………………………………
……………………………………………………………………………
The compilers and interpreters are types of translators.
Tick (√) to show which statements apply to each translator. [5]

Statement Compilers Interpreters


Translate high level language one line at time
Produce executable file
Report all error messages together
Optimize the source code
Once the source program is translated, the
translated will not run without the translator
Integrated Development Environment (IDE)
 An Integrated Development Environment (IDE) is used by programmers to aid the writing and
development of programs.
 There are many different IDEs available; some just support one programming language,
others can be used for several different programming languages.
 Example : PyCharm (for Python), Visual Studio (for Visual Basic) or eclipse (for Java).
 IDEs usually have these features:
 code editors
 a translator
 a runtime environment with a debugger
 error diagnostics and auto correction
 auto-completion
 an auto-documenter and prettyprinting.
Integrated Development Environment (IDE)
 Code editor : allows a program to be written and edited without the need to use a
separate text editor.
 Translator : provide a translator ( compiler or interpreter) to enable the program to
be executed
 A runtime environment with debugger : a program that runs the program under
development and allows the programmer to step through the program a line at time
 Error diagnostics and auto-correction :finds possible errors as the program code is
being typed, alerts the programmer at the time and provides a suggested
correction
 Auto completion : Code editors can offer context-sensitive prompts with text
completion for variable names and reserved words.
 Auto-documenter and prettyprinting: IDEs can provide an auto-documenter to
explain the function and purpose of programming code.
Logic
 Algorithm and programs are based on logic.
 There are some logic statement such as (IF…THEN) and operators such as AND,
OR and NOT.
 The truth table are used to evaluate the expected output of logic from different
inputs.

Input Working space Output

A B C A AND B P

0 0 0 0 0
0 0 1 0 1
0 1 0 0 0
0 1 1 0 1
1 0 0 0 0
1 0 1 0 1
1 1 0 1 1
1 1 1 1 1
Logic
 Algorithm and programs are based on logic.
 There are some logic statement such as (IF…THEN) and operators such as AND,
OR and NOT.
 The truth table are used to evaluate the expected output of logic from different
inputs.

Input Working space Output


P = ( A AND B ) OR C A B C A AND B P

0 0 0 0 0
0 0 1 0 1
True = 1 0 1 0 0 0
False = 0
0 1 1 0 1
1 0 0 0 0
1 0 1 0 1
1 1 0 1 1
1 1 1 1 1
Logic

game _over = (h<=0 OR s> 1000)

Input Output

h<=0 S> 1000 game_over

0 0 0
0 1 1
1 0 1
1 1 1
Logic
IF ( NOT g_mode AND h <=0) OR s > 1000 THEN
SET game_over to true
game _over = 1 if ( NOT g_mode AND h <=0) OR s > 1000
game _over = ( NOT g_mode AND h <=0) OR s > 1000

Input Working space Output

G_mode H <=0 S>1000 NOT NOT g_mode AND h game_over


g_mode <=0
0 0 0 1 0 0
0 0 1 1 0 1
0 1 0 1 1
1
0 1 1 1 1
1
1 0 0 0 0 0
0 1 0 0 1
1
1 1 0 0 0 0
1 1 1 0 0 1
1,1,0,0,1,1,0,1
(B AND S AND (NOT L))
(T OR S) AND L
Exercise
 Look at the statement below and write the truth table.
IF year =11 AND ( grade < target OR target > 7 ) THEN
SET revision_ class To true
High Level Language Low Level Language
Rich set of instructions for sequencing, selection, Limited instructions set
repetition, and iteration. supplemented by a library of
ready-made functions
Support many different data types, such as string, There are no data types, such as string and
integer, and Boolean integer.
One line of high-level language generates several one line of low-level code maps directly to one
executable instructions. execution instruction.
There are usually several different editors available There may be a limited set of tools available for
which incorporate syntax checkers. syntax checking.
Translation is required by all HLLs Assembly language requires an assembler and
machine code does not require translation at
all.
programmers don't have to know the details of a Programmers have to know the details of a
specific machine architecture to write code in a HLL specific machine architecture to write code in a
LLL.
HLL uses English-like command words and is Mnemonics; or binary code is harder for a
therefore easier for a novice programmer to novice programmer to read/write/understand.
read/write/understand
HLLs require more memory space. LLLs require less memory space.

You might also like