Microprocessor and Microcontroller
Microprocessor and Microcontroller
End
BIOS INTERRUPTS
INT 10H, Function 00H: Set video mode
INT 10H, Function 03H: Set desired resolution
INT 10H, Function 02H: Set cursor position
INT 10H, Function 06H: Scroll rectangle window up
INT 10H, Function 07H: Scroll rectangle window down
Assembler directives:
.MODEL:Selects the programming model followed by size of the memory system (tiny, small or huge)
DUP:This directive is used to initialize several locations and to assign values to these locations.
EQU:This is used to assign names to the constant used in the program.
MACRO and ENDM: The MACRO directive informs the assembler the beginning of the macro. ENDM
indicates the end of the macro
DB: Defines byte (8 bits). DB directive is used to declare a byte type variable or to store a byte in memory
location.
.CODE: Indicates the start of the code segment
.DATA: Indicates the start of the data segment
.STACK: Selects the start of the stack segment
END: Ends a program file
13: represents carriage return i.e. takes the cursor to the left corner of same line and 10: represents
newline like \n in C
Jump allows the programmer to skip section of a program and branch to any part of the memory
for the next instruction. Near and Far jump
JA = jump if above JNC = jump if no carry
JAE = jump if above or equal JNE or JNZ = jump if not equal or not zero
JB = jump if below JNP or JPO = jump if no parity or parity odd
JBE = jump if below or equal JP or JPE = jump if parity or parity even
JC = jump if carry JG = jump if greater than
JE or JZ = jump if equal or zero JGE = jump if greater than or equal
1. a) Search a key element in a list of ‘n’ 16-bit numbers using the Binary search
algorithm.
.MODEL SMALL
.DATA
ARR DW 1234H,1235H,1236H,1237H,1238H
LEN DW ($-ARR)/2
SERKEY EQU 1237H
MSG1 DB "KEY IS FOUND AT"
RES DB" POSITION",13,10,"$"
MSG2 DB"KEY IS NOT FOUND$"
.CODE
MOV AX,@DATA ; INITIALIZE DATA SEGMENT REGISTER
MOV DS, AX
MOV BX, 00
MOV DX, LEN ; LOAD DX WITH LENGTH OF ARRAY
MOV CX, SERKEY ; LOAD CX WITH SEARCH KEY
AGAIN: CMP BX, DX
JA FAILURE
MOV AX, BX
ADD AX, DX
SHR AX, 01 ; DIVIDE ARRAY BY 2
MOV SI, AX
ADD SI, SI
CMP CX, ARR [SI]
JAE BIGGER;SEARCH KEY EQUAL OR BIGGER MOVE DOWNWARDS IN ARRAY
DEC AX
MOV DX,AX
JMP AGAIN
RESULT:
[SEARCHKEY =1237H]
KEY IS FOUND AT 4 POSITION
[Change SEARCHKEY =1239H, Run the program again ]
KEY IS NOT FOUND
A key algorithm for searching an array for a target value when the array is already sortedin ascending order is
called Binary Search. We start byexamining the middle element of the array. If it smaller than x than x mustbe
in the upper half of the array; if is greater than x thenit must be in the lower half.
As we can see the above array is sorted in ascending order, binary search is applied on sorted lists only,
so that we can make the search fast.
Start with middle element
If it is equal to the number we are searching then search is completed
If it is less than it then move to the right
If it is more than it then move to the left
And then repeat till you find the number
Result:
After running the program, debug; command is Debug filename.exe
-t (keep on pressing t until you get NOP)
Then give the command dump 0000 (You can see the sorted list )
12 22 34 56 62 78
.MODEL SMALL
.DATA
STR1 DB 257 DUP (?)
REVERSE DB 257 DUP (?)
MSG1 DB 13,10 ,"ENTER A STRING: $"
MSG2 DB 13, 10,"STRING IS PALINDROME$"
MSG3 DB 13, 10,"STRING IS NOT PALINDROME$"
.CODE
MOV AX,@DATA ; INITIALIZE DATA & EXTRA SEGMENT REGISTER
MOV DS, AX
MOV ES, AX
LEA DX, MSG1 ; DISPLAY ENTER THE STRING MESSAGE
MOV AH, 09H
INT 21H
MOV SI, 0
Result:
ENTER A STRING: MADAM
STRING IS PALINDROME
ENTER A STRING: BRINDAVAN
STRING IS NOT PALINDROME
A palindrome is a word or a number or a sequence of words that can be read the same way from either
direction, forwards or backwards. Punctuation and spaces between the words or lettering is allowed.
Ex:level, noon, madam, radar, refer, repaper, rotator, wow, mygym, topspot, nolemon nomelon
A combination is a way of selecting items from a collection, such that (unlike permutations) the order
of selection does not matter.
.MODEL SMALL
.DATA
MSG1 DB 13, 10,"CURRENT TIME IS: $"
MSG2 DB 13, 10,"CURRENT DATE IS: $"
.CODE
MOV AX,@DATA ; INITIALIZE DATA SEGMENT REGISTER
MOVDS, AX
LEA DX, MSG1
MOV AH, 09H
INT 21H
MOV AH, 2CH ; DOS INTERRUPT TO GET THE SYSTEM TIME. WHEN THIS IS EXECUTED, AUTOMATICALLY
INT 21H CH CONTAINS HOUR, CL CONTAINS MINUTE, DH SECONDS AND DL MILISECONDS
MOV AL, CH
CALL DISP ; DISPLAY HOUR
MOV DL,':'
MOV AH, 02H
INT 21H
LEA DX,MSG2
MOV AH,09H
INT 21H
MOV AL, DL
CALL DISP ; DISPLAY DAY
MOV DL,'/'
MOV AH,02H
INT 21H
MOV AL, DH
CALL DISP ; DISPLAY MONTH
DISP PROC
AAM
ADD AX,3030H
MOV BX,AX
MOV DL,BH
MOV AH,02H
INT 21H
MOV DL,BL
MOV AH,02H
INT 21H
RET
DISP ENDP
END
Result:
Current Time is: 10:45:20
Current Date is: 10/4/17
O/P = 0x00005555
O/P = 0x5500AA55
O/P = 0x40000000 35 45
#include<lpc214x.h>
#include<stdio.h>
main()
{
int a=6,b=2,sum,mul,sub,div;
sum=a+b;
mul=a*b;
sub=a-b;
div=a/b;
}
O/P
r5 =0x00000006
r6 =0x00000002
r7 =0x00000008
r8 =0x0000000C
r9 =0x00000004
r10 =0x00000003
.CODE
MOV AX,@DATA
MOV DS,AX
MOV DX,CR
MOV AL,CW
OUT DX,AL
MOV AH,01H
INT 21H
MOV DX,PB
IN AL,DX
CALL DELAY
MOV BL,AL
MOV AH,01H
INT 21H
MOV DX,PB
IN AL,DX
CALL DELAY
MUL BL
MOV DX,PA
OUT DX,AL
MOV AH,4CH
INT 21H
OUTPUT:
The program performs the multiplication between two bytes and gives the result.Result will be
displayed on the port A of the logic controller.
Output:
This program displays “FIRE” and “HELP” on seven segment display interface
The reason for using a stepper motor is to achieve precise control: you can make it move through a
defined angle. But there are drawbacks too. Stepper motors can sometimes be quite jerky, because they
start and stop each step with a sudden impulse, which isn't always what you want if you're trying to
build a precision machine.
.MODEL SMALL
.STACK
.DATA
PA EQU 0E880H
PB EQU 0E881H
PC EQU 0E882H
CR EQU 0E883H
CW EQU 80H
X DB 80H,90H,0A1H,0B1H,0C0H,0CDH
DB 0DAH,0E5H,0EEH,0F6H,0FBH,0FEH,0FFH
DB 0FEH,0FBH,0F6H,0EEH,0E5H,0DAH
DB 0CDH,0C0H,0B1H,90H,80H ; values of „ Ɵ „
DB 70H,5FH,4FH,40H,33H,26H
DB 1BH,12H,0AH,05H,02H,00H
DB 02H,05H,0AH,02H,12H,1BH,26H
DB 33H,40H,4FH,5FH,70H
LENDW $-X
.CODE
MOVAX,@DATA
MOVDS,AX
MOV AL, CW
MOVDX,CR
OUTDX,AL
MOV BP,07H
AGAIN:MOV BX,0FFFFH
L2:MOVCX,LEN ; CX = 48
LEASI,X
MOVDX,PA
L1:MOV AL,[SI]
OUTDX,AL
INC SI
LOOP L1
DECBX
JNZ L2
DECBP
JNZ AGAIN
MOV AH,4CH
INT 21H
END
#include<LPC214X.H>
// #include<stdlib.h>
// #include<string.h>
#define EN (1 << 10) //enable set to pin 10
#define RW (1 << 12) //RW set to pin 11
#define RS (1 << 13) //RS set to pin 13
// #define BUZZ (1 << 25)
#define DATA (0Xff << 15) // Data pin selection from P0.15 to P0.22
#define port EN | RW | RS | DATA // define all to port
}
void data(char d) // DATA mode RS=1, RW=0, En=1 then EN=0
{
IOPIN0 = d << 15; // Sending data to data pins
IOCLR0 = RW;
IOSET0 = RS;
IOSET0 = EN;
delay(25);
IOCLR0 = EN;
}
void delay(int count)
{
int i,j;
for(i = 0;i < count;i++)
for(j = 0;j < 5000;j++);
}
int main()
{
while(*string_2)
{
data(*string_2);
string_2++;
}
Output:
WELCOME TO VTU
Main.C
#include "lpc21xx.h"
#include "motor.h"
int main(void)
{
init_motor();
while(1)
{
// rotate_motor_clock_wise();
rotate_motor_anticlock_wise();
}
Motor.C
#include "LPC214x.H"
#include "motor.h"
#definePIN1 (1<<27)
#definePIN2 (1<<28)
#definePIN3 (1<<29)
#definePIN4 (1<<30)
void init_motor()
{
IODIR1 = (PIN1|PIN2|PIN3|PIN4);
}
void rotate_motor_anticlock_wise()
{
unsigned char i;
// for(i=0;i<25;i++)
{
IOCLR1 = (PIN1|PIN2|PIN4);
IOSET1 = PIN3;
delay();
IOCLR1 = (PIN3|PIN2|PIN4);
IOSET1 = PIN1;
delay();
IOCLR1 = (PIN1|PIN3|PIN2);
IOSET1 = PIN4;
delay();
IOCLR1 = (PIN1|PIN3|PIN4);
IOSET1 = PIN2;
delay();
}
void rotate_motor_clock_wise()
{
unsigned char i;
// for(i=0;i<25;i++)
{
IOCLR1 = (PIN2|PIN3|PIN4);
IOSET1 = PIN1;
delay();
IOCLR1 = (PIN1|PIN2|PIN4);
IOSET1 = PIN3;
delay();
IOCLR1 = (PIN1|PIN3|PIN4);
IOSET1 = PIN2;
delay();
IOCLR1 = (PIN1|PIN2|PIN3);
IOSET1 = PIN4;
delay();
}
}
void delay()
{
int i,j;
for(i=0;i<10000;i++)
{
for(j=0;j<50;j++)
{
continue;
}
}
}
Motor.h
extern void init_motor(void);
Address and data bus are multiplexed in 8086 (AD0-AD15) and 8088(AD0-AD7) to reduce the number
of pinsrequired for 8086/88 µp integrated circuit.Address and Data need to be de-multiplexed from thebus.
(Q: Why not leave it multiplexed? Ans:Memory and I/O require that the address remainsvalid and stable
throughout a read or write cycle. If the buses are multiplexed, the addresschanges at the memory and I/O, which
causes them to read or write data in the wrong locations.)
If more than 10 unit loads are attached to any bus pin, the entire 8086 or 8088 system must be buffered orIn
order to drive the system buses, which typically have manydevices attached and with large capacitance, the
addressand data output pins must be buffered.
INTERFACE:
Interface refers to the connection of peripheral device to CPU.
Connection of memory device to CPU is called as memory interface
Connection of I/O device to CPU is called as I/O interface