Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Low-level programming language

From Wikipedia, the free encyclopedia
Programming language that provides little or no abstraction from underlying hardware
This article has multiple issues. Please helpimprove it or discuss these issues on thetalk page.(Learn how and when to remove these messages)
This articlepossibly containsoriginal research. Pleaseimprove it byverifying the claims made and addinginline citations. Statements consisting only of original research should be removed.(March 2017) (Learn how and when to remove this message)
This articleneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources. Unsourced material may be challenged and removed.
Find sources: "Low-level programming language" – news ·newspapers ·books ·scholar ·JSTOR
(July 2015) (Learn how and when to remove this message)
(Learn how and when to remove this message)

Alow-level programming language is aprogramming language that provides little or noabstraction from a computer'sinstruction set architecture, 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".

Machine code

[edit]
Front panel of aPDP-8/e minicomputer. The row of switches at the bottom can be used to toggle in machine code.

Machine code, classified as afirst-generation programming language,[1][2] isdataencoded and structured per theinstruction set architecture of aCPU. The instructions imply operations such as moving values in and out of memory locations, Boolean logic, arithmetic, comparing values, and flow control (branching and jumping).

Programmers almost never program directly in machine code; instead, they use anassembly language or a higher-level programming language.[3] Although few programs are written in machine languages, some programmers learn to read it through experience withcore dumps and debugging.

Assembly language

[edit]

Anassembly language, classified as asecond-generation programming language,[1][2] provides a level of abstraction on top of machine code. A program written in assembly language isnon-portable, due to being written and optimized for a particular architecture.[3][4][5][6]

Assembly language has littlesemantics or formal specification, being only a mapping of human-readable symbols, including symbolic addresses, toopcodes,addresses, numeric constants,strings and so on. Typically, onemachine instruction is represented as one line of assembly code, commonly called amnemonic.[7] Assemblers produceobject files that canlink with other object files or beloaded on their own. Most assemblers providemacros to generate common sequences of instructions.

In the early days of coding on computers likeTX-0 andPDP-1, the first thingMIThackers did was to write assemblers.[8]

C programming language

[edit]

TheC programming language, athird-generation programming language,[1][2] is sometimes classified as high or low depending on what one means by high vs. low level.[9] The syntax of C is inherently higher level than that of an assembly language since an assembly language is syntactically platform dependent whereas the C syntax is platform independent. C does support low-level programming – directly accessing computer hardware – but other languages, sometimes considered higher level than C, also can access hardware directly. With C, developers might need to handle relatively low-level aspects that other languages abstract (provide higher level support for) such as memory management and pointer arithmetic. But, C can encode abstractions that hide details such as hardware access, memory management and pointer arithmetic such that at least part of a Ccodebase might be as conceptually high-level as if constructed in any other language. Whether C is classified as high or low level language is contended, but it is higher level than assembly languages (especially syntactically) and is lower level than many other languages in some aspects.

Although C is not architecture independent, it can be used to write code that iscross-platform even though doing so can be technically challenging. An aspect of C that facilitates cross-platform development is theC standard library that provides “aninterface to system-dependent objects that is itself relatively system independent”.[10]

Comparison

[edit]

The following isx86-64 machine code for an algorithm to calculate thenthFibonacci number; with values inhexadecimal representation and each line corresponding to one instruction:

89 f885 ff74 2683 ff 0276 1c89 f9ba 01 00 00 00be 01 00 00 008d 04 1683 f9 0274 0d89 d6ff c989 c2eb f0b8 01 00 00c3

The following is the same algorithm written inx86-64 assembly language usingIntel syntax. Theregisters of the x86-64 processor are named and manipulated directly. The function loads its 64-bit argument fromrdi in accordance to theSystem V application binary interface for x86-64 and performs its calculation by manipulating values in therax,rcx,rsi, andrdi 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 therax register, again in accordance with System V application binary interface, theret instruction simply removes the top 64-bit element on thestack 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 inrax. 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 anapplication binary interface (ABI), such as the System V ABI for a particular instruction set.

