Showing posts with label MIL. Show all posts

MICROPROCESSOR INTERFACING LABORATORY

, by Prashant Gunjal

MICROPROCESSOR INTERFACING LABORATORY

Group A

1. Write 8086 Assembly language program (ALP) to add array of N hexadecimal numbers stored in the memory. Accept input from the user.








read more

8087ALP to obtain: i) Mean ii) Variance iii) Standard Deviation

, by Prashant Gunjal



7. Write 8087ALP to obtain: i) Mean ii) Variance iii) Standard Deviation For a given set of data elements defined in data segment. Also display result.



.model small
disp macro msg
lea dx,msg
mov ah,09h
int 21h
endm

divi macro number
mov ax,bx
mov dx,0000h
mov bx,number
div bx
mov bx,dx
mov dx,ax
endm

.8087
.data
msg2 db 10,13,"1.mean::$"
msg3 db,10,13,"2.Standard deviation::$"
msg4 db,10,13,"3.variance::$"
msg7 db ".$"
msg8 db 10,13," $"
a dd 11.30
b dd 22.30
c dd 23.40
d dd 24.60
count dd 4.00
l dd(?)
j dd(?)
m dw(?)
n dw(?)
p dd(?)
q dw(?)
r dw(?)
s dw(?)
t dw(?)
x dd 10.00

.code
mov ax,@data
mov ds,ax
disp msg2

finit

fld a
fld b
faddp st(1),st
fld c
faddp st(1),st
fld d
faddp st(1),st
fst j

fld count

fdivp st(1),st

fst l
frndint
fist m
fld l

fsub  st,st(1)
fld x
fmulp st(1),st
frndint
fistp n
fld a
fld a
fmulp st(1),st
fld b
fld b
fmulp st(1),st
faddp st(1),st
fld c
fld c
fmulp st(1),st
faddp st(1),st
fld d
fld d
fmulp st(1),st
faddp st(1),st

fld count
fdivp st(1),st
fld l
fld l
fmulp st(1),st
fsub st(1),st
fld st(1)
fst p
frndint
fist q
fld p
fsub st,st(1)
fld x
fmulp st(1),st
frndint
fistp r
fld p
fsqrt
fst p
frndint
fist s
fld p
fsub st,st(1)
fld x
fmul st(1),st
frndint
fistp t

mov bx,m

divi 03E8h
call bcdprint
divi 0064h
call bcdprint
divi 00Ah
call bcdprint
divi 0001h
call bcdprint

disp msg7

mov bx,n

mov dl,bl
and dl,0fh
cmp al,09h
jbe l3
add dl,00h
l3: add dl,30h
mov ah,02h
int 21h
jmp r1

r1: disp msg3
jmp r2
r2: mov bx,s

divi 03e8h
call bcdprint
divi 0064h
call bcdprint
divi 00ah
call bcdprint
divi 0001h
call bcdprint

disp msg7

mov bx,t

mov dl,bl
and dl,0fh
cmp al,09h
jbe l4
add dl,00h
l4: add dl,30h
mov ah,02h
int 21h
jmp r3

r3: disp msg4
jmp r4
r4: mov bx,q

divi 03e8h
call bcdprint
divi 0064h
call bcdprint
divi 00ah
call bcdprint
divi 0001h
call bcdprint

disp msg7

mov bx,r

mov dl,bl
and dl,0fh
cmp al,09h
jbe l5
add dl,00h
l5: add dl,30h
mov ah,02h
int 21h
jmp rend

bcdprint proc near
and dl,0fh
cmp dl,09h
jbe l1
add dl,07h
l1: add dl,30h
mov ah,02h
int 21h
ret
bcdprint endp
rend: mov ah,4ch
int 21h
end
;OUTPUT
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\student>CD ..

C:\Documents and Settings>CD ..

C:\>CD TASM

C:\tasm>TASM A_8087
Turbo Assembler  Version 2.0  Copyright (c) 1988, 1990 Borland International

Assembling file:   A_8087.ASM
Error messages:    None
Warning messages:  None
Passes:            1
Remaining memory:  472k


