Tuesday, 15 December 2015

Find largest number from an array

How to Create array using Assembly Language???

Initializing array using Assembly Language Code.

One example is given For Creating an array having 10 elements and find the largest number or element from the array itself.

DATA SEGMENT
     ARR DB 1,4,2,3,9,8,6,7,5,3
     LEN DW $-ARR
     LARGE DB ?
DATA ENDS
CODE SEGMENT
START:
        MOV AX,DATA
        MOV DX,AX          
        LEA SI,ARR      
        MOV AL,ARR[SI]
        MOV LARGE,AL              
        MOV CX,LEN
REPEAT:
        MOV AL,ARR[SI]
        CMP LARGE,AL
        JG NOCHANGE      
        MOV LARGE,AL
NOCHANGE:
        INC SI
        LOOP REPEAT
    
        MOV AH,4CH
        INT 21H    
CODE ENDS
END START

Output : The largest element is 9.

Sunday, 13 December 2015

Assembly Program Prints The Alphabets

Write a program in 8086 assembly language that prints the alphabets from A to Z.

stack segment
stack ends
data segment
data ends
code segment
  mov ah,02h  
  mov cx,26   
  mov dl,65
lop:
  int 21h
  add dl,1   
  loop lop 
  mov ax,4c00h
  int 21h
code ends
end

Explanation of the code
CX is the counter resister which is decreases it's value by 1 every iteration of the loop "lop".
Hence Loop will be executed for 26 times and all the alphabets are printed using dl resister.

dl resister's value is 65, the ascii code for character 'A'.
Add dl,1; statement increase it's value by one to 'B' then increase by one to 'C' upto 26 times it prints all the alphabets A to Z.

Note:
For Printing Lower case Alphabets.
initialize dl by 97 - ascii code of 'a'.

Find the average of three values stored in locations named FIRST, SECOND and THIRD and puts the result in the memory location AVGE

Write a program using 8086 assembly language to find the average of three values stored in locations named FIRST, SECOND and THIRD and puts the result in the memory location AVGE.

Prepared By Hitesh Vataliya

Assembly Program Code

DATA SEGMENT
     FIRST DB 5
     SECOND DB 9
     THIRD DB 7
     AVGE  DB ?
ENDS
CODE SEGMENT   
START:
      MOV AX,DATA
      MOV DX,AX    
      MOV AL,FIRST
      ADD AL,SECOND
      ADD AL,THIRD    
      MOV AH,0    
      MOV DL,3
      DIV DL    
      MOV AVGE,AL          
      MOV AX,4C00H
      INT 21H    
ENDS
END START

Saturday, 12 December 2015

Largest number among Three No

Write an Assembly Language Program to get largest number among Three numbers.

data segment
    s1 db "a is greater","$"
    s2 db "b is greater","$"
    s3 db "c is greater","$"   
    a db 05
    b db 10
    c db 15
ends
stack segment
    dw   128  dup(0)
ends
code segment
start:
     mov ax,@data
           mov ds,ax
          
           mov al,a
           mov bl,b
           mov cl,c
          
           cmp al,bl
          
           jc bgt
           mov ah,09
           mov dx,offset s1
           int 21h
          
           bgt:
           mov ah,09
           mov dx,offset s2
           int 21h
           jmp exit1
          
           cmp al,cl
          
           jc cgt
           mov ah,09
           mov dx,offset s1
           int 21h
          
           cgt:
           mov ah,09
           mov dx,offset s3
           int 21h
           jmp exit1         
          
          
           cmp bl,cl
          
           jc agt
           mov ah,09
           mov dx,offset s2
           int 21h
          
           agt:
           mov ah,09
           mov dx,offset s3
           int 21h
exit1:
mov ax, 4c00h
int 21h 
ends
end start

Big number among two numbers.

Write an Assembly Language Program to get largest number among two numbers.


data segment
ms1 db "a is largest number","$"
ms2 db "b is largest number","$"
a db 10h
b db 20h
ends
stack segment
    dw   128  dup(0)
ends
code segment
start:
mov ax,@data
mov ds,ax
mov al,a
mov bl,b
cmp al,bl
jg Big_a 
mov ah,09
mov dx,offset ms2
int 21h
jmp Exit1
Big_a:
mov ah,09
mov dx,offset ms1
int 21h
Exit1:
mov ax, 4c00h
int 21h
ends
end start



OUTPUT : b is largest number

Division of integer numbers

Write an assembly Language Programming for division of integer numbers.


data segment
ends
stack segment
    dw   128  dup(0)
ends
code segment
start:
mov al,24
mov bl,20
idiv bl   
mov dx,ax 
mov ax, 4c00h
int 21h 
ends
end start

