Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Microprocessor and Microcontroller: Soft Ware Programs-Part A

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 21

MICROPROCESSOR AND MICROCONTROLLER

SOFT WARE 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

.data

arr dw 0111h,0112h,0113h,0114h,0115h
len dw ($-arr)/2
key equ 0115h
msg1 db "found$"
msg2 db "not found$"
.code

mov ax,@data
mov ds,ax

mov bx,00
mov dx,len
mov cx,key
again: cmp bx,dx
ja notfnd

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

dec ax
mov dx,ax
jmp again
big:je found
inc ax
MICROPROCESSOR AND MICROCONTROLLER
mov bx,ax
jmp again
found: lea dx,msg1
Jmp displ
notfnd: lea dx,msg2
displ: mov ah,09h
int 21h
int 3
end
MICROPROCESSOR AND MICROCONTROLLER
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
.data
ARR DW 3333h, 4444h, 1111h, 9999h, 5555h, 2222h, 7777h, 8888h,
6666h
LEN EQU $-ARR
.code
MOV AX, @DATA
MOV DS, AX
MOV CX, (LEN/2)-1
OUTER: LEA SI, ARR
MOV BX, 0

MOV SI, 00
Inner : inc bx
MOV AX, ARR [SI]
INC SI
INC SI
CMP AX, ARR [SI]
JBE SKIP
XCHG AX, ARR [SI]
MOV ARR [SI-2], AX
SKIP: CMP BX, CX
JL INNER
LOOP OUTER
INT 3H
END START
MICROPROCESSOR AND MICROCONTROLLER
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
str1 db "manam"
slen equ ($-str1)
str2 db 40 dup(5)
msg1 db "Palindrome$"
msg2 db "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


jmp down1
down:lea dx, msg2
down1: mov ah, 09h
int 21h
int 3
end
MICROPROCESSOR AND MICROCONTROLLER
4.Develop an assembly language program to compute nCr using recursive
procedure. Assume that ‘n’ and ‘r’ are non-negative integers.

DATA SEGMENT
N DB 10
R DB 9
NCR DB 0
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:MOV AX,DATA
MOV DS,AX
MOV NCR,0
MOV AL,N
MOV BL,R
CALL ENCR
CALL DISPLAY
MOV AH,4CH
INT 21H
ENCR PROC
CMP AL,BL
JE NCR1
CMP BL,0
JE NCR1
CMP BL,0
JE NCR1
CMP BL,1
JE NCRN
DEC AL
CMP BL,AL
JE NCRN1
PUSH AX
PUSH BX
CALL ENCR
POP BX
POP AX
DEC BL
PUSH AX
PUSH BX
CALL ENCR
POP BX
POP AX
MICROPROCESSOR AND MICROCONTROLLER
RET
NCR1:INC NCR
RET
NCRN1:INC AL
NCRN:ADD NCR,AL
RET
ENCR ENDP
display PROC
PUSH CX
MOV AL,NCR
MOV CH,AL
AND AL,0F0H
MOV CL,04
SHR AL,CL
CMP AL,09H
JBE NEXT
ADD AL,07H
NEXT:ADD AL,30H
MOV DL,AL
MOV AH,02H
INT 21H
MOV AL,CH
AND AL,0FH
CMP AL,09H
JBE NEXT2
ADD AL,07H
NEXT2:ADD AL,30H
MOV DL,AL
MOV AH,02H
INT 21H
POP CX
RET
DISPLaY ENDP
CODE ENDS
END START
MICROPROCESSOR AND MICROCONTROLLER
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
.DATA
msg db "The Time is: "
hrs db ?,?,' : '
mins db ?,?,' (hh:mm) ',10,13
db "The Date is: "
da db ?,?, '/'
mon db ?,?, '/'
yea db ?,?, '(dd/mm/yy)', 10,13,'$'
.CODE
MOV AX,@DATA
MOV DS, AX
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 AH, 2AH
INT 21H
MOV AL, DL
AAM
Add ax,3030h
mov da,Ah
mov da +1, al
MOV AL, DH
AAM
Add ax, 3030h
MOV mon,AH
mov mon+1,al
; YEAR
ADD CX, 0F830H
MOV Al, cl
MICROPROCESSOR AND MICROCONTROLLER
aam
Add ax, 3030h
mov yea,ah
mov yea+1,al
lea dx,msg
mov ah,09h
int 21h
int 3
end
MICROPROCESSOR AND MICROCONTROLLER
6. To write and simulate ARM assembly language programs for data transfer,
arithmetic and logical operations (Demonstrate with the help of a suitable
program).