C:\tasm>TLINK A_8087
Turbo Link  Version 3.0 Copyright (c) 1987, 1990 Borland International
Warning: No stack

C:\tasm> A_8087

1.mean::0020.4
2.Standard deviation::0005.:
3.variance::0028.3
C:\tasm>
read more

ALP to perform multiplication of two 8-bit hexadecimal numbers.

, by Prashant Gunjal


6. Write 8086 ALP to perform multiplication of two 8-bit hexadecimal numbers. Use successive addition and add and shift method. Accept input from the user.



;MULTIPLICATION USING:-
;SUCCSIVE ADITION AND SHIFT AND ADD METHOD

DISP MACRO MSG        ;MARCO FOR DISPLAY MESSAGE
        LEA DX,MSG
        MOV AH,09H
        INT 21H
ENDM

.MODEL SMALL

.DATA           ;DEFINING DATA SEGMENT

        MSG1 DB 10,13,"ENTER MULTIPLICAND:$"
        MSG2 DB 10,13,"ENTER MULTIPLIER:$"
        MSG3 DB 10,13,"ANSWER:$"

        MSG4 DB 10,13,"1.SUCCSIVE ADITION$"
        MSG5 DB 10,13,"2.SHIFT AND ADD$"
        MSG6 DB 10,13,"3.EXIT$"

        NO1 DW 1 DUP(0)
        NO2 DB 1 DUP(0)
        ANS DW 1 DUP(0)

.CODE                
        MOV AX,@DATA
        MOV DS,AX

MENU:   DISP MSG4

        DISP MSG5

        DISP MSG6

        MOV AH,01H
        INT 21H

        SUB AL,30H
        CMP AL,09H

        JNZ X1

        SUB AL,07H

     X1:CMP AL,01H

        JZ MENU1

        CMP AL,02H

        JZ MENU2

        CMP AL,03H

        JZ EXIT

        JMP MENU

MENU1:  CALL READ   ;CALLING PROC FOR READ TWO NO

        CALL SADD1  ;CALLING PROC FOR MULTIPLICATION
                    ;USING SUCCSIVE ADITION METHOD

        CALL DISP1  ;DISPLAY ANS

        JMP MENU

MENU2:  CALL READ   ;CALLING PROC FOR READ TWO NO

        CALL SADD2  ;CALLING PROC FOR MULTIPLICATION
                    ;USING SHIFT AND ADD METHOD

        CALL DISP1  ;DISPLAY ANS

        JMP MENU

   EXIT:MOV AH,4CH
        INT 21H


  READ PROC NEAR    ;PROCEDURE FOR READING TWO NO

        DISP MSG1

     L1:MOV AH,01H
        INT 21H
        SUB AL,30H
        CMP AL,09H
        JBE L2
        SUB AL,07H

     L2:MOV AH,00H
        MOV CL,0CH
        ROL AX,CL
        MOV DX,AX

     L3:MOV AH,01H
        INT 21H
        SUB AL,30H
        CMP AL,30H
        JBE L4
        SUB AL,07H

     L4:MOV AH,00H
        MOV CL,08H
        ROL AX,CL
        ADD DX,AX

     L5:MOV AH,01H
        INT 21H
        SUB AL,30H
        CMP AL,09H
        JBE L6
        SUB AL,07H

     L6:MOV AH,00H
        MOV CL,04H
        ROL AX,CL
        ADD DX,AX

     L7:MOV AH,01H
        INT 21H
        SUB AL,30H
        CMP AL,09H
        JBE L8
        SUB AL,07H

     L8:MOV AH,00H
        ADD DX,AX

        MOV NO1,DX

     L9:DISP MSG2

    L11:MOV AH,01H
        INT 21H
        SUB AL,30H
        CMP AL,09H
        JBE L12
        SUB AL,07H

    L12:MOV CL,04H
        ROL AL,CL
        MOV DL,AL

    L13:MOV AH,01H
        INT 21H
        SUB AL,30H
        CMP AL,30H
        JBE L14
        SUB AL,07H

    L14:ADD DL,AL

        MOV NO2,DL

        RET
 ENDP

 SADD1 PROC NEAR  ;PROCEDURE FOR SUCCSIVE ADDITION METHOD

     M1:MOV AX,NO1
        MOV CL,NO2
        MOV DX,0000H
        MOV CH,00H

     M2:ADD DX,AX
        LOOP M2

        MOV ANS,DX
        RET
  ENDP


 SADD2 PROC NEAR   ;PROCEDURE SHIFT AND ADD METHOD

     A1:MOV AX,NO1
        MOV BL,NO2

        MOV CX,0801H
        MOV DX,0000H

     A2:SHL BL,CL
        JC A3

        SHL DX,CL
        JMP A4

     A3:SHL DX,CL
        ADD DX,AX

     A4:DEC CH
        JNZ A2

        MOV ANS,DX


        RET
  ENDP


 DISP1 PROC NEAR   ;PROCEDURE FOR DISPLAYING NO

     R1:DISP MSG3

        MOV BX,ANS

        MOV CX,0204H
        MOV DH,BH
     R2:ROL DH,CL
        MOV DL,DH
        AND DL,0FH
        CMP DL,09H
        JBE R3
        ADD DL,07H
     R3:ADD DL,30H
        MOV AH,02H
        INT 21H
        DEC CH
        JNZ R2

        MOV CX,0204H
        MOV DH,BL
     R4:ROL DH,CL
        MOV DL,DH
        AND DL,0FH
        CMP DL,09H
        JBE R5
        ADD DL,07H
     R5:ADD DL,30H
        MOV AH,02H
        INT 21H
        DEC CH
        JNZ R4

        RET
 ENDP

