This blog includes subject like Computer Organization, Microprocessor, Digital Electronics, System Programming

Pages

This blog includes subject like Computer Organization, Microprocessor, Digital Electronics, System Programming

Powered by Blogger.

Friday, May 10, 2019

Assembly Language Basic Part-1



What is Assembly Language?
l  Every PC has a microprocessor that manages computer's ALU and control activities.
l  Each processor has its own set of instructions for handling various operations like Input and output.
l  To operate this activity assembly language is used.

Why Study Assembly Language?
l  It is used to Interface of programs with OS, processor and BIOS.
l  Representation of data in memory and other external devices.
l  It requires less memory and execution time.
l  It allows hardware-specific complex jobs in an easier way.

Assembler
l  Assembler is a type of converter accept assembly language as input and convert it into equivalent machine language.
l  There are following types of popular assembler:
1. Netwide Assembler (NASM)
2. Microsoft Assembler (MASM)
3. Borland Turbo Assembler (TASM)

Assembly Basic Syntax
An assembly program can be divided into three sections:
1. The data section
2. The bss (Block Started Symbol) section
3. The text section
1. The Data Section
l  The data section is used for declaring initialized data or constants.
l  This data does not change at runtime.
l  The syntax for declaring data section is:
Syntax:   section .data
2. The bss (Block Started Symbol) section:
l  The bss section is used for declaring variables.
l  These variables are accessed from keyboard and used to display result.
l  The syntax for declaring bss section is:
Syntax: section .bss
3. The text section
l  The text section is used for keeping the actual code.
l  This section must begin with the declaration global  _start:
l  Which tells the kernel where the program execution begins.
l  The syntax for declaring text section is:
section .text
global  _start:
_start:

Syntax of Assembly Language Statements:
l  Assembly language statements are entered one statement per line. Each statement follows the following format:
l  [label]   mnemonic          [operands]         [;comment]
l  e.g.
abc1: mov   ax, 00h                  ;initialize acc.


The Hello World Program!!!
section .data
msg db 'Hello, world!', 10 ;our string, 10=\n like C.
len equ $ - msg                  ;length of our dear string

section .text
global _start                       ;must be declared for linker (ld)
_start:                                 ;tells linker entry point
mov edx,len                       ;message length
mov ecx,msg                     ;message to write
mov ebx,1                         ;file descriptor (stdout)
mov eax,4                         ;system call number (sys_write)
int 80h                              ;call kernel
mov eax,1                         ;system call number (sys_exit)
int 80h                              ;call kernel

Compile and execute Program
>nasm -f elf64 progname.asm   ; Compile code
>ld -o progname progname.o    ;Load & create obj
>./progname     ;Execute program
               

0 comments:

Post a Comment