Higher level and lower level languages: Difference between revisions
Mr. MacKenty (talk | contribs) |
Mr. MacKenty (talk | contribs) No edit summary |
||
Line 45: | Line 45: | ||
* '''Bytecode:''' A low-level binary representation of code that can be run by other applications. | * '''Bytecode:''' A low-level binary representation of code that can be run by other applications. | ||
* '''Machine code:''' A binary representation of code that can be run directly by hardware. | * '''Machine code:''' A binary representation of code that can be run directly by hardware. | ||
== High-Level Language: Python == | |||
<syntaxhighlight lang="python"> | |||
# Python code to add two numbers | |||
def add_numbers(a, b): | |||
return a + b | |||
result = add_numbers(5, 3) | |||
print(result) | |||
</syntaxhighlight> | |||
== Lower-Level Language: Assembly (x86 Assembly) == | |||
<syntaxhighlight lang="asm"> | |||
section .data | |||
result dd 0 ; Reserve space for the result (4 bytes) | |||
section .text | |||
global _start ; Entry point for the program | |||
_start: | |||
; Load the values 5 and 3 into registers | |||
mov eax, 5 ; Load 5 into register eax | |||
mov ebx, 3 ; Load 3 into register ebx | |||
; Perform the addition | |||
add eax, ebx ; eax = eax + ebx (5 + 3) | |||
; Store the result in the result variable | |||
mov [result], eax ; Move the value in eax (8) to result | |||
; Exit the program | |||
mov eax, 1 ; System call number (sys_exit) | |||
int 0x80 ; Call kernel to exit | |||
</syntaxhighlight> | |||
== Explanation == | |||
* '''Python Code:''' | |||
** In Python, the function `add_numbers` takes two arguments, `a` and `b`, and returns their sum. | |||
** The function is then called with the values `5` and `3`, and the result is printed. | |||
* '''Assembly Code:''' | |||
** The assembly code defines a data section to reserve space for storing the result. | |||
** The text section contains the code to execute the program. | |||
** `mov` instructions load the values `5` and `3` into registers `eax` and `ebx`. | |||
** The `add` instruction performs the addition, storing the result back into `eax`. | |||
** Finally, the result is stored in memory, and the program exits with a system call. | |||
== Standards == | == Standards == |
Latest revision as of 05:36, 22 August 2024
Higher level language[edit]
A high-level language (HLL) is a programming language such as C, FORTRAN, or Pascal that enables a programmer to write programs that are more or less independent of a particular type of computer. Such languages are considered high-level because they are closer to human languages and further from machine languages.[2]
In computer science, a high-level programming language is a programming language with strong abstraction from the details of the computer. In contrast to low-level programming languages, it may use natural language elements, be easier to use, or may automate (or even hide entirely) significant areas of computing systems (e.g. memory management), making the process of developing a program simpler and more understandable than when using a lower-level language. The amount of abstraction provided defines how "high-level" a programming language is.[3]
List of some popular higher-level languages[edit]
- Python
- Java
- JavaScript
- C++
- C#
- Ruby
- Perl
- PHP
- GO
- Rust
Low level language[edit]
A low-level language is a programming language that provides little or no abstraction of programming concepts and is very close to writing actual machine instructions. Two examples of low-level languages are assembly and machine code.[4]
A low-level programming language is a programming language that provides little or no abstraction from a computer's instruction set architecture—commands or functions in the language map closely to processor instructions. Generally, this refers to either machine code or assembly language. The word "low" refers to the small or nonexistent amount of abstraction between the language and machine language; because of this, low-level languages are sometimes described as being "close to the hardware". Programs written in low-level languages tend to be relatively non-portable.[5]
List of some low-level languages[edit]
- assembly language
- machine language
Video to help you understand[edit]
Levels of programming languages[edit]
I used this glossary from an auth0 article on web assembly[6]
- Source code: What a developer writes.
- Compiler: An application that turns source code into assembly, bytecode or machine code (what other apps or hardware run).
- Assembly: A low-level source-like language specific to a machine or an application.
- Bytecode: A low-level binary representation of code that can be run by other applications.
- Machine code: A binary representation of code that can be run directly by hardware.
High-Level Language: Python[edit]
# Python code to add two numbers
def add_numbers(a, b):
return a + b
result = add_numbers(5, 3)
print(result)
Lower-Level Language: Assembly (x86 Assembly)[edit]
section .data
result dd 0 ; Reserve space for the result (4 bytes)
section .text
global _start ; Entry point for the program
_start:
; Load the values 5 and 3 into registers
mov eax, 5 ; Load 5 into register eax
mov ebx, 3 ; Load 3 into register ebx
; Perform the addition
add eax, ebx ; eax = eax + ebx (5 + 3)
; Store the result in the result variable
mov [result], eax ; Move the value in eax (8) to result
; Exit the program
mov eax, 1 ; System call number (sys_exit)
int 0x80 ; Call kernel to exit
Explanation[edit]
- Python Code:
- In Python, the function `add_numbers` takes two arguments, `a` and `b`, and returns their sum.
- The function is then called with the values `5` and `3`, and the result is printed.
- Assembly Code:
- The assembly code defines a data section to reserve space for storing the result.
- The text section contains the code to execute the program.
- `mov` instructions load the values `5` and `3` into registers `eax` and `ebx`.
- The `add` instruction performs the addition, storing the result back into `eax`.
- Finally, the result is stored in memory, and the program exits with a system call.
Standards[edit]
- Explain the need for higher level languages.
- Outline the need for a translation process from a higher level language to machine executable code.
References[edit]
- ↑ http://www.flaticon.com/
- ↑ https://www.webopedia.com/TERM/H/high_level_language.html
- ↑ https://en.wikipedia.org/wiki/High-level_programming_language
- ↑ https://www.computerhope.com/jargon/l/lowlangu.htm
- ↑ https://en.wikipedia.org/wiki/Low-level_programming_language
- ↑ https://auth0.com/blog/7-things-you-should-know-about-web-assembly/