A program written in assembly language is a low-level program written in terms of the processor’s hardware and instruction set. It can be used to control hardware devices such as LEDs Light Emitting Diodes. Assembly, also known as machine-code, allows a level of understanding of what the processor is doing that high-level programming languages don’t provide. This understanding can help a programmer to write more efficient code and understand how a device works, such as an input/output pin or logic gate.
To make a program Assembly programs in assembly, the code is entered into an assembler, which turns it into the corresponding machine-code instructions for the target system. The assembler is aware of the processor’s registers and memory locations, and can produce a file that includes symbolic names for variables (memory addresses), data constants, and labels (code locations). The assembler program also knows how to translate from the mnemonics of the assembler instructions to the standard operation codes that are recognized by the machine-code interpreter.
Each assembler instruction starts with a mnemonic representing the operation to be performed, followed by the operands that will be operated on. This may be a destination or source operand, or both. For example, the ADD instruction (covered in a previous article) adds two numbers together and places the result in the destination register, R0. Some mnemonics are specific to the processor, such as MOV, while others are generic and can be used for any operation, such as ST, LR, MVI, or LSB. The assembler program also keeps track of the current location in the file by using a program counter or location counter, and inserts the proper address into the object code for each instruction.
There are many different assembler programs available, with each supporting a variety of processors and operating systems. NASM and YASM, for example, are popular cross-platform assemblers that can be used with Intel x86 processors. Several other assemblers are used to write specialized software for specific devices, such as the Intel 8-bit microprocessor family and other embedded processors.
Some high-level programming languages can be used with assembly, although there is a lot of overhead required by these languages. When this is done, it is often necessary to adhere to a calling convention, which defines how function parameters and return values are passed between the different languages. Despite these constraints, it is still possible to build complex applications with both assembly and high-level language code. As higher-level languages continue to abstract away what a computer does, knowing assembly can give you a better understanding of how it works and how to write more efficient code. In addition, it can be helpful when debugging problems with a piece of hardware.