Вы находитесь на странице: 1из 30

15CSL48 Microprocessor and microcontroller lab

SOFTWARE PROGRAMS: PART A

1. Design and develop an assembly language program to search a key element X in a list
of n 16-bit numbers. Adopt Binary search algorithm in your program for searching.

.model small
.stack
.data

arr dw 0111h,0112h,0113h,0114h,0115h
len dw ($-arr)/2
key equ 0116h
msg1 db key element is found $
msg2 db key element is not found $

.code
mov ax,@data
mov ds,ax

mov bx,00h
mov dx,len
mov cx,key

again: cmp bx,dx


ja notfnd
mov ax,bx
add ax,dx
shr ax,1
mov si,ax
dec si
add si,si
cmp cx,arr[si]
jae big

dec ax
mov dx,ax
jmp again

big: je found
inc ax
mov bx,ax
jmp again

found: lea dx,msg1


mov ah,09h
int 21h
jmp displ

SJMIT CSE DEPARTMENT Page 1


PREPARED BY: Nandini GR
15CSL48 Microprocessor and microcontroller lab

notfnd: lea dx,msg2


mov ah,09h
int 21h

displ: mov ah,4ch


int 21h
end

Conclusion:

This program performs a search for a key element in an array. If the search element is
found it will display a message found. As the search element (key element in program) is not
present in the given array it will display a message not found.

SJMIT CSE DEPARTMENT Page 2


PREPARED BY: Nandini GR
15CSL48 Microprocessor and microcontroller lab

2. Design and develop an assembly program to sort a given set of n 16-bit numbers in
ascending order. Adopt Bubble Sort algorithm to sort given elements.

.model small
.stack
.data

array db 13h,21h,12h,15h,10h
len db ($-array)

.code
mov ax,@data
mov ds,ax
mov dl,len
dec dl

back: lea si,array


mov cl,dl
mov ch,00h

again: mov bl,[si]


mov al,[si+1]
cmp bl,al
jc l1
xchg bl,al
mov [si],bl
mov [si+1],al

l1: inc si
loop again
dec dl
jnz back
mov ah,4ch
int 21h
end

Conclusion:

This program will sort the given numbers in ascending order. The sorted numbers will be
stored directly in the data Segment. To view the data segment the following code must be used.

-d ds: 0

SJMIT CSE DEPARTMENT Page 3


PREPARED BY: Nandini GR
15CSL48 Microprocessor and microcontroller lab

3. Develop an assembly language program to reverse a given string and verify whether it is
a palindrome or not. Display the appropriate message.

.model small
.data
.stack

str1 db alam
slen equ ($-str1)
str2 db 40 dup(0)
msg1 db string is palindrome $
msg2 db string is not palindrome $

.code
start: mov ax,@data
mov ds,ax
mov es,ax

mov cx,slen
lea si,str1
add si,slen-1
lea di,str2

up: mov al,[si]


mov [di],al
dec si
inc di
loop up
lea si,str1
lea di,str2
mov cx,slen
cld

repe cmpsb
jne down
lea dx,msg1
mov ah,09h
int 21h
jmp down1

down: lea dx,msg2


mov ah,09h
int 21h

SJMIT CSE DEPARTMENT Page 4


PREPARED BY: Nandini GR
15CSL48 Microprocessor and microcontroller lab

down1: mov ah,4ch


int 21h
end

Conclusion:

This program reverse the string provided in data segment by keeping the original
string as it is and compares both the strings. It will check each and every character. If all the
characters are same then the given string is said to be as palindrome and it will display a message
palindrome on screen otherwise the given string is not palindrome and it will display a
message not palindrome on screen.

SJMIT CSE DEPARTMENT Page 5


PREPARED BY: Nandini GR
15CSL48 Microprocessor and microcontroller lab

4. Develop an assembly language program to compute nCr using recursive procedure.


Assume that n and r are non-negative integers

.model small
.data

n.dw 03h
r dw 02h
ncr dw ?

.code
mov ax,@data
mov ds,ax

mov ncr,00h
mov ax,n
mov bx,r

call ncrproc
mov dx,ncr
mov ah,4ch
int 21h

ncproc proc
cmp ax,bx
je res1

cmp bx,00h
je res1

cmp bx,01h
je resn

dec ax
cmp ax,bx
je res2

push ax
push bx
call ncrproc

SJMIT CSE DEPARTMENT Page 6


PREPARED BY: Nandini GR
15CSL48 Microprocessor and microcontroller lab