6(a)
.Data Transfer

Area movt,code,readonly
Entry
Mov R1,#005
Mov R2,#002
Mov R3,R1
Mov R4,R2
Stop b Stop
End

6(b)
Arithmetic Operations
A. Addition, Subtraction and Multiplication:
area addt, code, readonly
entry
mov r1,#0005 ; Mov immediate 32 bit data to r1
mov r2,#0002 ; Mov immediate 32 bit data to r2
add r3,r2,r1 ; Add the contents present in r2 with the
contents of r1 and store in r3
sub r5,r1,r2 ; Subtract; r5 = r1-r2
mul r6,r1,r2 ; Multiply
mov r7,r6
add r7,#2 ; Add immediate data
mov r8,r7
sub r8,#3 ; Subtract immediate data
mov r9,r8
stop b stop
end

6(c)
Area movt,code,readonly
Mov R1,#05
Mov R2,#02
AND R3,R1,R2
Stop b Stop
End
MICROPROCESSOR AND MICROCONTROLLER

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

#include<lpc214x.h>
void main()
{
int a=6,b=2,c;
c=a+b;
IO0SET = 0x00000000;
IO0SET = (IO0SET | 0xFFFFFFFF)&c;
}
MICROPROCESSOR AND MICROCONTROLLER
HARDWARE PROGRAMS-PART B
8a. Design and develop an assembly program to demonstrate BCD Up-Down
Counter (00-99) on the Logic Controller Interface
8(a) bcd up counter

.model small
.stack
.data
pa equ 0e800h
pb equ 0e801h
pc equ 0e802h
cr equ 0e803h
cw db 80h
.code
mov ax,@data
mov ds,ax
mov dx,cr
mov al,cw
out dx,al
mov dx,pa
mov al,00h
l1:out dx,al
call delay
call stop
add al,01h
jne l1
daa
cmp al,01h
jne l1
mov dx,pa
mov al,99h
l2:out dx,al
call delay
call stop
sub al,01h
das
cmp al,99h
jne l2
exit:mov ah,4ch
int 21h
delay proc near
mov si,0ffffh
MICROPROCESSOR AND MICROCONTROLLER
l3:mov di,0ffffh
l4:dec di
jnz l4
dec si
jnz l3
ret
delay endp
stop proc near
push ax
mov ah,01h
int 16h
pop ax
ret
stop endp
end
MICROPROCESSOR AND MICROCONTROLLER
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
.model small
.stack
.data
dispm macro str
lea dx,str
mov ah,9h
int 21h
endm
cwr EQU 0e803h
pa EQU 0e800h
pb EQU 0e801h
msg1 db 10,13,"Enter the value of x:$"
msg2 db 10,13,"Enter the value of y:$"
msg3 db 10,13,"LSB result is :$"
msg4 db 10,13,"MSB result is :$"
.code
mov ax,@data
mov ds,ax
mov al,82h
mov dx,cwr
out dx,al

dispm msg1
call delay
call delay
call delay

mov dx,pb
in al,dx

mov cl,al
dispm msg2

call delay
call delay
call delay

mov dx, pb
in al,dx
MICROPROCESSOR AND MICROCONTROLLER
mov ah,00h
mul cl

push ax
dispm msg3
pop ax

mov dx,pa
out dx,al

call delay
call delay
call delay

push ax
dispm msg4
pop ax

mov dx, pa
mov al, ah
out dx,al

call delay
call delay
call delay

mov ah,4ch
int 21h

delay PROC near


mov si, 0ffffh
back: mov di,0ffffh
back1: nop
nop
dec di
jnz back1
dec si
jnz back
ret
delay ENDP
end
MICROPROCESSOR AND MICROCONTROLLER
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

clrscr MACRO
mov al,2
mov ah,0
int 10h
endm

mdisp MACRO str


lea dx,str
mov ah,9
int 21h
endm

.data
msg1 db "Demo pgm for seven segment display",13,10,"$"
msg2 db "Press any key to exit",13,10,"$"

array db 08EH,0CFH,0AFH,86H,89H,86H,0C7H,8CH

