Jump to content

Assembly language: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
m Automated conversion
Alan d (talk | contribs)
linked register, and added some on usefulness of asm.
Line 5: Line 5:
does, for programmers it is easier to remember the semantics of the equivalent
does, for programmers it is easier to remember the semantics of the equivalent
mov $0x61, %al
mov $0x61, %al
(it means to move the [[hexadecimal]] value 61 (97 decimal) into the register 'al'.)
(it means to move the [[hexadecimal]] value 61 (97 decimal) into the [[register]] 'al'.)


Unlike in [[high-level language]]s, there is a 1-to-1 mapping from simple assembly to machine language, so that computers can translate in both directions without losing information. Transforming assembly into machine languages is accomplished by an [[assembler]], the other direction by a [[disassembler]]. When real programming is done in assembly, it is usually in a bit more complex variant, and the convenient mapping is gone.
Unlike in [[high-level language]]s, there is a 1-to-1 mapping from simple assembly to machine language, so that computers can translate in both directions without losing information. Transforming assembly into machine languages is accomplished by an [[assembler]], the other direction by a [[disassembler]]. When real programming is done in assembly, it is usually in a bit more complex variant, and the convenient mapping is gone.
Line 29: Line 29:
* applying a simple operation (for example, addition) to a vector of values
* applying a simple operation (for example, addition) to a vector of values


There is some debate over the usefulness of assembly language. In many cases, modern compilers can render higher-level languages into code as fast as assembler. However, some discrete calculations can still be rendered into faster running code in assembler, and some low-level programming is simply easier to do in assembler. Many compilers also render high-level languages into assembler first before fully compiling, allowing the assembler code to be viewed for debugging and optimization purposes.

Revision as of 16:14, 1 June 2002

Assembly is a human-readable rendition of the machine language that a specific computer architecture uses. Machine language, a mere pattern of bits, is made readable by replacing the raw values with short commands, called mnemonics, and their arguments.

So, while a computer will recognize what

 10110000 01100001

does, for programmers it is easier to remember the semantics of the equivalent

 mov $0x61, %al

(it means to move the hexadecimal value 61 (97 decimal) into the register 'al'.)

Unlike in high-level languages, there is a 1-to-1 mapping from simple assembly to machine language, so that computers can translate in both directions without losing information. Transforming assembly into machine languages is accomplished by an assembler, the other direction by a disassembler. When real programming is done in assembly, it is usually in a bit more complex variant, and the convenient mapping is gone.

Every computer architecture has its own machine language, and henceforth its own assembly language (the example above is from the i386). These languages differ by the number and type of operations that they support; while all general-purpose computers are able carry out the same functionality, the way they do it differs.

Nevertheless, some basic operations are available in almost all assembly languages:

  • moving
    • load a value into a register
    • move data from a memory location to a register, or vice versa
  • computing
    • add, subtract, multiply, or divide the values of two registers, placing the result in a register
    • combine two register values with logical and/or
    • negate a register value arithmetically or by logical not
  • affecting program flow
    • jump to another location in the program (normally, instructions are processed sequentially)
    • jump to another location, but save the next instruction as a point to return to
    • go back to the last return point

Specific languages will often have single, or a few instructions for operations which would otherwise take many instructions. Examples:

  • moving big blocks of memory
  • higher arithmetic (sine, cosine, square root, etc.)
  • applying a simple operation (for example, addition) to a vector of values

There is some debate over the usefulness of assembly language. In many cases, modern compilers can render higher-level languages into code as fast as assembler. However, some discrete calculations can still be rendered into faster running code in assembler, and some low-level programming is simply easier to do in assembler. Many compilers also render high-level languages into assembler first before fully compiling, allowing the assembler code to be viewed for debugging and optimization purposes.