Division of two numbers

Write an assembly Language Programming for division of two numbers.

data segment
ends
stack segment
    dw   128  dup(0)
ends
code segment
start:
mov al,24
mov bl,20
div bl   
mov dx,ax 
mov ax, 4c00h
int 21h 
ends
end start

Multiplication of two integer numbers

Write an assembly Language Programming for multiplication of two integer numbers.

data segment
ends
stack segment
    dw   128  dup(0)
ends
code segment
start:
mov al,24
mov bl,20
imul bl    ;multiplication store al,bl to ax
mov dx,ax ;we can see multiplication from dx 
mov ax, 4c00h
int 21h 
ends
end start



Multiplication of two numbers

Write an assembly Language Programming for multiplication of two numbers.


data segment
ends
stack segment
    dw   128  dup(0)
ends
code segment
start:
mov al,24
mov bl,20
mul bl    ;multiplication store al,bl to ax
mov dx,ax ;we can see multiplication from dx 
mov ax, 4c00h
int 21h 
ends
end start


Subtraction of two numbers

Write an assembly Language Programming for subtraction of two numbers.

data segment
ends
stack segment
    dw   128  dup(0)
ends
code segment
start:
mov ax,1001h
mov bx,2001h
sub bx,ax
mov dx,bx   
mov ax, 4c00h
int 21h 
ends
end start

Some Tips are written in the Addition of two numbers program.



Addition of two numbers

Write an assembly Language Programming for addition of two numbers.

Prepared By Hitesh Vataliya

Basic Assembly Language Program code to add two numbers

Program Code


data segment
ends
stack segment
    dw   128  dup(0)
ends
code segment
start:
mov ax,1001h
mov bx,2001h
add bx,ax
mov dx,bx   
mov ax, 4c00h
int 21h 
ends
end start

Some Useful Tips for Understanding the Assembly Program Code.

data segment and stack segment are used creating variables for the program.
code segment is used for stores code inside it which is written in assembly language. we must have to follow the above structure.
Start : starting of Program Execution of Assembly Language code
Mov ax,1001h this instruction moves data 1001h into the ax resister.
add ax,bx performs addition of ax and bx and stores it's answer to ax resister.

Assembly Language Vs Machine Language

Assembly Language Vs Machine Language

Prepared By Hitesh Vataliya




Machine Language is based on 0's and 1's. It understands only binary digits. Hence we can say Binary Language is Machine Understandable Language. Binary Language can't be understandable by the Human Being.
All the data stored inside the CD, DVD, Floppy disk, Memory Card, Hard disk or Pen drive are in the form of Binary Language, whose base is 2. 
Machine only understands that two digits.
Storage Media as said above stores the Binary Format but We are seeing the GUI(Graphical User Interface) by which we can say that the data is software, game, website, movie or video. which are possible by the software engineer of scientific officer who understand binary they make Assembly language.
  • It greatly depends on machine and is difficult for most people to write in 0-1 forms. 
  • DEBUGGING is difficult. 
  • Deciphering the machine code is very difficult. Thus program logic will be difficult to understand.

Assembly Language is Language which has mnemonics or we can say some words which can pass humans message to the CPU or Computer.
Human can understand the Assembly Language, so we can say that programmer writes the program which needs to be converted into computer understandable form and for that assembler plays the role as middle man between HUMAN and CPU.
Assembler is the software program which converts assembly language code to machine language.

  • Assembly Language provides more control over handling particular hardware and  software, as it allows you to study the instructions set, addressing modes, interrupts etc.
  • Assembly Programming generates smaller, more compact executable modules: as the programs are closer to machine, you may be ableto write highly optimised programs. This results in faster execution of programs.
Some Useful Instruction of 8086 Micro Processor or CPU:

LOAD  as  “Load the accumulator with the content of memory”
STORE  as  “Store the current value of Accumulator in the memory”
ADD  as  “Add the value from memory to the Accumulator”
MOV  AH, 08H ; Function to move 08H to AH resister
INT  21H ; The character input in AL is
SUB  BL, ‘0’  ; subtract the 0H from BL Resister
MUL  BL, 10H ; multiply BL by 10H
DIV BL  ; Divide AL Resister By BL and Store Answer in AL

Defining Types of Data


The following format is used for defining data definition:
Format for data definition:
{Name} <Directive> <expression>
Name -  a program references the data item throughthe name although it is
optional.
Directive: Specifying the data type of assembly.
Expression: Represent a value or evaluated to value.
The list of directives are given below:
Directive   Description   Number of Bytes
DB   Define byte                1
DW  Define word               2
DD   Define double word   4
DQ   Define Quad word     8
DT   Define 10 bytes         10