END

read more

ALP using far procedure for string operations

, by Prashant Gunjal


5. Write 8086 ALP to perform string manipulation. The strings to be accepted from the user is to be stored in data segment of program_l and write FAR PROCEDURES in code segment program_2 for following operations on the string:
(a) Concatenation of two strings (b) Number of occurrences of a sub-string in the given string
Use PUBLIC and EXTERN directive. Create .OBJ files of both the modules and link them to create an EXE file.

;PROGRAM 1


extrn concat:far
extrn substring:far
public str1
public str2
public msg5
public msg7
public msg8
.model small
disp macro msg
lea dx,msg
mov ah,09h
int 21h
endm
.data
msg1 db 10,13,10,13,"MENU",10,13,"1.Enter 1st string",10,13,"2.Enter 2nd string",10,13,"3.Concatenate",10,13,"4.Substring ",10,13,"5.exit $"
msg2 db 10,13,"Enter your choice:$"
msg3 db 10,13,"Enter the 1st string:$"
msg4 db 10,13,"Enter the 2nd string:$"
msg5 db 10,13,"Concatenate string is:$"
msg6 db 10,13,"substring is found $"
               msg7 db 10,13,"substring is not found $"
               msg8 db 10,13,"no. of occurence: $"
               str1 db  25,?,25 dup("$")
str2  db 25,?,25 dup("$")
             
.code
              mov ax,@data
mov ds,ax
mov es,ax
main: disp msg1
disp msg2
mov ah,01h
int 21h
cmp al,31h
je p1
cmp al,32h
je p2
cmp al,33h
                  je p3
               cmp al,34h
je p4
               cmp al,35h
je p5
jmp main
p1: disp msg3
lea dx,str1
mov ah,0Ah
int  21h
jmp main

p2: disp msg4
lea dx,str2
mov ah,0Ah
int  21h
jmp main
p3: call concat
                 jmp main

p4: call substring
                 jmp main

p5:          mov ah,4ch      
int 21h
              end

; PROGRAM 2


extrn str1
extrn str2
extrn msg5
extrn msg7
extrn msg8

public concat
public substring
disp macro msg
      lea dx,msg
       mov ah,09h
       int 21h
endm
.model small
.data
 count2 db ?
add_off dw ?
.code
concat proc far
disp msg5
lea si,str1
lea di,str2
inc si
inc di

