Top Banner
PART A ; to generate FIBONACCI series(11A) .model small .stack 200 .data n dw 6 fib db 30 dup(?) .code mov ax,@data ; initialization of data segment mov ds,ax ; inside the code segment lea si,fib mov [si],0 ;initializing first number mov [si+1],1 ;initializing second number mov cx,n sub cx,2 back: mov al,[si] add al,[si+1] ; adding first & second number mov [si+2],al ; storing at as third number inc si loop back int 3 ; break point interrupt end BNMIT/CSE/Mp Lab Manual 1
67

Mup Lab Manual

Sep 16, 2015

Download

Documents

Rohmah Fitri

microprocessor lab manual 4th sem vtu cs
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript

PART A; to generate FIBONACCI series(11A).model small

.stack 200

.data

n dw 6

fib db 30 dup(?)

.code

mov ax,@data

; initialization of data segment mov ds,ax

; inside the code segment lea si,fib mov [si],0

;initializing first number mov [si+1],1

;initializing second number mov cx,n

sub cx,2

back:

mov al,[si]

add al,[si+1]

; adding first & second number mov [si+2],al

; storing at as third number inc si

loop back

int 3

; break point interruptend; sort the no using bubble sort(3A).model small

.stack 200

.data

a db 23h,43h,12h,55h,11h

len dw ($-a)

.code

mov ax,@data

; initialization of data segment

mov ds,ax

; inside code segment

mov bx,len

; outer loop from 0 to n-1

dec bx

outl:

mov cx,bx

; inner loop from 0 to outer loop

mov si,0

inl:

mov al,a[si]

inc si

cmp al,a[si]

; comparison of 2 elements

jb next

xchg al,a[si]

; if greater exchange

mov a[si-1],al

next:

loop inl

dec bx

jnz outl

mov ah,4ch

; interrupt to end the code segment

int 21h

end

;Binary Search-1A.model small

.stack 200

.data

a dw 1111h,3333h,5555h,7777h,9999h

len dw ($-a)/2

key dw 2333h

msg1 db 10,13,'successful search','$'

msg2 db 10,13,'Unsuccessful search','$'

.code

mov ax,@data

; Initialization of Data Segment

mov ds,ax

; Inside Code Segment

mov ax,key

; ax = Search key

mov si,0

; si = low

mov di,len

; di = high

dec di

again:

cmp si,di

; low > high

ja notfound

mov bx,si

add bx,di

; bx = low + high

shr bx,01

; bx = mid

mov bp,bx

shl bx,01

; pointer adjustment

cmp ax,a[bx]

; Searching for key element

je found

; mid = key

jc midbig

inc bp

; si(low) = mid + 1

mov si,bp

jmp again

midbig:

dec bp

; di (high) = mid - 1

mov di,bp

jmp again

found:

lea dx,msg1

jmp exit

notfound:

lea dx,msg2

exit:

mov ah,09h

; interrupt to display the

int 21h

; message

mov ah,4ch

; interrupt to end the

int 21h

; program

end

; linking of 2 macros which are (2A) included as library files with

include c:\masm\jalaja\2a1.mac

include c:\masm\jalaja\2a2.mac

.model small

.stack 200

.data

msg db 10,13,"enter the data end with enter key",'$'

a db 10 dup(?)

.code

mov ax,@data

; initialization of data segment

mov ds,ax

; inside code segment

lea dx,msg

; interrupt to print

mov ah,09h

; the message

int 21h

mov si,0

again:

read

; macro to accept i/p

cmp al,13

; till ENTER key is pressed

je disp

mov a[si],al

inc si

jmp again

disp:

mov dl,0ah

; interrupt to move the

mov ah,02

; cursor to next line

int 21h

mov cx,si

mov si,0

begin:

mov dl,a[si]

writ

; macro to print a character

inc si

loop begin

mov ah,4ch

int 21h

end

;------2a1.mac------

read macro

mov ah,01

; interrupt to accept i/p

int 21h

endm

;-----2a2.mac------

writ macro

mov ah,02

; interrupt to print a character

int 21h

endm

; Factorial of a number using(8a)

; recursive approach

.model small

.stack 200

.data

n dw 4

res dw ?

.code

mov ax,@data

; initialization of data segment

mov ds,ax

; inside code segment

mov ax,n

call fact

; procedure finding the factorial

int 3

; break point interrupt

;---factorial procedure---

fact proc

cmp ax,00

je exit

push ax

dec ax

call fact

; procedure called recursively

pop ax

mul res

mov res,ax

ret

exit:

mov res,1

ret

fact endp

end

; 9A Write an ALP to compute NCR using recursive procedure

; nCr = (nC(r-1) * (n+1-r))/r

.model small

.stack 200

.data

n dw 4

r dw 2

n dw ?

.code

mov ax,@data

mov ds,ax

mov ax,n

mov bx,r call ncrrecRA1: mov ah,4ch

int 21h

ncrrec proc

cmp bx,0

je exit

push ax

push bx

dec bx

call ncrrec

RA2:

pop bx

pop ax

inc ax

; n+1

sub ax,bx

; n+1-r

mul ncr

;ax