Low Level Programming Languages | Assembly level language
Introduction:
There are different types of programming languages like low-level and high-level programming languages. In this Article, We are going to discuss about the low level programming languages.
Low Level Programming Languages:
Programming languages which are in the symbolic format are called as Low-level programming languages. The Symbolic format means usage of hardware specific mnemonics.
Languages like Assembly language uses the Mnemonics like ADD, SUB, MOV, jmp, etc. These languages are called Low Level Languages. And low level languages are very hard to learn and understand.
Low level Languages also hardware dependent. The code you wrote for one hardware chipset won’t work for other hardware. So you have to re-write your application again for new hardware. The low level languages are not portable.
Most of the modern programming Languages like Python, Swift, etc. Which looks very close to the English language are called High level languages. We can easily learn and master these high level languages and these languages are portable as well. For more information on High Level Language please check following article – High level programming language
Key Characteristics of Low Level Programming Languages:
- Low level programming languages are in the form of mnemonics like sub, add, mov, jmp, retq, popq, and etc.
- Maintaining code, writing, debugging the low-level code is not easy compared with High level languages code.
- Low-level languages are Hardware dependent languages we cannot reuse code write for one hardware platform on other hardware platform. So these languages are not portable.
- Assembly level language is best example for low level programming language
Translating Assembly language in to Machine language:
The low level language code is close to hardware mnemonics but still it need to convert into the Machine Level Code or Binary code so that computer processor (CPU) will understand it. So We need to translate the assembly code to Machine code which is done by Assembler.
Example Program in Low Level Language:
Let’s look at the example low-level program to get better understanding of the concept.
First of we will write a simple addition program in C programming language and then we will convert the C program into the Assembly program.
Here is a C Program to Add two numbers
Add Two Numbers in C:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#include<stdio.h> int main() { // Take two input numbers int a = 10, b = 20; // Add two numbers and store result into variable 'sum' int sum = a + b; // Display the result printf("Sum of %d and %d is %d \n", a, b, sum); return 0; } |
The above program outputs the sum of two variables 'a'and 'b'
Low Level Programming Language Example:
Let’s convert above C Language code into the Assembly code.
We can convert the C Programming code into the assembly code by using the gcc compiler with option '-S' ( capital 's').
By using the gcc compiler compilation option '-S', Gcc will generate a file with .s extension under the same folder/directory. Which is the Assembly language file.
We saved above C program with sum.c file name. To generate the Assembly code for sum.c file, Use the following command.
1 |
$ gcc -S sum.c |
The above command create a file named sum.s which is Assembly equivalent of sum.c file.
Here is how our sum.c looks in the assembly language.
Assembly Code of sum.c program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
.section __TEXT,__text,regular,pure_instructions .build_version macos, 10, 15 sdk_version 10, 15, 6 .globl _main ## -- Begin function main .p2align 4, 0x90 _main: ## @main .cfi_startproc ## %bb.0: pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset %rbp, -16 movq %rsp, %rbp .cfi_def_cfa_register %rbp subq $32, %rsp movl $0, -4(%rbp) movl $10, -8(%rbp) movl $20, -12(%rbp) movl -8(%rbp), %eax addl -12(%rbp), %eax movl %eax, -16(%rbp) movl -8(%rbp), %esi movl -12(%rbp), %edx movl -16(%rbp), %ecx leaq L_.str(%rip), %rdi movb $0, %al callq _printf xorl %ecx, %ecx movl %eax, -20(%rbp) ## 4-byte Spill movl %ecx, %eax addq $32, %rsp popq %rbp retq .cfi_endproc ## -- End function .section __TEXT,__cstring,cstring_literals L_.str: ## @.str .asciz "Sum of %d and %d is %d \n" .subsections_via_symbols |
If you see above assembly language code, which contains lot of mnemonics which are hard to remember and master.
Conclusion:
In this article, We have discussed about the Low Level Languages and with example code snippets.
1 Response
[…] our previous article, We discussed about the Low-level programming languages and In this article, We will look into the High level […]