mov cl,[si]
mov bl,[di]
mov ch,cl
up11: inc si
dec ch
jnz up11
inc si
inc di
mov bh,bl
up12: mov al,[di]
mov [si],al
inc si
inc di
dec bh
jnz up12

add bl,cl
lea si,str1
inc si
inc si


up13: mov dl,[si]
mov ah,02h
int 21h
inc si
dec bl
jnz up13
             
               ret
              endp

substring proc far
lea si,str1
lea di,str2
  inc si
inc di
               mov bl,00h
               mov cl,[si]
mov ch,[di]
mov count2,ch
sub cl,ch
add cl,01h
inc si
               inc di
up3: mov bh,[si]
cmp bh,[di]
  jne out1
  mov add_off,si
up1: mov bh,[si]
cmp bh,[di]
  jne out3
               inc si
inc di
dec ch
jnz up1
inc bl
out3: mov ch,count2
mov si,add_off
out1: inc si
                lea di,str2
                 inc di
inc di
dec cl
 jnz up3
               cmp bl,00h
                 jne down
                  disp msg7
                   jmp main1
down: disp msg8
         mov cx,0204h
again: rol bl,cl
      mov dl,bl
      and dl,0fh
      cmp dl,09h
      jbe skip
      add dl,07h
skip: add dl,30h
      mov ah,02h
      int 21h
      dec ch
      jnz again
   
     main1:      ret
      endp  
end  

 OUTPUT
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\student>cd\tasm

C:\tasm>tasm pg1.asm
Turbo Assembler  Version 2.0  Copyright (c) 1988, 1990 Borland International

Assembling file:   pg1.asm
Error messages:    None
Warning messages:  None
Passes:            1
Remaining memory:  440k


C:\tasm>tasm pg2.asm
Turbo Assembler  Version 2.0  Copyright (c) 1988, 1990 Borland International

Assembling file:   pg2.asm
Error messages:    None
Warning messages:  None
Passes:            1
Remaining memory:  441k


C:\tasm>tlink pg1 pg2
Turbo Link  Version 3.0 Copyright (c) 1987, 1990 Borland International
Warning: No stack

C:\tasm>pg1


MENU
1.Enter 1st string
2.Enter 2nd string
3.Concatenate
4.Substring
5.exit
Enter your choice:1
Enter the 1st string:kaka

MENU
1.Enter 1st string
2.Enter 2nd string
3.Concatenate
4.Substring
5.exit
Enter your choice:2
Enter the 2nd string:kaki

MENU
1.Enter 1st string
2.Enter 2nd string
3.Concatenate
4.Substring
5.exit
Enter your choice:3
Concatenate string is:kakakaki

MENU
1.Enter 1st string
2.Enter 2nd string
3.Concatenate
4.Substring
5.exit
Enter your choice:4
substring is not found

MENU
1.Enter 1st string
2.Enter 2nd string
3.Concatenate
4.Substring
5.exit
Enter your choice:5
C:\tasm>
read more

ALP for string operations

, by Prashant Gunjal



4. Write 8086 ALP for the following operations on the string entered by the user.

(a) Enter the string b) Calculate length of string c) Reverse string d) Check palindrome e) Exit


.model small
disp macro msg
lea dx,msg
mov ah,09h
int 21h
endm
.data
msg1 db 10,13,10,13,"MENU",10,13,"1.ENTER THE STRING",10,13,"2.LENGTH ",10,13,"3.REVERSE",10,13,"4.PALINDROME",10,13,"5.EXIT $"
msg2 db 10,13,"Enter your choice:$"
msg3 db 10,13,"Enter the string:$"
msg4 db 10,13,"Length of string is:$"
msg5 db 10,13,"Reverse of string is:   $"
msg6 db 10,13,"String is palindrome$"
msg7 db 10,13,"String is  not palindrome$"
str1 db 25,?,25 dup("$")
.code
mov ax,@data
mov ds,ax
main: disp msg1
disp msg2
mov ah,01h
int 21h
cmp al,31h
je p1
cmp al,32h
je p2
cmp al,33h
je p3
cmp al,34h
je p4
cmp al,35h
je p5
jmp main
p1: disp msg3
lea dx,str1
mov ah,0Ah
int 21h
jmp main
p2: mov bl,str1+1
disp msg4
call prin
jmp main
p3: mov bl,str1+1
mov cl,bl
lea dx,str1+2
mov di,dx
disp msg5
again1: inc di
dec cl
jnz again1
dec di
again2: mov dl,[di]
mov ah,02h
int 21h
dec di
dec bl
jnz again2
jmp main
p4: mov bl,str1+1
mov cl,bl
lea dx,str1+2
mov si,dx
mov di,dx
loop1: inc di
dec cl
jnz loop1
dec di
loop2: mov dl,[di]
mov dh,[si]
cmp dl,dh
jne outt
dec di
inc si
dec bl
jnz loop2
disp msg6
jmp main
outt: disp msg7
jmp main
p5: mov ah,4ch
int 21h

