Assembly language in a computer is a low-level programming language. The assembly language (ASM) is close to hardware and has direct control over it. But it is far different from machine language. ASM is easily readable by humans.
ASM programs are processed by an assembler and converted to machine language. The ASM program consists of a sequence of statements, each representing a single instruction. ASM uses a set of mnemonics and rules to use these mnemonics that we refer to as syntax.
ASM is machine specific; thus, each computer architecture has a different assembly language. We will discuss assembly language in detail in the section, so let’s start.
Content: Assembly Language in Computer
- What is Assembly Language?
- Assembly Language Syntax
- Use of Assembly Language
- Examples of Assembly Language
- Assembly Language Vs Machine Language
- Advantages & Disadvantages
What is Assembly Language?
Assembly language is a low-level programming language. It has a set of symbolic names (mnemonics) and rules to use them. Mnemonics are shorthand words that describe some operation. Such as LD for Load, ST for Store, ADD for Addition, etc.
We refer to the set of rules that defines the use of mnemonics for constructing an instruction or entire program as syntax.
We know that a computer or a processor cannot execute a program in assembly language. So, a system program assembler automatically translates the program in assembly language into a sequence of machine instructions.
The assembly language for each assembler is different. It depends on which computer architecture the assembler is designed.
How is assembly language different from machine language?
Assembly language is different from a high-level language. The high-level language offers abstraction over the low-level language. It lets programmers focus on what they want to do instead of how the machine should do it. However, the assembly language focuses more on how the computer must perform a particular task.
Thus, assembly language is quite efficient when it comes to low-level controls. The processor executes assembly language instruction faster as compared to high-level language instruction.
Assembly Language Syntax
Assembly language programs consist of a sequence of statements/instructions. Each statement specifies the operation to be performed, along with the operands involved in this operation.
Usually, the statements in the assembly language are in the form given below:
Label: Operation Operand(s) Comment
One or more blank spaces separate these four fields.
- A label is an optional field that refers to the memory address where the machine instruction generated from the corresponding statement will be loaded.
- The operation field denotes the operation, i.e. mnemonic of the instruction.
- Operands filed either holds the value that must be operated or the reference address for accessing the operands.
- The last file holds the comments, if any and is ignored by the assembler while processing the instruction. The comments are only for documentation purposes, and it only makes a program easier to understand.
This is the basic syntax of a source statement in assembly language. Its detail and complexity differ from one computer architecture to another.
Use of Assembly Language
A processor only executes instructions in machine language. The instructions in machine language are represented as 0s and 1s. But writing instructions or programs in machine language is tedious and error-prone. Let’s see how.
Consider that we have basic instruction.
A = B + C
Now let’s program this instruction in machine language and initialize the operands B and C to 2 and 4, respectively. Let’s say the program starts in location 101, and the memory for three variables starts from 201.
The machine language program above initially consists of three instructions:
- Load the content of location 201 into the AC.
- Add the content of location 202 to the AC.
- Store the contents of the AC in location 203.
The rest three instructions show the initialization of the variables B, C and A, respectively. Now if we convert this program to a symbolic program, it would be a set of instructions. Each instruction has three fields separated by spaces. The first field represents the location’s address; the second field represents an operation in a symbolic form called opcode. The third field represents the address of operands in the first three instructions, and in the next three, it represents the value itself.
Symbolic language is convenient but still has some issues, for each word; we have to provide an absolute address which means the instruction and data have to be placed on the given location only. For this, we must know the location ahead of time.
Now, what if we want to add or delete the instruction? It will subsequently affect other instructions too. So, instead of an absolute address, let’s go for a symbolic one. By doing this, we end with assembly language.
Examples of ASM
The image below shows the assembly program for the statement A = B + C.
Here, each instruction still has three fields. The first field is an address, but we use a symbol instead of an absolute address in this case. The second field is of operation to be performed, and the third field represents an address in symbolic form.
Assembly language is comparatively easy for programmers to code. It also leveraged the evolution of high-level languages. Nowadays, only a few programmers use assembly language to code. But it is used in almost all machines as it is used to code system programs such as compilers, I/O routines, drivers etc.
Assembly Language Vs Machine Language
Basis for Comparison | Assembly Language | Machine Language |
---|---|---|
Basic | Assembly language uses mnemonics to represent operations, operands and data. | Machine language uses 0s and 1s to represent instructions and data. |
Ease | It is easy for humans to understand assembly language. | It is easy for a machine to understand machine language. |
Execution speed | Comparatively slower | Faster |
Error Risk | Less prone to error. | High risk of error. |
Modification | It’s easy to make changes to assembly language code. | It’s difficult to make changes to machine language code. |
Advantages & Disadvantages
Advantages of Assembly Language
- It’s easy for humans to understand assembly language code.
- It’s a less error-prone process.
- Has more control over the computer’s hardware.
- Program in assembly language executes fast.
- Instructions or programs can be modified easily.
Disadvantages of Assembly Language
- Assembly language is machine dependent, and thus it is not portable.
- There is a different assembly language for each computer.
- It is comparatively more difficult than high-level language and restricts programmers from focusing on what they want the computer to do.
- Some of the syntaxes of assembly language are difficult to remember.
So, this is all about the assembly language in computer. We have learnt that it is a low-level language close to the computer’s hardware. It uses mnemonics to represent instructions and data. Assembly language is different for different computer architectures; thus, it is not portable.
Leave a Reply