HOME

TheInfoList



OR:

A low-level programming language is a
programming language A programming language is a system of notation for writing computer programs. Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
that provides little or no
abstraction Abstraction is a process where general rules and concepts are derived from the use and classifying of specific examples, literal (reality, real or Abstract and concrete, concrete) signifiers, first principles, or other methods. "An abstraction" ...
from a computer's
instruction set architecture In computer science, an instruction set architecture (ISA) is an abstract model that generally defines how software controls the CPU in a computer or a family of computers. A device or program that executes instructions described by that ISA, ...
, memory or underlying physical hardware; commands or functions in the language are structurally similar to a processor's instructions. These languages provide the programmer with full control over program memory and the underlying machine code instructions. Because of the low level of abstraction (hence the term "low-level") between the language and machine language, low-level languages are sometimes described as being "close to the hardware". Programs written in low-level languages tend to be relatively non-portable, due to being optimized for a certain type of system architecture. Low-level languages are directly converted to machine code with or without a
compiler In computing, a compiler is a computer program that Translator (computing), translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primaril ...
or interpretersecond-generation programming languages depending on programming language. A program written in a low-level language can be made to run very quickly, with a small
memory footprint Memory footprint refers to the amount of main memory that a program uses or references while running. The word footprint generally refers to the extent of physical dimensions that an object occupies, giving a sense of its size. In computing, t ...
. Such programs may be architecture dependent or operating system dependent, due to using low level
API An application programming interface (API) is a connection between computers or between computer programs. It is a type of software interface, offering a service to other pieces of software. A document or standard that describes how to build ...
s.


Machine code