prin proc near
mov cx,0204h
up1: rol bl,cl
mov dl,bl
and dl,0fh
cmp dl,09h
jbe skip
add dl,07h
skip: add dl,30h
mov ah,02h
int 21h
dec ch
jnz up1
ret
endp

end

read more

ALP for HEX to BCD BCD to HEX

, by Prashant Gunjal



3. Write 8086 ALP to convert 4-digit Hex number into its equivalent BCD number and 5-digit BCD number into its equivalent HEX number. Make your program user friendly to accept the choice from user for: (a) HEX to BCD b) BCD to HEX (c) EXIT. Display proper strings to prompt the user while accepting the input and displaying the result.

; HEX to BCD no



.model small
  disp macro msg
         lea dx,msg
         mov ah,09h
            int 21h
    endm
.data
       msg1 db 10,13,"enter the hex no: $"
       msg2 db 10,13,"bcd no is: $"
       arr dw 10 dup(0)
 
.code
mov ax,@data
mov ds,ax
 disp msg1
   mov ah,01h
     int 21h
  sub al,30h
  cmp al,09h
  jbe  next1
  sub al,07h
next1:  mov bh,00h
              mov bl,al
              mov cl,0Ch
              rol bl,cl

 
  mov ah,01h
     int 21h
  sub al,30h
  cmp al,09h
  jbe  next2
  sub al,07h
next2: mov bh,00h
            mov bl,al
            mov cl,08h
             rol bl,cl

  mov ah,01h
     int 21h
  sub al,30h
  cmp al,09h
  jbe  next3
  sub al,07h
next3: mov bh,00h
            mov bl,al
            mov cl,04h
             rol bl,cl

  mov ah,01h
     int 21h
  sub al,30h
  cmp al,09h
  jbe  next4
  sub al,07h
next4: mov bh,00h
             mov bl,al

       lea si,arr
       mov ax,bx
       mov dx,0000h
       mov bx,03E8h
       div bx

        mov [si],ax
        inc si
        inc si

       mov ax,dx
       mov dx,0000h
       mov bx,064h
       div bx

       mov [si],ax
       inc si
       inc si
     
     
 mov ax,dx
       mov dx,0000h
       mov bx,0Ah
       div bx

       mov [si],ax
       inc si
       inc si  

 mov ax,dx
       mov dx,0000h
       mov bx,01h
       div bx

       mov [si],ax

lea si,arr

mov ax,[si]
mov cl,0Ch
rol  ax,cl
mov bx,ax
inc si
inc si

mov ax,[si]
mov cl,08h
rol  ax,cl
add bx,ax
inc si
inc si

mov ax,[si]
mov cl,04h
rol  ax,cl
add bx,ax
inc si
inc si

mov ax,[si]
add bx,ax  

disp msg2
 
mov cx,0204h
mov dh,bh

up1: rol dh,cl
         mov dl,dh
         and dl,0fh
         cmp dl,09h
         jbe next5
         add dl,07h
next5: add dl,30h

          mov ah,02h
           int 21h  
         
           dec ch
            jnz up1

mov cx,0204h
mov dh,bl

up2: rol dh,cl
         mov dl,dh
         and dl,0fh
         cmp dl,09h
         jbe next6
         add dl,07h
