Wednesday, March 19, 2014

MPP experiment 6

EXP6-part 1
Programme to transfer string from ds to es
.model small
.stack 10h
data segment
array db 02h, 04h , 06h, 07h , 10h
array_cpy db 10 dup (?)
data ends
code segment
assume cs:code,ds:data
start :
                                mov ax,data
                                mov ds,ax
                                mov es,ax
                                xor ax,ax
                                mov si,offset array
                                mov di,offset array_cpy
                                mov cx,04h
                       rep movsb
                                mov ax,4c00h
                                int 21h
code ends
        end start
EXP 6-B
Programme to swap a string
.model small
.stack 10h
data segment
        array db 01h, 02h, 03h, 04h, 05h
        array_rev db 5 dup (?)
data ends
code segment
        assume cs:code,ds:data
        start :
                                mov ax,data
                                mov ds,ax
                                mov es,ax
                                xor ax,ax
                                mov si,offset array
                                mov di, offset array + 04h
                                mov cx,02h
        repeat : mov al,[si]
                                xchg al,[di]
                                xchg al,[si]
                                inc si
                                dec di
                                loop repeat
                                mov ax,4c00h
                                int 21h
code ends
        end start
Exp6c
Programme to serch an element in a string
Algorithm: Linear Search
.model small
.stack 10h
data segment
        array db 01h, 02h, 03h, 04h, 05h
        msg1 db 13,10, "KEY NOT FOUND$"
        msg2 db 13,10, "KEY FOUND$"
data ends
code segment
        assume cs:code,ds:data
        start :
                                mov ax,data
                                mov ds,ax
                                mov es,ax
                                xor ax,ax
                                mov di,offset array
                                mov ax,0700h
                                int 21h ; dos int for accepting an i/p
                                sub al,30h
                                mov cx,05h
                                cld
                      repne scasb ; search a string
                                cmp cx,00h
                                je not_found
                                mov bx,offset array + 04h
                                sub bx,cx ; bx contains the addr of key
                                mov dx,offset msg2
        print : mov ax,0900h
                                int 21h ; dos int for displaying the o/p
                                mov ax,4c00h
                                int 21h
        not_found : mov dx,offset msg1
                                jmp print
code ends
        end start

Here is the link to download algorithms, flowcharts and answers:

0 comments:

Post a Comment