''Machine code'' is the form in which code that can be directly executed is stored on a computer. It consists of machine language instructions, stored in memory, that perform operations such as moving values in and out of memory locations, arithmetic and Boolean logic, and testing values and, based on the test, either executing the next instruction in memory or executing an instruction at another location. Machine code is usually stored in memory as binary data. Programmers almost never write programs directly in machine code; instead, they write code in
assembly language In computing, assembly language (alternatively assembler language or symbolic machine code), often referred to simply as assembly and commonly abbreviated as ASM or asm, is any low-level programming language with a very strong correspondence bet ...
or higher-level programming languages. Although few programs are written in machine languages, programmers often become adept at reading it through working with
core dump In computing, a core dump, memory dump, crash dump, storage dump, system dump, or ABEND dump consists of the recorded state of the working Computer storage, memory of a computer program at a specific time, generally when the program has crash (com ...
s or debugging from the front panel. Example of a function in hexadecimal representation of
x86-64 x86-64 (also known as x64, x86_64, AMD64, and Intel 64) is a 64-bit extension of the x86 instruction set architecture, instruction set. It was announced in 1999 and first available in the AMD Opteron family in 2003. It introduces two new ope ...
machine code to calculate the ''n''th
Fibonacci number In mathematics, the Fibonacci sequence is a Integer sequence, sequence in which each element is the sum of the two elements that precede it. Numbers that are part of the Fibonacci sequence are known as Fibonacci numbers, commonly denoted . Many w ...
, with each line corresponding to one instruction:
89 f8
85 ff
74 26
83 ff 02
76 1c
89 f9
ba 01 00 00 00
be 01 00 00 00
8d 04 16
83 f9 02
74 0d
89 d6
ff c9
89 c2
eb f0
b8 01 00 00
c3


Assembly language

Second-generation languages provide one abstraction level on top of the machine code. In the early days of coding on computers like TX-0 and PDP-1, the first thing MIT hackers did were write assemblers. Assembly language has little
semantics Semantics is the study of linguistic Meaning (philosophy), meaning. It examines what meaning is, how words get their meaning, and how the meaning of a complex expression depends on its parts. Part of this process involves the distinction betwee ...
or formal specification, being only a mapping of human-readable symbols, including symbolic addresses, to
opcode In computing, an opcode (abbreviated from operation code) is an enumerated value that specifies the operation to be performed. Opcodes are employed in hardware devices such as arithmetic logic units (ALUs), central processing units (CPUs), and ...
s, addresses, numeric constants, strings and so on. Typically, one machine instruction is represented as one line of assembly code, commonly called a ''mnemonic''. Assemblers produce
object file An object file is a file that contains machine code or bytecode, as well as other data and metadata, generated by a compiler or assembler from source code during the compilation or assembly process. The machine code that is generated is kno ...
s that can link with other object files or be loaded on their own. Most assemblers provide macros to generate common sequences of instructions. Example: The same
Fibonacci number In mathematics, the Fibonacci sequence is a Integer sequence, sequence in which each element is the sum of the two elements that precede it. Numbers that are part of the Fibonacci sequence are known as Fibonacci numbers, commonly denoted . Many w ...
calculator as above, but in x86-64 assembly language using Intel syntax: fib: mov rax, rdi ; The argument is stored in rdi, put it into rax test rdi, rdi ; Is the argument zero? je .return_from_fib ; Yes - return 0, which is already in rax cmp rdi, 2 ; No - compare the argument to 2 jbe .return_1_from_fib ; If it is less than or equal to 2, return 1 mov rcx, rdi ; Otherwise, put it in rcx, for use as a counter mov rdx, 1 ; The first previous number starts out as 1, put it in rdx mov rsi, 1 ; The second previous number also starts out as 1, put it in rsi .fib_loop: lea rax, si + rdx ; Put the sum of the previous two numbers into rax cmp rcx, 2 ; Is the counter 2? je .return_from_fib ; Yes - rax contains the result mov rsi, rdx ; No - make the first previous number the second previous number dec rcx ; Decrement the counter mov rdx, rax ; Make the current number the first previous number jmp .fib_loop ; Keep going .return_1_from_fib: mov rax, 1 ; Set the return value to 1 .return_from_fib: ret ; Return In this code example, the registers of the x86-64 processor are named and manipulated directly. The function loads its 64-bit argument from in accordance to the System V application binary interface for x86-64 and performs its calculation by manipulating values in the , , , and registers until it has finished and returns. Note that in this assembly language, there is no concept of returning a value. The result having been stored in the register, again in accordance with System V application binary interface, the instruction simply removes the top 64-bit element on the stack and causes the next instruction to be fetched from that location (that instruction is usually the instruction immediately after the one that called this function), with the result of the function being stored in . x86-64 assembly language imposes no standard for passing values to a function or returning values from a function (and in fact, has no concept of a function); those are defined by an
application binary interface An application binary interface (ABI) is an interface exposed by software that is defined for in-process machine code access. Often, the exposing software is a library, and the consumer is a program. An ABI is at a relatively low-level of a ...
(ABI), such as the System V ABI for a particular instruction set. Compare this with the same function in C: unsigned int fib(unsigned int n) This code is similar in structure to the assembly language example but there are significant differences in terms of abstraction: * The input (parameter ) is an abstraction that does not specify any storage location on the hardware. In practice, the C compiler follows one of many possible calling conventions to determine a storage location for the input. * The local variables , , and are abstractions that do not specify any specific storage location on the hardware. The C compiler decides how to actually store them for the target architecture. * The return function specifies the value to return, but does not dictate ''how'' it is returned. The C compiler for any specific architecture implements a standard mechanism for returning the value. Compilers for the x86-64 architecture typically (but not always) use the register to return a value, as in the assembly language example (the author of the assembly language example has ''chosen'' to use the System V application binary interface for x86-64 convention but assembly language does not require this). These abstractions make the C code compilable without modification on any architecture for which a C compiler has been written, whereas the assembly language code above will only run on processors using the x86-64 architecture.


C programming language

C has variously been described as low-level and high-level. Traditionally considered high-level, C’s level of abstraction from the hardware is far lower than many subsequently developed languages, particularly interpreted languages. The direct interface C provides between the programmer and hardware memory allocation and management make C the lowest-level language of the 10 most popular languages currently in use. C is architecture independent — the same C code may, in most cases, be compiled (by different machine-specific compilers) for use on a wide breadth of machine platforms. In many respects (including directory operations and memory allocation), C provides “an interface to system-dependent objects that is itself relatively system independent”. This feature is considered “high-level” in comparison of platform-specific assembly languages.


Low-level programming in high-level languages

During the late 1960s and 1970s, high-level languages that included some degree of access to low-level programming functions, such as PL/S, BLISS, BCPL, extended
ALGOL ALGOL (; short for "Algorithmic Language") is a family of imperative computer programming languages originally developed in 1958. ALGOL heavily influenced many other languages and was the standard method for algorithm description used by the ...
and NEWP (for Burroughs large systems/Unisys Clearpath MCP systems), and C, were introduced. One method for this is inline assembly, in which assembly code is embedded in a high-level language that supports this feature. Some of these languages also allow architecture-dependent compiler optimization directives to adjust the way a compiler uses the target processor architecture. Furthermore, as referenced above, the following block of C is from the GNU Compiler and shows the inline assembly ability of C. Per the GCC documentation this is a simple copy and addition code. This code displays the interaction between a generally high level language like C and its middle/low level counter part Assembly. Although this may not make C a natively low level language these facilities express the interactions in a more direct way. int src = 1; int dst; asm ("mov %1, %0\n\t" "add $1, %0" : "=r" (dst) : "r" (src)); printf("%d\n", dst);


References


Bibliography

* {{Authority control Programming language classification Articles with example C code