next6: add dl,30h

          mov ah,02h
           int 21h  
         
           dec ch
            jnz up2

mov ah,04ch
int 21h
end

;BCD to HEX


.model small
.data
msg1 db 10,13,"Enter 5 digit BCD No: $"
msg2 db 10,13,"The equivalent hex No. is: $"
arr dw 5 dup(0)

.code
mov ax,@data
mov ds,ax

lea dx,msg1
mov ah,09h
 int 21h

lea si,arr

mov ah,01h
int 21h

sub al,30h
mov ah,00h
mov bx,2710h
mul bx
mov [si],ax
inc si
inc si

mov ah,01h
int 21h

sub al,30h
mov ah,00h
mov bx,03E8h
mul bx
mov [si],ax
inc si
inc si

mov ah,01h
int 21h

sub al,30h
mov ah,00h
mov bx,0064h
mul bx
mov [si],ax
inc si
inc si

mov ah,01h
int 21h

sub al,30h
mov ah,00h
mov bx,000Ah
mul bx
mov [si],ax
inc si
inc si

mov ah,01h
int 21h

sub al,30h
mov ah,00h
mov bx,01h
mul bx
mov [si],ax
inc si
inc si

lea si,arr
mov bx,[si]
inc si
inc si
mov ch,04h

up: add bx,[si]
       inc si
       inc si
       dec ch
        jnz up

lea dx,msg2
mov ah,09h
int 21h

mov cx,0204h
mov dh,bh

up1: rol dh,cl
         mov dl,dh
         and dl,0fh
         cmp dl,09h
         jbe next1
         add dl,07h
next1: add dl,30h

          mov ah,02h
           int 21h  
         
           dec ch
            jnz up1

mov cx,0204h
mov dh,bl

up2: rol dh,cl
         mov dl,dh
         and dl,0fh
         cmp dl,09h
         jbe next2
         add dl,07h
next2: add dl,30h

          mov ah,02h
           int 21h  
         
           dec ch
            jnz up2

mov ah,04ch
int 21h
end

read more

ALP to perform non-overlapped and overlapped block transfer

, by Prashant Gunjal



2. Write 8086 ALP to perform non-overlapped and overlapped block transfer (with and without string specific instructions). Block containing data can be defined in the data segment.


;ALP to perform NON-overlapped block transfer

.model small
.data
msg1 db 10,13 ,"enter size of array:$"
msg2 db 10,13,"enter the array elements: $"
msg3 db 10,13,"second array elements are: $"
arr1 db 10 dup(0)
arr2 db 10 dup(0)
cnt db 1 dup(0)
.code
mov ax,@data
mov ds,ax
mov es,ax
     lea dx,msg1
mov ah,09h
int 21h
mov ah,01h
int 21h
sub al,30h
cmp al,09h
jbe next
sub al,07h
next:         mov cnt,al
mov ch,cnt
mov bl,cnt
lea si,arr1
mov cl,04h
l1: lea dx,msg2
mov ah,09h
int 21h    mov ah,01h
int 21h
sub al,30h
cmp al,09h
jbe l2
sub al,07h
l2: mov bh,al
rol bh,cl
mov ah,01h
int 21h
sub al,30h
cmp al,09h
jbe l3
sub al,07h
l3: add bh,al
mov [si],bh
inc si
dec ch
jnz l1
  l4: mov cl,cnt
        mov ch,00h
        lea si,arr1
        lea di,arr2
cld
rep movsb
    lea dx,msg3
mov ah,09h
int 21h
    lea di,arr2
mov bl,cnt

up2: mov cx,0204h
        mov dh,[di]
up: rol dh,cl
mov dl,dh
and dl,0fh
cmp dl,09h
jbe l5
add dl,07h
l5: add dl,30h
mov ah,02h
int 21h
                   dec ch
  jnz  up
               mov dl,' '
      mov ah,02h
int 21h
         inc di
dec cnt
jnz up2                  
      mov ah,04ch
int 21h
end
  
output
 
C:\tasm>tasm non.asm
Turbo Assembler  Version 2.0  Copyright (c) 1988, 1990 Borland International
Assembling file:   non.asm
Error messages:    None
Warning messages:  None
Passes:            1
Remaining memory:  475k

