Assembly Coding

3 Basic Elements of Assembly Coding

Rate this post

Assembly language (also known as symbolic machine code or assembler language) is that low-level programming language that might be called assembly and employs ASM or asm abbreviations. Assembly language refers to languages and lower-level programming languages with a very clear correspondence to the machine code instructions for that architecture. Assembly languages usually have one statement for every machine instruction. A constant, comments or assembler directives, symbolic labels for e.g. memory locations and registers and even macros are generally supported.

Therefore, we are presenting to you 3 basic elements to assembly coding.

Opcode mnemonics and extended mnemonics

The instructions in assembly language are generally very simple, unlike the ones in high-level languages. In general, a mnemonic is a symbolic name for a single executable machine language instruction (an opcode), and there is at least one opcode mnemonic defined for each machine language instruction. Each instruction typically comprises an operation or opcode plus zero or more operands. Most of the instructions refer to a single value or a pair of values. Operands can be immediate (value coded in the instruction itself), registers specified in the instruction or implied, or by the addresses of data located elsewhere in storage. This is determined by the underlying processor architecture: the assembler has simply to reflect how that architecture works. An example of extended mnemonics would be to encode a combination of an opcode with a specific operand, such as the System/360 assemblers using B as an extended mnemonic for BC with a mask of 15 and NOP (“NO OPeration“- do nothing for one step) for BC with a mask of 0.

Extended mnemonics are most often used to enable an unusual or awkward use of an instruction that is not immediately apparent from the instruction name. For instance, most of today’s microprocessors do not have a NOP operation. However, they usually employ ineffective instruction to carry out the NOP function. This instruction is xchg ax, ax in the 8086 CPUs; the nop pseudo-opcode simply encodes this instruction. Some disassemblers are clever enough to recognize this and decode the xchg ax, ax instruction as a nop. Similarly, the System/360 and System/370 assemblers of IBM use the extended mnemonics NOP and NOPR for BC and BCR with zero masks, respectively, while such instructions are referred to as synthetic instructions in the SPARC architecture.

Data directives

The instructions define various data elements to contain data and variables. These instructions define the type of data, length, and alignment of said data. The instructions can mention whether the data is available to external programs (separately assembled programs) or only to the program where the data section is defined. Some assemblers treat these types of instructions as pseudo-ops.

Assembly directives

Assembly directives are sometimes called pseudo-opcodes, pseudo-operations, or pseudo-ops; they consist of commands given to an assembler “directing it to perform operations other than assembling instructions”.Directives affect how the assembler operates and “may affect the object code, the symbol table, the listing file, and the values of internal assembler parameters”.Sometimes, the term pseudo-opcode is reserved for those that generate object code, often generating data.

The names of pseudo-operations usually begin with a dot so as to distinguish them from machine instructions. Pseudo-operations can make assembly of a given program dependent upon parameters input by a programmer so that one program could ultimately be assembled in different ways for different applications. Or it can refer to manipulation of a program’s presentation such that it becomes easier to read and maintain. Another common use of pseudo-operations is to allocate storage areas for dynamic run-time data and optionally initialize their contents to some known values.

 

Back To Top