Difference between revisions of "Assembly language"

From Conservapedia
Jump to: navigation, search
m (cats)
Line 58: Line 58:
  
 
[[Category:Information technology]]
 
[[Category:Information technology]]
[[Category:computer science]]
+
[[category:Programming Languages]]
[[category:Programming_language]]
+

Revision as of 21:53, January 22, 2008

An Assembly language is a low-level Programming language that is specific to a given CPU's instruction set. For instance, the Zilog Z80 assembly language is different from the Intel 8080 assembly language, despite the similarities in the underlying isntruction sets.

A program, called an Assembler converts source code written in Assembly Language into the CPU's machine code. Each CPU instruction is assigned a short mnuemonic code (traditionally 3 or 4 characters in length). Additional syntax supports registers, addressing modes, labels and other symbolic names, comments, and directives. Assembly languages supporting macro processing (substitution, etc) used to be called Macro Assembly languages, but as most Assembly languages now support macros, the "Macro" prefix has been dropped from common usage.

The instruction mnuemonics are typically defined by the manufacturer of the CPU. Although anyone could assign their own arbitrary set of mnuemonics for a CPU's instruction set, in practice this is seldom done.

Advantages and Diadvantages of Assembly Language

Assembly languages do not provide many of the useful abstractions of high-level languages, such as memory management, object and other complex data structure support, or string manipulation. Such features are often available through libraries of assembly code, though. Assembly language is essential when a new CPU is developed since it allows the development of higher-level language compilers for that CPU. Assembly is also required for access to unique and low-level features of a CPU which is why portions of most Operating Systems must be written using assembly language. Because assembly provides no abstractions, code written with it can run faster than equivalent code written in a high-level programming language. However, modern optimizing compilers are often better at generating efficient machine code than human-crafted assembly. Finally, writing assembly code is more tedious (and therefore more error-prone) than using a high-level language.

Macros

Macros provide short-hand for assembly programmers. The most common macro feature is the substitution macro. This allows the programmer to define his own mnuemonic in place of several pre-existing mnuemonics. When the macro is used, the assembler will substitute the corresponding mnuemonics in place of the macro, as if the programmer had included those mnuemonics at that point in the source code. Another form of macro is the iteration macro which allows the programmer to duplicate something without having the manually duplicate it numerous times. Thus macros can reduce the size, and complexity, of the assembler source code.

Example

Without an assembler, a person who wanted to increment the Zilog Z80 "C" register, would have to figure out the numeric code (in this case 4 hexadecimal or 00000100 binary). Assembly allows this operation to be specified with the mnuemonic:

INC C which is much easier to remember. Modern CPUs have even more complicated instruction sets which can exceed the length of this instruction by four times or more. For this reason, some refer to machine language as a first-generation language, and assembly as a second-generation language. High-level programming languages are called third-generation languages.

Sample Assembly Source Code

The following is a sample of assembly code for the Intel 8086 CPU:


The purpose of this code is to output a new line
.DEFINE OUTR
      MOV   AX, 02H
      INT   21H
.ENDDEF

CRLF: PUSH DX

      PUSHF
      MOV   DL, _CR
      OUTR
      MOV   DL, _LF
      OUTR
      POPF
      POP   DX
      RET
      END

References

  • The 8086 Family User's Manual, Intel Coporation, 1979
  • VAX 11 Structured Assembly Language Programming, Robert W. Sebesta, Benjamin/Cummings Publishing, ISBN 0-8053-7001-3
  • Programming the Z80, Rodnay Zaks, Sybex, ISBN 0-89588-069-5