MPlab Program
MPlab Program
MPlab Program
_____________________________________________________
1 BINARY SEARCH
.MODEL SMALL
.STACK
.DATA
ARUN JAYARAMAN
A DW 1,2,3,4,5
N DW ($-A)/2
KEY EQU 4
MSG1 DB 'KEY FOUND$'
MSG2 DB 'KEY NOT FOUND$'
.CODE
MOV AX,@DATA
MOV DS,AX
MOV BX,0
MOV CX,N
AGAIN:CMP BX,CX
JG NOTFND
MOV AX,BX
ADD AX,CX
SHR AX,1
MOV SI,AX
ADD SI,SI
CMP A[SI],KEY
JE FOUND
JC SETLB
DEC AX
MOV CX,AX
1
JMP AGAIN
SETLB:INC AX
MOV BX,AX
JMP AGAIN
FOUND:DISPLAY MSG1
JMP QUIT
NOTFND:DISPLAY MSG2
QUIT:MOV AH,4CH
INT 21H
END
2 BUBBLE SORT
elements.
.MODEL SMALL
.STACK
.DATA
A DW 5,4,1,2,3
N DW ($-A)/2
.CODE
MOV AX,@DATA
MOV DS,AX
MOV BX,N
DEC BX
LOOP1:MOV CX,BX
MOV SI,0
LOOP2:MOV AX,A[SI]
INC SI
INC SI
CMP AX,A[SI]
JC LOOP3
XCHG AX,A[SI]
MOV A[SI-2],AX
LOOP3:LOOP LOOP2
2
DEC BX
JNZ LOOP1
MOV AH,4CH
INT 21H
END
3 PALINDROME
.MODEL SMALL
ARUN JAYARAMAN
.STACK
.DATA
STR DB 'CIVIC'
LEN DW LEN-STR
RSTR DB LEN-STR DUP(0)
MSG1 DB 'PALINDROME$'
MSG2 DB 'NOT PALINDROME$'
.CODE
MOV AX,@DATA
MOV DS,AX
MOV ES,AX
LEA SI,LEN-1
LEA DI,RSTR
MOV CX,LEN
BACK:MOV AL,[SI]
MOV [DI],AL
DEC SI
INC DI
LOOP BACK
CLD
LEA SI,STR
LEA DI,RSTR
MOV CX,LEN
REPE CMPSB
3
JE PALIN
DISPLAY MSG2
JMP QUIT
PALIN:DISPLAY MSG1
QUIT:MOV AH,4CH
INT 21H
END
4 NCR
.MODEL SMALL
.STACK
.DATA
N DW 4
NAMARAYAJ NURA
R DW 2
RESULT DW 0
.CODE
MOV AX,@DATA
MOV DS,AX
MOV AX,N
MOV BX,R
CALL NCR
MOV AH,4CH
INT 21H
NCR PROC
CMP BX,0
JE RES1
CMP BX,AX
JE RES1
CMP BX,1
JE RESN
DEC AX
CMP BX,AX
4
JE INCR
PUSH AX
PUSH BX
CALL NCR
POP BX
POP AX
DEC BX
PUSH AX
PUSH BX
CALL NCR
POP BX
POP AX
RET
RES1:INC RESULT
RET
NAMARAYAJ NURA
INCR:INC RESULT
RESN:ADD RESULT,AX
RET
NCR ENDP
END
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
NEXTLINE DB 10,13,"$"
HYPHEN DB "-$"
DAY DB ?
MONTH DB ?
.CODE
MOV AX,@DATA
MOV DS,AX
5
;display of hours
MOV AL,CH
AAM
MOV BX,AX
CALL DISP
MOV DL,':'
MOV AH,02H
INT 21H
;display of minutes
MOV AL,CL
AAM
MOV BX,AX
CALL DISP
MOV DL,':'
MOV AH,02H
INT 21H
NAMARAYAJ NURA
;display of seconds
MOV AL,DH
AAM
MOV BX,AX
CALL DISP
MOV AH,09H
LEA DX,NEXTLINE
INT 21H
;display of day
MOV DAY,DL
MOV MONTH,DH
MOV AL,DAY
AAM
MOV BX,AX
CALL DISP
MOV AH,09H
LEA DX,HYPHEN
INT 21H
;display of month
MOV AL,MONTH
6
AAM
MOV BX,AX
CALL DISP
MOV AH,09H
LEA DX,HYPHEN
INT 21H
;display of year
MOV AX,CX
MOV BX,1000
CALL CONVERT
MOV AX,DX
MOV BX,100
CALL CONVERT
MOV AX,DX
MOV BX,10
CALL CONVERT
NAMARAYAJ NURA
ADD DL,30H
MOV AH,02H
INT 21H
;quit
MOV AH,4CH
INT 21H
;CONVERT procedure
CONVERT PROC
MOV DX,0
DIV BX
PUSH DX
MOV DL,AL
ADD DL,30H
MOV AH,02H
INT 21H
POP DX
RET
CONVERT ENDP
;DISPLAY procedure
MOV DL,AH
7
ADD DL,30H
MOV AH,02H
INT 21H
MOV DL,BL
ADD DL,30H
MOV AH,02H
INT 21H
RET
DISP ENDP
END
6. To write and simulate ARM assembly language programs for data transfer,
arithmetic and
logical operations (Demonstrate with the help of a suitable program).
ARITHMETIC OPERATION
ADD64
LDR R0,= 0X1234E640
LDR R1,= 0X12348900
LDR R2,= 4321212102
ADDS R4,R1,R3
ADC R5,R0,R2
NOP
NOP
BX LR
END
LOGICAL OPERATION
AREA LARGEST,CODE,READONLY
ENTRY
START
8
AND R2,R3
LDR R4,= RESULT
STR R2,[R4]
NOP
NOP
NOP
;array of 32 bit numbers
VALUE1
DCD 0X55AAAA55
VALUE2
DCD 0X5555AA55
AREA DATA2,DATA,READWRITE
RESULT DCD 0X0
END
AREA PGM1,CODE,READONLY
ENTRY
START
NAMARAYAJ NURA
LOOP B LOOP
VALUE
DCD 0X22222222;
AREA DATA1,DATA,READWRITE
RES
DCD 0X00
END
ARITHMETIC OPERATIONS
#include<lpc21xx.h>
main()
{
int a=6,b=2,sum,mul,sub,div;
sum=a+b;
mul=a*b;
sub=a-b;
div=a/b;
}
9
LOGICAL OPERATIONS
#include<lpc21xx.h>
main()
{
int a=0,b=1,and,or,exor,not;
and=a&b;
or=a|b;
exor=a^b;
not=~a;
}
.MODEL SMALL
.STACK
.DATA
.CODE
MOV AL,80H
MOV DX,CR
OUT DX,AL
MOV DX,PORTA
MOV AL,0
AGAIN:OUT DX,AL
CALL DELAY
ADD AL,1
DAA
CMP AL,COUNT
JLE AGAIN
MOV AL,COUNT
BACK:OUT DX,AL
CALL DELAY
SUB AL,1
DAS
CMP AL,0
10
JGE BACK
MOV AH,4CH
INT 21H
DELAY PROC
PUSH BX
PUSH CX
MOV BX,0FFFFH
LOOP2:MOV CX,0FFFFH
LOOP1:LOOP LOOP1
DEC BX
JNZ LOOP2
POP CX
POP BX
RET
DELAY ENDP
NAMARAYAJ NURA
END
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
.CODE
MOV AL,82H
MOV DX,CR
OUT DX,AL
MOV DX,PORTB
IN AL,DX
MOV BL,AL
AND AL,0FH
MOV CL,4
SHR BL,CL
11
MUL BL
MOV DX,PORTA
OUT DX,AL
MOV AH,4CH
INT 21H
END
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
.MODEL SMALL
.STACK
.DATA
NAMARAYAJ NURA
FIRE DB 79H,77H,06H,71H
HELP DB 73H,38H,79H,76H
.CODE
MOV AX,@DATA
MOV DS,AX
MOV AL,80H
MOV DX,CR
OUT DX,AL
MOV CX,2
AGAIN:MOV DI,20
DISP1:LEA SI,FIRE
CALL DISPLAY
DEC DI
JNZ DISP1
MOV DI,20
DISP2:LEA SI,HELP
CALL DISPLAY
DEC DI
12
JNZ DISP2
LOOP AGAIN
MOV AH,4CH
INT 21H
DISP PROC
MOV AH,0
MOV DX,PORTA
OUT DX,AL
CALL DELAY
INC AH
CMP AH,4
JNZ BACK
RET
NAMARAYAJ NURA
DISPLAY ENDP
DELAY PROC
PUSH BX
PUSH CX
MOV BX,0FFH
LOOP2:MOV CX,0FFFFH
LOOP1:LOOP LOOP1
DEC BX
JNZ LOOP2
POP CX
POP BX
RET
DELAY ENDP
END
13
.MODEL SMALL
.DATA
.CODE
MOV AL,80H
MOV DX,CR
OUT DX,AL
MOV DX,PORTC
MOV AL,88H
MOV CX,1000
AGAIN:OUT DX,AL
CALL DELAY
ROL AL,1
LOOP AGAIN
NAMARAYAJ NURA
MOV DX,PORTC
MOV AL,88H
MOV CX,1000
MOV AH,4CH
INT 21H
DELAY PROC
PUSH BX
PUSH CX
MOV BX,0FFH
LOOP2:MOV CX,0FFFFH
LOOP1:LOOP LOOP1
DEC BX
JNZ LOOP2
POP CX
POP BX
RET
DELAY ENDP
14
END
Design and develop an assembly language program to Generate the Sine Wave
using DAC interface (The output of the DAC is to bedisplayed on the CRO).
.MODEL SMALL
.DATA
TABLE DB 127,149,170,190,208,224,236,246,252,254
DB 252,246,236,224,208,190,170,149,127
DB 104,83,63,45,29,17,7,1,0
DB 1,7,17,29,45,63,83,104,127
.CODE
NAMARAYAJ NURA
MOV AX,@DATA
MOV DS,AX
MOV AL,80H
MOV DX,CR
OUT DX,AL
BACK: LODSB
OUT DX,AL
CALL DELAY
LOOP BACK
MOV AH,1
INT 10H
JZ AGAIN
MOV AH,4CH
INT 21H
DELAY PROC
MOV BX,0FFFFH
LOOP1:DEC BX
JNZ LOOP1
RET
15
DELAY ENDP
END
Generate a Half Rectified Sine waveform using the DAC interface. (The output
of the DAC is to be displayed on the CRO).
.MODEL SMALL
.DATA
TABLE DB 127,149,170,190,208,224,236,246,252,254
DB 252,246,236,224,208,190,170,149,127
DB 127,127,127,127,127,127,127,127,127,127
DB 127,127,127,127,127,127,127,127,127,127
.CODE
NAMARAYAJ NURA
MOV AX,@DATA
MOV DS,AX
MOV AL,80H
MOV DX,CR
OUT DX,AL
BACK: LODSB
OUT DX,AL
CALL DELAY
LOOP BACK
MOV AH,1
INT 10H
JZ AGAIN
MOV AH,4CH
INT 21H
DELAY PROC
MOV BX,0FFFFH
LOOP1: DEC BX
JNZ LOOP1
16
RET
DELAY ENDP
END
// LCD INTERFACING
//----------------------------------------------------------------
// CONTROLLER : LPC-2148
// DATE : December - 2015
// Developed By : Advanced Electronic Systems Bangalore, India
//----------------------------------------------------------------
//----------------------------------------------------------------
// Predefined data will be displayed on LCD
//----------------------------------------------------------------
NAMARAYAJ NURA
#include<lpc214x.h>
#include<stdio.h>
//Function prototypes
void lcd_init(void);
void wr_cn(void);
void clr_disp(void);
void delay(unsigned int);
void lcd_com(void);
void wr_dn(void);
void lcd_data(void);
int main()
{
PINSEL0 = 0X00000000; // configure P0.0 TO P0.15 as GPIO
IO0DIR = 0x000000FC; //configure o/p lines for lcd [P0.2-P0.7]
17
temp1 = 0x81; //Display starting address of first line 2nd pos
lcd_com(); //function to send command to lcd
ptr = disp; // pointing data
while(*ptr!='\0')
{
temp1 = *ptr;
lcd_data(); //function to send data to lcd
ptr ++;
}
temp1 = 0xC0; // Display starting address of second line 1st pos
lcd_com(); //function to send command to lcd
ptr = disp1; // pointing second data
while(*ptr!='\0')
{
temp1 = *ptr;
lcd_data(); //send data to lcd
ptr ++;
}
while(1);
NAMARAYAJ NURA
} //end of main()
temp1 = 0x28; // load command for lcd function setting with lcd in 4 bit
mode,
lcd_com(); // 2 line and 5x7 matrix display
delay(3200);
temp1 = 0x0C; // load a command for display on, cursor on and blinking off
lcd_com();
18
delay(800);
void lcd_com(void)
{
temp = temp1 & 0xf0; //masking higher nibble first
wr_cn();
temp = temp1 & 0x0f; //masking lower nibble
temp = temp << 4;
wr_cn();
delay(500); // some delay
}
NAMARAYAJ NURA
19
wr_dn();
#include <LPC21xx.h>
void clock_wise(void) ;
void anti_clock_wise(void) ;
int main(void)
{
PINSEL2 = 0x00000000; //P1.20 to P1.23 GPIO
IO1DIR |= 0x00F00000 ; //P1.20 to P1.23 made as output
20
while(1)
{
for( j = 0 ; j < 50 ; j++ ) // 50 times in Clock wise Rotation
clock_wise() ; // rotate one round clockwise
for( k = 0 ; k < 65000 ; k++ ) ; // Delay to show anti_clock Rotation
for( j=0 ; j < 50 ; j++ ) // 50 times in Anti Clock wise Rotation
anti_clock_wise() ; // rotate one round anticlockwise
for( k = 0 ; k < 65000 ; k++ ) ; // Delay to show ANTI_clock Rotation
}
} // End of main()
void clock_wise(void)
{
var1 = 0x00080000; //For Clockwise
for( i = 0 ; i <= 3 ; i++ ) // for A B C D Stepping
{
var1 <<= 1 ;
IO1CLR =0x00F00000 ; //clearing all 4 bits
IO1SET = var1 ; // setting particular bit
for( k = 0 ; k < 3000 ; k++ ); //for step speed variation
NAMARAYAJ NURA
}
}
void anti_clock_wise(void)
{
var1 = 0x00800000 ; //For Anticlockwise
IO1CLR =0x00F00000 ; //clearing all 4 bits
IO1SET = var1 ;
for( k = 0 ; k < 3000 ; k++ ) ;
for( i = 0 ; i < 3 ; i++ ) // for A B C D Stepping
{
var1 >>=1; //rotating bits
IO1CLR =0x00F00000 ; // clear all bits before setting
IO1SET = var1 ; // setting particular bit
for( k = 0 ; k < 3000 ; k++ ) ; //for step speed variation
}
}
21
// STEPPER MOTOR INTERFACING
//--------------------------------------------------------------
// CONTROLLER : LPC-2148
// DATE : JULY - 2016
// Developed By : Advanced Electronic Systems Bangalore,India
//----------------------------------------------------------------
//-------------------------------------------------------------------
// A stepper motor direction is controlled by shifting the voltage across
// the coils. Port lines : P1.20 to P1.23
//-------------------------------------------------------------------
#include <LPC21xx.h>
void clock_wise(void) ;
void anti_clock_wise(void) ;
int main(void)
{
NAMARAYAJ NURA
void clock_wise(void)
{
var1 = 0x00080000; //For Clockwise
for( i = 0 ; i <= 3 ; i++ ) // for A B C D Stepping
{
var1 <<= 1 ;
IO1CLR =0x00F00000 ; //clearing all 4 bits
IO1SET = var1 ; // setting particular bit
for( k = 0 ; k < 3000 ; k++ ); //for step speed variation
}
}
void anti_clock_wise(void)
{
22
var1 = 0x00800000 ; //For Anticlockwise
IO1CLR =0x00F00000 ; //clearing all 4 bits
IO1SET = var1 ;
for( k = 0 ; k < 3000 ; k++ ) ;
for( i = 0 ; i < 3 ; i++ ) // for A B C D Stepping
{
var1 >>=1; //rotating bits
IO1CLR =0x00F00000 ; // clear all bits before setting
IO1SET = var1 ; // setting particular bit
for( k = 0 ; k < 3000 ; k++ ) ; //for step speed variation
}
}
NAMARAYAJ NURA
23
KEIL EXECUTION STEPS
->filename.c
->Target1
->Source Group
->startup.s
->click on configuration wizard tab which is seen downwards.
->new
->save with either same or different filename
Goto Target1
->right click
->options
->in Target tab
->give 12Mhz
->select use microlib
->select IROM1
->select IRAM1
24
Flash Magic
Step1:
Device:lpc2148
COM port:COM1
BAUD rate:9600
Interface:None(ISP)
Oscillator:12
Step2:
Step3:
->browse ->filename.hex->start
1. Define Microprocessor
The Processor is an integrated circuit in a small size and hence the name
microprocessor.
25
Segment registers are used to hold the upper 16-bits of the starting
addresses of the 4 memory
segments.
12. How many active flags are there in 8086? Name them.
There are 9 active flags. They are Carry Flag, Parity Flag, Auxillary Flag,
Zero Flag, Sign Flag, and
Overflow Flag.
26
DD- Define Doubleword
DQ- Define Quadword
DT- Define Tenbytes.
27
FAR JUMP- Is 5 byte instruction, which allows a jump to any memory location
within the real
memory system. A FAR jump is a jump where the destination location is from
a different segment.
In this case both IP and CS are changed as specified in the destination.
26. What is the other name for NEAR jump and FAR jump.
NEAR jump is also called as intersegment jump and FAR jump is also called
as intrasegment jump.
NAMARAYAJ NURA
28
The instruction copies byte from address pointed by [BX+AL] back into
AL
Equivalent MOVE instruction is MOV AL,[AL][BX]
Use of XLAT instruction in Program 6b.
i) Store in the data segment; say for example starting from offset location
4000H, the table
of 7-segment equivalent code in hexadecimal. For example, the character 6
has the
ASCII code of 36H and 7 segment equivalent code of 7DH (refer 7 segment
equivalent
code table). Thus 7DH is stored in location 4036H.
ii) To convert the ASCII code of 36H to 7 segment equivalent code of 7Dh,
we must
execute XLAT instruction with AL contents 36H and BX contents as 4000H. This
results in AL contents changing to 7DH.
Before After
(AL) 36 7DH
(BX) 4000 4000
(DS:36[BX] 7D 7D
35. Which are the 3 ways by which a normal program can be interrupted
3 ways are:
1. By External Signal applied to NMI or INTR input pin
2. Special Instruction in the program Eg INT
3. By the occurrence of some condition Divide by zero, overflow etc.
29
Interrupt caused by an external signal is referred to as hardware interrupt.
Conditional interrupts or interrupts caused by special instructions are
called software interrupts.
38. How many interrupts service routines can be stored in the interrupt
vector table
Table can hold the starting addresses for 256 interrupt service routines.
30
IMUL instruction multiplies a signed byte from some source and a signed byte
in AL.
47. What is the DOS function to read a character from the keyboard
31
01H is the service number to read a character from the keyboard and read
character will be stored in
AL register.
48. What is the DOS function to display string on the output screen
09H is the service number to display string on the output screen and the
effective address of the
string to be displayed should be stored in DX register
NAMARAYAJ NURA
32