An introduction to GNU assembly language.

An introduction to GNU assembly language.

Learn about the low-level programming language which makes wonders in the dark

Introduction

Ever wondered how programs are understood by the computers and how they are transformed before execution. These can be understood by getting a glimpse of low-level programming language which is very close to object code understand by computer.

Assembly

We can create a assembly language code (.s extention file) for Gnu based systems from a simple c programme(**.c extension) using the following command on your terminal. gcc -S -O0 file.c

  • -S -> create the .s file
  • -O0 -> prevent optimization so that we can understand the code completely

    The above command only works on GNU base systems like Linux (or) gcc compiler installed on windows. The above command will create a a.out file and a file.s assembly language file

Assembly Language Syntax

The assembly language is divided into segments. Some definitions are b ->byte(8bit) , w-> word(16 bits), l -> long(32 bits), q->quadword(64 bits). The prefix % denotes a register on the CPU The main instruction and their definition are follows,

  • movq reg1, reg2 -> copy a quadword from reg1 to reg2
  • pushq reg -> push the address into stack for further retrieval (Eg:: functions)
  • ret -> stop the program and return control to user
  • cmpl reg1, reg2 -> compare reg1 with reg2 and set flag to 0 if they are same

    Flag

    Flags are used know what's happening in the program. For specific instructions the flag is set, which helps us proceed with further instruction. Example: while subtracting 2-3=> -1. The program can know we get a negative value by setting a flag as true. The most important component for assembly program is System calls

    System call

    System call is a way to interact with the kernel directly. When we want to take user input (or) print out anything to screen, we will need the help of OS to do so. That's where system calls come in, we can request different privileges from the OS using system calls. The system calls have different names as hexadecimal numbers and can be invoked by syscall command.

This is a very basic introduction to assembly language.

Did you find this article valuable?

Support hari hara sankar by becoming a sponsor. Any amount is appreciated!