C:\tasm>tlink non
Turbo Link  Version 3.0 Copyright (c) 1987, 1990 Borland International

Warning: No stack
C:\tasm>non
enter size of array:5
enter the array elements: 01
enter the array elements: 02
enter the array elements: 03
enter the array elements: 04
enter the array elements: 05
second array elements are: 01 02 03 04 05
C:\tasm>

;ALP to perform overlapped block transfer


.MODEL SMALL

.DATA
        ARR1 DB 10 DUP(0)
        ;ARR2 DB 5 DUP(0)
        COUNT DB 1 DUP(0)
        OV_COUNT DB 1 DUP(0)

        MSG1 DB 10,13,"ENTER SIZE:-$"
        MSG2 DB 10,13,"ENTER NO:-$"
        MSG3 DB 10,13,"ENTER OVELAPED COUNT:-$"
        MSG4 DB 10,13,"ARRAY IS COPIED$"
        MSG5 DB 10,13,"NEW ARRAY:-$"

.CODE
        MOV AX,@DATA
        MOV DS,AX
        MOV ES,AX

        LEA DX,MSG1
        MOV AH,09H
        INT 21H

        MOV AH,01H
        INT 21H

        SUB AL,30H
        CMP AL,09H
        JBE L
        SUB AL,07H

     L:MOV COUNT,AL

        MOV CL,COUNT
        LEA SI,ARR1

     L1:LEA DX,MSG2
        MOV AH,09H
        INT 21H

        MOV AH,01H
        INT 21H

        SUB AL,30H
        CMP AL,09H
        JBE L2
        SUB AL,07H

     L2:MOV DL,CL
        MOV CL,04H
        MOV BH,AL

        ROL BH,CL

        MOV CL,DL
        MOV AH,01H
        INT 21H

        SUB AL,30H
        CMP AL,09H
        JBE L3
        SUB AL,07H

     L3:ADD BH,AL
        MOV [SI],BH
        INC SI
        LOOP L1


        LEA DX,MSG3
        MOV AH,09H
        INT 21H

        MOV AH,01H
        INT 21H

        SUB AL,30H
        CMP AL,09H
        JBE N
        SUB AL,07H




      N:MOV OV_COUNT,AL
MOV BH,COUNT
        MOV DH,OV_COUNT

        LEA SI,ARR1    ;MOVE OFFSET OF ARR1 TO SI REG.
        LEA DI,ARR1    ;MOVE OFFSET OF ARR1 TO DI REG.

        MOV CL,BH
     L4:
        INC SI


        DEC CL
        JNZ L4        ;INCREMENT SI BY 1
               
        DEC SI         ;DECREMENT SI BY 1

        MOV DI,SI      ;MOVE SI TO DI

        MOV CL,DH

     L5:INC DI         ;INCREMENT DI BY 1
        DEC CL
        JNZ L5

        MOV CH,00H
        MOV CL,COUNT

        STD

        REP MOVSB      ;TRANSFER CONTAINS OF SI TO DI BYTE BY BYTE
                       ;REPEAT MOVSB INSTRUCTION UNTIL CX IS NOT 0
        DEC DI
        MOV BH,OV_COUNT
        LEA SI,ARR1
        MOV AL,00H

     L6:MOV [SI],AL
        INC SI
        DEC BH
        JNZ L6
       
        LEA DX,MSG4
        MOV AH,09H
        INT 21H

        LEA SI,ARR1

        MOV CL,COUNT

        ADD CL,OV_COUNT

        LEA DX,MSG5
        MOV AH,09H
        INT 21H


        MOV CH,COUNT
        ADD CH,OV_COUNT
