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