is the only language a computer can process directly without a previous transformation. Currently, programmers almost never write programs directly in machine code, because it requires attention to numerous details that a high-level language handles automatically. Furthermore, it requires memorizing or looking up numerical codes for every instruction, and is extremely difficult to modify. True machine code is a stream of raw, usually binary, data. A programmer coding in "machine code" normally codes instructions and data in a more readable form such as decimal, octal, or hexadecimal which is translated to internal format by a program called a loader or toggled into the computer's memory from a front panel. Although few programs are written in machine language, programmers often become adept at reading it through working with core dumps or debugging from the front panel. Example: A function in hexadecimal representation of 32-bit x86 machine code to calculate the nth Fibonacci number: 8B542408 83FA0077 06B80000 0000C383 FA027706 B8010000 00C353BB 01000000 B9010000 008D0419 83FA0376 078BD989 C14AEBF1 5BC3
Second-generation languages provide one abstraction levelon top of the machine code. In the early days of coding on computers like the TX-0 and PDP-1, the first thing MIT hackers did was write assemblers. Assembly language has little semantics or formal specification, being only a mapping of human-readable symbols, including symbolic addresses, to opcodes, addresses, numeric constants, strings and so on. Typically, one machine instruction is represented as one line of assembly code. Assemblers produce object files 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 calculator as above, but in x86-64 assembly language using AT&T syntax: _fib: movl $1, %eax .fib_loop: cmpl $1, %edi jbe.fib_done movl %eax, %ecx addl %ebx, %eax movl %ecx, %ebx subl $1, %edi jmp.fib_loop .fib_done: ret
In this code example, hardware features of the x86-64 processor are named and manipulated directly. The function loads its input from %edi in accordance to the System V ABI and performs its calculation by manipulating values in the EAX, EBX, and ECXregisters 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 EAX register, the RET command simply moves code processing to the code location stored on the stack and it is up to the author of the calling code to know that this function stores its result in EAX and to retrieve it from there. x86-64 assembly language imposes no standard for returning values from a function ; it is up to the calling code to examine state after the procedure returns if it needs to extract a value. Compare this with the same function in C: unsigned fib
This code is very similar in structure to the assembly language example but there are significant differences in terms of abstraction:
The input 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 assembly language version loads the input parameter from the stack into a register and in each iteration of the loop decrements the value in the register, never altering the value in the memory location on the stack. The C compiler could load the parameter into a register and do the same or could update the value wherever it is stored. Which one it chooses is an implementation decision completely hidden from the code author.
The local variables a, b and c 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 architecture typically use the EAX register to return a value, as in the assembly language example.
These abstractions make the C code compilable without modification on any architecture for which a C compiler has been written. The x86 assembly language code is specific to the x86 architecture.
In the late 1960s, high-level languages such as PL/S, BLISS, BCPL, extended ALGOL and C included some degree of access to low-level programming functions. 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.