LEA SI,ARR1

     L7:MOV CL,04H
        MOV BL,[SI]
        ROL BL,CL
        AND BL,0FH

        MOV DL,BL
        CMP DL,09H
        JBE L8

        ADD DL,07H

     L8:ADD DL,30H
        MOV AH,02H
        INT 21H

        MOV BL,[SI]
        AND BL,0FH
        MOV DL,BL
        CMP DL,09H

        JBE L9

        ADD DL,07H
     L9:ADD DL,30H
        MOV AH,02H ;DISPLAY ARRAY
        INT 21H

        INC SI

        DEC CH
        JNZ L7


   EXIT:MOV AH,4CH
        INT 21H

END


OUTPUT:-

Turbo Assembler  Version 2.0  Copyright (c) 1988, 1990 Borland International

Assembling file:   OM241.ASM
Error messages:    None
Warning messages:  None
Passes:            1
Remaining memory:  441k


C:\tasm>TLINK OM241.OBJ
Turbo Link  Version 3.0 Copyright (c) 1987, 1990 Borland International
Warning: No stack

C:\tasm>OM241

ENTER SIZE:-5
ENTER NO:-11
ENTER NO:-12
ENTER NO:-13
ENTER NO:-14
ENTER NO:-15
ENTER OVELAPED COUNT:-3
ARRAY IS COPIED
NEW ARRAY:-00 00 00 11 12 13 14 15
C:\tasm>
read more

ALP to add array of N hexadecimal numbers stored in the memory. Accept input from the user

, by Prashant Gunjal


1. Write 8086 Assembly language program (ALP) to add array of N hexadecimal numbers stored in the memory. Accept input from the user.


.model small
.data
msg1 db 10,13,"Enter size of array:$"
msg2 db 10,13,"Enter two bit no:$"
msg3 db 10,13,"addtion:$"
arr db 10h dup(?)
n1 db 00h
.code

mov ax,@data
mov ds,ax ;store contents of ax in DS

lea dx,msg1 ;display msg1
mov ah,09h
int 21h

mov ah,01h ;accept the number of elements in array
int 21h

sub al,30h ;subtract 30 from al
cmp al,09h
jbe l4
sub al,07h

l4:
lea si,arr ;stores array contents in si
mov ch,al ;move contents in ch
mov n1,ch ;move ch in n1

l2:
lea dx,msg2 ;display msg 1
mov ah,09h
int 21h

mov ah,01h ;accept 1st number
int 21h

sub al,30h ;subtract 30 from al
cmp al,09h
jbe l5

sub al,07h
l5:
mov bh,al ;mov al contents in bh

mov ah,01h ;accept 2nd number
int 21h

sub al,30h ;subtract 30 from al
cmp al,09h
jbe l6
sub al,07h

l6:
mov bl,al ;mov al content in bl
mov cl,04h ;cl is counter having value 4

rol bh,cl ;rotate bh contents 4 times
add bh,bl ;mov bl contents to bh
mov[si],bh ;mov bh in si offset
inc si

dec ch
jnz l2 ;jump if not zero

lea dx,msg3 ;display msg 3
mov ah,09h
int 21h

mov ch,n1 ;mov n1 to ch
lea si,arr ;mov array content in si
mov bh,[si] ;mov si data to bh

l3: inc si
add bh,[si] ;add si to bh
dec ch
jnz l3 ;jump till ch is zero

mov cx,0204h ;cx is counter

l1: rol bh,cl ;rotate bh contents 4 times
mov bl,bh ;mov bh in bl
and bh,0fh ;anding bh of times
mov dl,bh ;mov bh in dl

cmp dl,09h
jbe l7
add dl,07h
l7: add dl,30h

mov ah,02h ;display number
int 21h

mov bh,bl ;mov bl in bh
dec ch
jnz l1

mov ah,4ch ;termination
int 21h
end

#### Output ###

C:\TASM>tasm ass1.asm
Turbo Assembler  Version 2.0  Copyright (c) 1988, 1990 Borland International

Assembling file:   ass1.asm
Error messages:    None
Warning messages:  None
Passes:            1
Remaining memory:  476k


C:\TASM>tlink ass1.obj
Turbo Link  Version 3.0 Copyright (c) 1987, 1990 Borland International
Warning: No stack

C:\TASM>ass1

Enter size of array:2
Enter two bit no:2C
Enter two bit no:3A
addtion:66
C:\TASM>
read more