pop bx
pop ax
dec bx

push ax
push bx
call ncrproc
pop bx
pop ax
ret

res1: inc ncr


ret
res2: inc ncr
resn: add ncr,ax
ret
ncrproc endp
end

Conclusion:

This program performs nCr using recursive procedure. Output is stored in data segment.
To observe the output in data segment we have to search for our given n and r values as
program is written to store the result after the given data in data segment.

SJMIT CSE DEPARTMENT Page 7


PREPARED BY: Nandini GR
15CSL48 Microprocessor and microcontroller lab

5. Design and develop an assembly language program to read the current time and Date
from the system and display it in the standard format on the screen.

.model small
.stack
.data
msg db the date is :
days db ?,?,:
months db ?,?,:
years db ?,?,(dd:mm:yy),10,13,$

msg1 db the time is :


hrs db ?,?,:
mins db ?,?,:
secs db ?,?,(hh:mm:ss),10,13,$

.code
Start: mov ax,@dara
mov ds,ax
mov ah,2ah
int 21h
mov al,dl
aam

add ax,3030h
mov days,ah
mov days+1,al

mov al,dh
aam
add dx,3030h
mov months,ah
mov months+1,al

add cx,0f830h
mov al,cl
aam
add ax,3030h
mov years,ah
mov years+1,al

SJMIT CSE DEPARTMENT Page 8


PREPARED BY: Nandini GR
15CSL48 Microprocessor and microcontroller lab

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

mov ah,2ch
int 21h

mov al,ch
aam
add ax,3030h
mov hrs,ah
mov hrs+1,al

mov al,cl
aam
add ax,3030h
mov mins,ah
mov mins+1,al

mov al,dh
aam
add ax,3030h
mov secs,ah
mov secs+1,al

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

mov ah,4ch
int 21h
end start

Conclusion: this program displays the present system time and date.

SJMIT CSE DEPARTMENT Page 9


PREPARED BY: Nandini GR
15CSL48 Microprocessor and microcontroller lab

6. To write and simulate ARM assembly language programs for data transfer, arithmetic
and logical operations (Demonstrate with the help of a suitable program).

1. ADDITION PROGRAM

AREA ADDITION , CODE , READONLY ; name this block of code as ADDITION.


EXPORT ADD32

ADD32
LDR R0,=0X8234E640 ; Load R0= 0X8234E640
LDR R1,=0X13210010 ; Load R1= 0X13210010
LDR R2,=0X12348900 ; Load R2= 0X12348900
LDR R3,=0X43212102 ; Load R3= 0X43212102
ADD R4,R0,R1 ; R4=R0+R1
ADC R5,R2,R3 ; R5=R2+R3
BX LR
END

OUTPUT:
R4=0X9555E650
R5=0X5555AA02

SJMIT CSE DEPARTMENT Page 10


PREPARED BY: Nandini GR
15CSL48 Microprocessor and microcontroller lab

2. SUBTRACTION PROGRAM

AREA SUBTRACT , CODE , READONLY


EXPORT SUB32
SUB32
LDR R0,=0X8334F750 ; Load R0= 0X83210010
LDR R1,=0X8234E640 ; Load R1= 0X8234E640
LDR R2,=0X43212102 ; Load R2= 0X43212102
LDR R3,=0X12348900 ; Load R3= 0X12348900
SUB R4,R0,R1 ; R4=R0-R1
SUB R5,R2,R3 ; R5=R2-R3

BX LR
END

OUTPUT:
R4=0x01001110
R5=0x30EC9801

3. MULTIPLICATION PROGRAM

AREA MULTIPLY , CODE , READONLY


EXPORT MULTI
MULTI

LDR R0,=0X706F ; Load R0= 0X706F


LDR R1,=0X716E ; Load R1= 0X716E
MUL R2,R1,R0 ;R2=R1*R2

BX LR
END

OUTPUT:
R2=0X31D14EB2

SJMIT CSE DEPARTMENT Page 11


PREPARED BY: Nandini GR
15CSL48 Microprocessor and microcontroller lab

4. DIVISION PROGRAM
AREA DIVISION , CODE , READONLY
EXPORT DIV
DIV
LDR R0,=0X0002 ; Load R0=0X0002 (Divisor)
LDR R1,=0X0008 ; Load R1=0X0008 (Dividend)
L1 SUB R1, R1,R0 ; R1=R1-R0
ADD R2,#1 ; R2=+1
CMP R1,R0 ;IF R1>R0 Jump to label L1 else end
BGE L1 ; Remainder in R1, Quotient in R2.
END

