Talk:Low-level programming language
Examples
This page could use some examples. Thehotelambush 16:09, 30 July 2007 (UTC)
- Example - a function that calculates the nth Fibonacci number.
- First, in C [3rd generation]:
unsigned int fib(unsigned int n) { if (n <= 0) return 0; else if (n <= 2) return 1; else { int a,b,c; a = 1; b = 1; while (1) { c = a + b; if (n <= 3) return c; a = b; b = c; n--; } } }
- The same function, but converted to x86 assembly language, specifically MASM, using the
__cdecl
calling convention [2nd generation]:
fib: mov edx, [esp+8] cmp edx, 0 ja @f mov eax, 0 ret @@: cmp edx, 2 ja @f mov eax, 1 ret @@: push ebx mov ebx, 1 mov ecx, 1 @@: lea eax, [ebx+ecx] cmp edx, 3 jbe @f mov ebx, ecx mov ecx, eax dec edx jmp @b @@: pop ebx ret
- Note:
@f
refers to the closest following@@:
label.@b
refers to the closest preceding@@:
label.- I deliberately did not use
proc
.
- And here is the final x86 machine code [1st generation]:
8B542408 83FA0077 06B80000 0000C383 FA027706 B8010000 00C353BB 01000000 B9010000 008D0419 83FA0376 078BD98B C84AEBF1 5BC3
- For comparison purposes, here is a disassembly listing:
00401000 fib: 00401000 8B542408 mov edx,[esp+8] 00401004 83FA00 cmp edx,0 00401007 7706 ja loc_0040100F 00401009 B800000000 mov eax,0 0040100E C3 ret 0040100F loc_0040100F: 0040100F 83FA02 cmp edx,2 00401012 7706 ja loc_0040101A 00401014 B801000000 mov eax,1 00401019 C3 ret 0040101A loc_0040101A: 0040101A 53 push ebx 0040101B BB01000000 mov ebx,1 00401020 B901000000 mov ecx,1 00401025 loc_00401025: 00401025 8D0419 lea eax,[ecx+ebx] 00401028 83FA03 cmp edx,3 0040102B 7607 jbe loc_00401034 0040102D 8BD9 mov ebx,ecx 0040102F 8BC8 mov ecx,eax 00401031 4A dec edx 00401032 EBF1 jmp loc_00401025 00401034 loc_00401034: 00401034 5B pop ebx 00401035 C3 ret
Absolute terms
I've always known low-level and high-level programming languages to be absolute terms. The former refers to programming languages that provide no abstraction from the instructions that the processor implements, this is binary code (maybe written in hexadecimal), and assembler language, which is a mnemonic for the binary code and is assembled. The latter refers to programming languages that can be used independently of the processor because there is a software layer that abstracts that detail (something an assembler does not do), as a compiler or an interpreter.
The crisp and absolute difference between low-level programming languages and high-level programming languages, for what I knew, is that the code is done for a specific hardware (or group of them) as may be the x86 group of processors, or it is done for a software (or group of them) as is the group of C compilers.
Unfortunately I haven't been able to find references as this is more a terminological matter than a informatics matter, that's why I've required the citation (as there may be one). All that I got by now is this a definition in the webopedia[1].
Kind regards. —Preceding unsigned comment added by Trylks (talk • contribs) 23:26, 19 February 2008 (UTC)