cr EQU 0e803h
pa EQU 0e800h
pb EQU 0e801h
pc EQU 0e802h
.code
mov ax,@data
mov ds,ax
clrscr
mdisp msg1
mdisp msg2
mov al,80h
mov dx,cr
out dx,al
MICROPROCESSOR AND MICROCONTROLLER
getkey:mov bx,0000h

back: mov al,bl


and al,03h
cmp al,00
jne no_delay

mov cx,0ffffh
up: mov ax,09fffh
up1: dec ax
jnz up1
loop up

no_delay: mov cl,08h


mov ch,array[bx]

first: rol ch,1


mov al,ch
mov dx,pb
out dx,al

mov dx,pc
mov al,01h
out dx,al
mov al,00h
out dx,al
dec cl
jnz first
inc bx
cmp bx,08h
jb back

mov ah,01h
int 16h
jz getkey

mov ah,4ch
int 21h

end
MICROPROCESSOR AND MICROCONTROLLER
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).

.MODEL SMALL
.DATA
PA EQU 0E800H
PB EQU 0E801H
PC EQU 0E802H
CR EQU 0E803H
CW DB 80H
.CODE
MOV AX,@DATA
MOV DS,AX
MOV DX,CR
MOV AL,CW
OUT DX,AL
MOV CX,200D
MOV DX,PA
MOV AL,88H
L1: ROL AL,01H
OUT DX,AL
CALL DELAY
LOOP L1
MOV AH,4CH
INT 21H
DELAY PROC NEAR
MOV SI,0FFFFH
L2: MOV DI,0FFFH
L3: DEC DI
JNZ L3
DEC SI
JNZ L2
RET
DELAY ENDP
END
MICROPROCESSOR AND MICROCONTROLLER

11.To interface LCD with ARM processor—write and execute in the c program.
Display the messages and number on LCD.

#include <LPC214x.h>

void cmd(unsigned char d);


void datal(unsigned char t);
void delay (int count);

int main()
{
int i;
unsigned char name[]={"WelCome"};

IO0DIR=0x30403C00;

cmd(0x02);
delay(10000);
cmd(0x01);
delay(10000);

cmd(0x8f);

for (i=0;name[i]!='\0';i++)
{
datal(name[i]);
cmd(0x18);
delay(100000);
}

void cmd(unsigned char d)


{
int a=0;
a = d | 0xFFFFFF0F;
IO0CLR |= 0x00003C00;
a=a<<6;
IO0CLR = 0x20400000;
IO0SET = 0x10000000;
MICROPROCESSOR AND MICROCONTROLLER
IO0SET =(IO0SET | 0x00003c00)&a;
delay(1000);
IO0CLR = 0x10000000;

a=0x0;
d=d<<4;
a = d | 0xFFFFFF0F;
IO0CLR |= 0x00003C00;
a=a<<6;
IO0CLR = 0x20400000;
IO0SET = 0x10000000;
IO0SET = (IO0SET | 0x00003C00)&a;
delay(1000);
IO0CLR = 0x10000000;
}
void datal(unsigned char t)
{
int b=0;
b = t|0xFFFFFF0F;
IO0CLR |= 0x00003C00;
b=b<<6;
IO0SET = 0x10400000;
IO0SET = (IO0SET | 0x00003C00)&b;
delay(1000);
IO0CLR = 0x10000000;

b=0x0;
t=t<<4;
b=t|0xFFFFFF0F;
IO0CLR |= 0x00003C00;
b=b<<6;
IO0SET = 0x10400000;
IO0SET = (IO0SET | 0x00003C00)&b;
delay(1000);
IO0CLR = 0x10000000;
}
void delay(int count)
{
int j=0, i=0;
for (j=0;j<count;j++)
for (i=0;i<35;i++);
}
MICROPROCESSOR AND MICROCONTROLLER
12. To inter face stepper motor with ARM processor. Write a c program to
rotate stepper motor.
#include<lpc214x.h>
void delay()
{
int i,j;
for(i=0;i<0xFF;i++)
for(j=0;j<0x25;j++);
}
int main()
{
IO0DIR=0x000F0000;
while(1)
{
IO0PIN=0x00080000;
delay();
IO0PIN=0X00040000;
delay();
IO0PIN=0X00020000;
delay();
IO0PIN=0x00010000;
delay();
}
}
MICROPROCESSOR AND MICROCONTROLLER

You might also like