OUTPUT:
R1=0X00000000 (REMAINDER)
R2=0X00000004 (QUOTIENT)

5. DATATRANSFER PROGRAM

AREA DATAMOV , CODE , READONLY


EXPORT DATA
DATA
LDR R1,=VALUE1 ; Loads The Address Of First Value to R1
LDR R2,[R1] ; load the value at the address of R1 to R2
LDR R1,=VALUE2 ; Loads The Address Of second Value
LDR R3,[R1] ; load the value at the address of R1 to R3
ADD R0,R3,R2 ; R4=R3 + R2
LDR R4,=RESULT ; Loads The Address Of Result
STR R0,[R4] ; Stores The Result In R0 And Att Memory stored in R4

VALUE1 DCD 0X55AAAA55


VALUE2 DCD 0X5555AA55
AREA DATA2, DATA, READWRITE ; To Store Result In Given Address
RESULT DCD 0X0
END ; Mark end of program

SJMIT CSE DEPARTMENT Page 12


PREPARED BY: Nandini GR
15CSL48 Microprocessor and microcontroller lab

OUTPUT:

memory window1
type 0x40000000
0X40000000: AA 54 00 AB

LOGICAL INSTRUCTION PROGRAM


AREA LOGICAL , CODE , READONLY
EXPORT LOGIC
LOGIC
LDR R0,=0X00001234 ; Load R0=0X00001234
LDR R1,=0X00004567 ; Load R0=0X00004567
MVN R2,R0 ;R2=~R0
AND R3,R0,R1 ;R3=R0 & R1
ORR R4,R0,R1 ;R4=R0| R1
EOR R5,R0,R1 ;R5=R0 ^ R1
BX LR
END

OUTPUT:
R2=0XFFFFEDCB ;NOT operation result
R3=0X00000024 ;AND operation result
R4=0X00005777 ;OR operation result
R5=0X00005753 ;XOR operation result

SJMIT CSE DEPARTMENT Page 13


PREPARED BY: Nandini GR
15CSL48 Microprocessor and microcontroller lab

7. To write and simulate C Programs for ARM microprocessor using KEIL (Demonstrate
with the help of a suitable program)

ARITHMETIC OPERATION PROGRAM LOGICAL INSTRUCTION PROGRAMS

#include<lpc21xx.h> #include<lpc21xx.h>

int main(void) int main(void)


{ {
int a=6,b=2; int a=6,b=2;
unsigned int sum,sub,mul,div; unsigned int and,or,exor,not ;
and =a&b;
sum =a+b; exor=a^b;
sub =a-b; or=a|b;
mul =a*b; not =~a;
}
}

OUTPUT:
OUTPUT:
R1=0x00000006 ;a value in R1
R1=0x00000006 ;a value in R1
R2=0x00000002 ;b value in R2
R2=0x00000002 ;b value in R2
R3=0X00000002 ;AND operation
R3=0X00000008 ;Sum value in R3 result
R12=0X00000004 ; Sub value in R12 R4=0X00000004 ;XOR operation
R4=0X0000000C ;mul value in R4 result
R5=0XFFFFFFF9 ;NOT operation result
R12=0X00000006 ;OR operation result

SJMIT CSE DEPARTMENT Page 14


PREPARED BY: Nandini GR
15CSL48 Microprocessor and microcontroller lab

HARDWARE PROGRAMS: PART B

8. a. Design and develop an assembly program to demonstrate BCD Up-Down Counter (00-99)
on the Logic Controller Interface.

.model small
.stack
.data

mov al,80h
mov dx,1103h
out dx,al
mov al,00h

l1: mov dx,1100h


out dx,al
call delay
add al,01h
daa
cmp al,99h
je l2
jmp l1

l2: mov dx,1100h


out dx,al
call delay
sub al,01h
das
cmp al,00h
das
cmp al,00h
je l3
jmp l2

l3: mov ah,4ch


int 21h
delay proc
push ax
push cx

SJMIT CSE DEPARTMENT Page 15


PREPARED BY: Nandini GR
15CSL48 Microprocessor and microcontroller lab

mov cx,0ffffh
b2: mov ax,0ffffh
b1: dec ax
jnz b1
loop b2
pop cx
pop ax
ret
delay endp
end

SJMIT CSE DEPARTMENT Page 16


PREPARED BY: Nandini GR
15CSL48 Microprocessor and microcontroller lab

Output: interface used : logic controller

Allowio 0x1100h
Masm/zi updown;
Link/co updown;
updown

In logic controller interface

Status of output LEDS (red)will be

PA7 PA6 PA5 PA4 PA3 PA2 PA1 PA0 BCD equivalent
0 0 0 0 0 0 0 0 00
0 0 0 0 0 0 0 1 01
0 0 0 0 0 0 1 0 02
0 0 0 0 0 0 1 1 03 up counter (00-99)
|
|

1 0 0 1 1 0 0 1 99

1 0 0 1 1 0 0 0 98 down counter (99-00)


1 0 0 1 0 1 1 1 97
|
|
0 0 0 0 0 1 0 0 04
0 0 0 0 0 0 0 0 00

SJMIT CSE DEPARTMENT Page 17


PREPARED BY: Nandini GR
15CSL48 Microprocessor and microcontroller lab

8. b. Design and develop an assembly program to read the status of two 8-bit inputs (X & Y)
from the Logic Controller Interface and display X*Y.

display macro msg


lea dx,msg
mov ah,09h
int 21h
endm

.model small
.stack
.data

m1 db 10,13,set value of x:$


m2 db 10,13,set the value of y:$

.code
mov ax,@data
mov ds,ax

mov dx,1103h
mov al,8ah
out dx,al
display m1
mov ah,08h
int 21h

mov dx,1101h
in al,dx
mov bl,al
display m2
mov ah,08h
int 21h

mov dx,1101h
in al,dx
mul bl

mov dx,1100h

SJMIT CSE DEPARTMENT Page 18


PREPARED BY: Nandini GR
15CSL48 Microprocessor and microcontroller lab

out dx,al
call delay
mov al,ah

mov dx,1100h
out dx,al
mov ah,4ch
int 21h

delay proc
mov si,0ffffh

l2: mov di,0ffffh


l1: dec di
jnz l1
dec si
jnz l2
ret
delay endp
end

SJMIT CSE DEPARTMENT Page 19


PREPARED BY: Nandini GR
15CSL48 Microprocessor and microcontroller lab

Output: interface used: logic controller


allowio 0x1100h
Masm/zi multi;
Link/co multi;
Multi

Set the value of x:


In logic controller set the value of x as 00000010

Set the value of y:


In logic controller set the value of y as 00000010

In logic controlle the status of red color LEDs wil be 00000100

Similarly for x=00000100


y= 00000010

the output will be 00010000

SJMIT CSE DEPARTMENT Page 20


PREPARED BY: Nandini GR
15CSL48 Microprocessor and microcontroller lab

9. Design and develop an assembly program to display messages FIRE and HELP
alternately with flickering effects on a 7-segment display interface for a suitable period of
time. Ensure a flashing rate that makes it easy to read both the messages (Examiner does not
specify these delay values nor is it necessary for the student to compute these values).

.model small
.stack
.data

F db 00h,00h,79h,77h,06h,71h
H db 73h,38h,79h,76h,00h,00h

.code
mov ax,@data
mov ds,ax

mov al,80h
mov dx,1103h
out dx,al
mov bp,0ah

Z: mov bx,0fffh
R: mov si,00h
mov cl,00h

up: mov al,cl


mov dx,1102h
out dx,al
mov al,F[si]
mov dx,1100h
out dx,al
call delay
inc cl
inc si
cmp si,06h
jnz up
dec bx
jnz R
mov bx,0fffh

SJMIT CSE DEPARTMENT Page 21


PREPARED BY: Nandini GR
15CSL48 Microprocessor and microcontroller lab

A: mov di,00h
mov cl,00h

B: mov al,cl
mov dx,1102h
out dx,al
mov al,H[di]
mov dx,1100h
out dx,al
call delay
inc cl
inc di
cmp di 06h
jnz B
dec bx
jnz A
dec bp
jnz Z
mov ah,4ch
int 21h
delay procnear
push cx
push dx
mov cx,0ffh

l2: mov dx,0ffh


l1: dec dx
jnz l1
loop l2
pop dx
pop cx
ret
delay endp
end

SJMIT CSE DEPARTMENT Page 22


PREPARED BY: Nandini GR
15CSL48 Microprocessor and microcontroller lab

Output:
Interface used multiplexed seven segment display

Allowio 0x1100h
Masm/zi fire;
Link/co fire;
Fire

In seven segment display the messages FIRE and HELP will be displayed alternately with
flickering effects.

To write the hexadecimal code for alphabets.

h g f e d c b a
0 1 1 1 0 0 0 1 (71h=F)
0 0 0 0 0 1 1 0 (06h=I)
0 1 1 1 0 1 1 1 (77h=R)
0 1 1 1 1 0 0 1 (79h=E)

SJMIT CSE DEPARTMENT Page 23


PREPARED BY: Nandini GR
15CSL48 Microprocessor and microcontroller lab

10. Design and develop an assembly program to drive a Stepper Motor interface and rotate the
motor in specified direction (clockwise or counter-clockwise) by N steps (Direction and N
are specified by the examiner). Introduce suitable delay between successive steps. (Any
arbitrary value for the delay may be assumed by the student).

a) Clock wise rotation

.model small
.stack
.code

mov al,80h
mov dx,1103h
out dx,al
mov cx,32h
mov al,33h

up: mov dx,1102h


out dx,al
call delay
ror al,01h
loop up
mov ah,4ch
int 21h
delay proc
push cx
push dx
mov dx,0fffh

l1: mov cx,0fffh


here: loop here
dec dx
jnz l1
pop dx
pop cx
ret
delay endp
end

SJMIT CSE DEPARTMENT Page 24


PREPARED BY: Nandini GR
15CSL48 Microprocessor and microcontroller lab

b) Anticlockwise rotation

.model small
.stack
.code

mov al,80h
mov dx,1103h
out dx,al
mov cx,32h
mov al,33h

up: mov dx,1102h


out dx,al
call delay
rol al,01h
loop up
mov ah,4ch
int 21h
delay proc
push cx
push dx
mov dx,0fffh

l1: mov cx,0fffh


here: loop here
dec dx
jnz l1
pop dx
pop cx
ret
delay endp
end

SJMIT CSE DEPARTMENT Page 25


PREPARED BY: Nandini GR
15CSL48 Microprocessor and microcontroller lab

Output:

Allowio 0x1100h
Masm/zi stepper;
Link/co stepper;
Stepper

SJMIT CSE DEPARTMENT Page 26


PREPARED BY: Nandini GR
15CSL48 Microprocessor and microcontroller lab

11. Design and develop an assembly language program to


a. Generate the Sine Wave using DAC interface (The output of the DAC is to be
displayed on the CRO).

.model small
.stack
.data

Code1 db 80h,96h,0ach,0c0h,0d2h,0e2h,0e0h
db 0e2h,0f8h,0feh,0f3h,0f8h,0efh,0e2h
db 0d2h,0c0h,0ach,96h,80h,69h,54h,40h,02fh
db 0eh,11h,08h,02h,00h,02h,05h,04h,1eh,2ch
db 40h,54h,6ah,80h

.code

mov ax,@data
mov ds,ax

mov al,80h
mov dx,1103h
out dx,al

l2: mov cx,21h


lea si,code1

l1: mov al,[si]


mov dx,1100h

out dx,al
inc si
loop l1
jmp l2
mov ah,4ch
int 21h
end

SJMIT CSE DEPARTMENT Page 27


PREPARED BY: Nandini GR
15CSL48 Microprocessor and microcontroller lab

output:

Allowio 0x1100h
Masm/zi sinw;
Link/co sinw;
Sinw

SJMIT CSE DEPARTMENT Page 28


PREPARED BY: Nandini GR
15CSL48 Microprocessor and microcontroller lab

b. Generate a Half Rectified Sine waveform using the DAC interface. (The output of
the DAC is to be displayed on the CRO).

.model small
.stack
.data

Code1 db 80h,96h,0ach,0c0h,0d2h,0e2h,0e0h
db 0f8h,0feh,0ffh,0fch,0f8h,0efh,0e2h
db 0d2h,0c0h,0ach,96h,80h,80h,80h,80h,80h
db 80h,80h,80h,80h,80h,80h,80h,80h,80h,80h
db 80h,80h,80h,80h,80h,80h

.code

mov ax,@data
mov ds,ax

mov al,80h
mov dx,1103h
out dx,al

l2: mov cx,21h


lea si,code1

l1: mov al,[si]


mov dx,1100h

out dx,al
inc si
loop l1
jmp l2
mov ah,4ch
int 21h
end

SJMIT CSE DEPARTMENT Page 29


PREPARED BY: Nandini GR
15CSL48 Microprocessor and microcontroller lab

output:

Allowio 0x1100h
Masm/zi halfr;
Link/co halfr;
halfr

SJMIT CSE DEPARTMENT Page 30


PREPARED BY: Nandini GR

Вам также может понравиться