fib:movrax,rdi; The argument is stored in rdi, put it into raxtestrdi,rdi; Is the argument zero?je.return_from_fib; Yes - return 0, which is already in raxcmprdi,2; No - compare the argument to 2jbe.return_1_from_fib; If it is less than or equal to 2, return 1movrcx,rdi; Otherwise, put it in rcx, for use as a countermovrdx,1; The first previous number starts out as 1, put it in rdxmovrsi,1; The second previous number also starts out as 1, put it in rsi.fib_loop:learax,[rsi+rdx]; Put the sum of the previous two numbers into raxcmprcx,2; Is the counter 2?je.return_from_fib; Yes - rax contains the resultmovrsi,rdx; No - make the first previous number the second previous numberdecrcx; Decrement the countermovrdx,rax; Make the current number the first previous numberjmp.fib_loop; Keep going.return_1_from_fib:movrax,1; Set the return value to 1.return_from_fib:ret; Return

The following is the same algorithm again, but in C. This is similar in structure to the assembly example but there are significant differences in abstraction:

  • The input (parametern) is an abstraction that does not specify any storage location on the hardware. In practice, the C compiler follows one of many possiblecalling conventions to determine a storage location for the input.
  • The local variablesf_nminus2,f_nminus1, andf_n 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 dictatehow it is returned. The C compiler for any specific architecture implements astandard mechanism for returning the value. Compilers for the x86-64 architecture typically (but not always) use therax register to return a value, as in the assembly language example (the author of the assembly language example haschosen 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 for any architecture that is supported by a C compiler; whereas the assembly code above only runs on processors using the x86-64 architecture.

unsignedintfib(unsignedintn){if(!n){return0;}elseif(n<=2){return1;}else{unsignedintf_nminus2,f_nminus1,f_n;for(f_nminus2=f_nminus1=1,f_n=0;;--n){f_n=f_nminus2+f_nminus1;if(n<=2){returnf_n;}f_nminus2=f_nminus1;f_nminus1=f_n;}}}

Low-level programming in high-level languages

[edit]

Somehigh-level languages, such asPL/S,BLISS,BCPL, extendedALGOL andNEWP, and C, can access lower-level programming languages. One method for doing this isinline assembly, in which assembly code is embedded in the high-level language code. Some of these languages also allow architecture-dependentcompiler optimization directives to adjust the way a compiler uses the target processor architecture.

The following block of C code from theGNU C Compiler (GCC) demonstrates its inline assembly feature.[11]

intsrc=1;intdst;asm("mov %1, %0\n\t""add $1, %0":"=r"(dst):"r"(src));printf("%d\n",dst);

References

[edit]
  1. ^abc"Generation of Programming Languages".GeeksforGeeks. 2017-10-22. Retrieved2024-04-27.
  2. ^abc"What is a Generation Languages?".www.computerhope.com. Retrieved2024-04-27.
  3. ^ab"3.1: Structure of low-level programs".Workforce LibreTexts. 2021-03-05. Retrieved2023-04-03.
  4. ^"What is a Low Level Language?".GeeksforGeeks. 2023-11-19. Retrieved2024-04-27.
  5. ^"Low Level Language? What You Need to Know | Lenovo US".www.lenovo.com. Archived fromthe original on 2024-07-24. Retrieved2024-04-27.
  6. ^"Low-level languages - Classifying programming languages and translators - AQA - GCSE Computer Science Revision - AQA".BBC Bitesize. Retrieved2024-04-27.
  7. ^"Machine Language/Assembly Language/High Level Language".www.cs.mtsu.edu. Archived fromthe original on 2024-12-14. Retrieved2024-04-27.
  8. ^Levy, Stephen (1994).Hackers: Heroes of the Computer Revolution. Penguin Books. p. 32.ISBN 0-14-100051-1.
  9. ^Jindal, G.; Khurana, P.; Goel, T. (January 2013). "Comparative study of C, Objective C, C++ programming language".International Journal of Advanced Trends in Computer Science and Engineering.2 (1): 203.
  10. ^Kernighan, B.;Ritchie, D. (1988).The C Programming Language, 2nd Edition. p. 163.
  11. ^"Extended Asm (Using the GNU Compiler Collection (GCC))".gcc.gnu.org. Retrieved2024-04-27.

Bibliography

[edit]
  • Zhirkov, Igor (2017).Low-level programming: C, assembly, and program execution on Intel 64 architecture. California: Apress.ISBN 978-1-4842-2402-1.
Level
Generation
x86 assembly topics
Topics
Assemblers
Programming
issues
Authority control databases: NationalEdit this at Wikidata
Retrieved from "https://en.wikipedia.org/w/index.php?title=Low-level_programming_language&oldid=1305615053"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp