Lab Manual ECE212
Lab Manual ECE212
MICROPROCESSOR LAB
INDEX SR.NO. TOPICS 1. Study of 8085 microprocessor kit. 2. Write a program to add two 8-bit numbers using 8085 microprocessor. 3. Write a program to add two 16-bit numbers using 8085 microprocessor. 4. Write a program to subtract two 8-bit numbers. 5. Write a program to subtract two 16-bit numbers. 6. Write a program to multiply two 8-bit numbers by repetitive addition method using 8085 microprocessor. 7. Write a program to multiply two 8-bit numbers using rotation method using 8085. 8. Write a program to multiply 16-bit number with 8-bit number using 8085. 9. Write a program to generate fibbonaci series using 8085. 10. Write a program to sort series using bubble sort algorithm with 8085. 11. Study of 8086 mp kit. 12. Write a program to copy 12 bytes of data from source to destination using 8086. 13. Write a program to find maximum number from series with 8086. PAGE NO. 3-6 7-8 9-11 12-13 14-16 17
Exp 1: EXPT 13: Introduction to 8085 microprocessor kit 8085 micro processor: It is also known as CPU or complete computation engine that is fabricated on a single chip. The first microprocessor was INTEL 4004 introduced in 1971. It was not very powerful as it was used only for simple arithmetic operations. Secondly, it could process only 4 bits at a time.
Features of 8085 MP: 1. Control Unit Generates signals within uP to carry out the instruction, which has been decoded. In reality causes certain connections between blocks of the uP to be opened or closed, so that data goes where it is required, and so that ALU operations occur. 2. Arithmetic Logic Unit The ALU performs the actual numerical and logic operation such as add, subtract, AND, OR, etc. It uses data from memory and from accumulator to perform arithmetic. It always stores result of operation in Accumulator. 3. Registers
The 8085 includes six registers, one accumulator and one flag register. In addition, it has two 16-bit registers: the stack pointer and the program counter. They are described briefly as follows: The 8085 has six general-purpose registers to store 8-bit data; these are identified as B, C, D, E, H, and L as shown in the figure. They can be combined as register pairs - BC, DE, and HL - to perform some 16-bit operations. The programmer can use these registers to store or copy data into the registers by using data copy instructions. 4. Accumulator The accumulator is an 8-bit register that is a part of arithmetic/logic unit (ALU). This register is used to store 8-bit data and to perform arithmetic and logical operations. The result of an operation is stored in the accumulator. The accumulator is also identified as register A. 5. Flags The ALU includes five flip-flops, which are set or reset after an operation according to data conditions of the result in the accumulator and the flags which are Zero (Z), Carry (CY), Sign (S), Parity (P) and Auxiliary Carry (AC) flags. They are listed in the table and their bit positions in the flag register are shown in the figure below. The most commonly used flags are Zero, Carry, and Sign. The microprocessor uses these flags to test data conditions. For example, after an addition of two numbers, if the sum in the accumulator is larger than eight bits, the flip-flop uses to indicate a carry called the Carry flag (CY) which is set to one. When an arithmetic operation results in zero, the flipflop called the Zero (Z) flag is set to one. The flags are stored in the 8-bit register so that the programmer can examine these flags (data conditions) by accessing the register through an instruction. 6. Program Counter (PC) This 16-bit register deals with sequencing the execution of instructions. This register is a memory pointer. Memory locations have 16-bit addresses, and that is why this is a 16-bit register. The microprocessor uses this register to sequence the execution of the instructions. The function of the program counter is to point to the memory address from which the next byte is to be fetched. When a byte (machine code) is being fetched, the program counter is incremented by one to point to the next memory location 7. Stack Pointer (SP)
4
The stack pointer is also a 16-bit register used as a memory pointer. It points to a memory location in R/W memory called the stack. The beginning of the stack is defined by loading 16-bit address in the stack pointer. 8. 8085 System Bus: a). Address Bus One wire for each bit, therefore 16 bits = 16 wires is needed. Binary number carried alerts memory to open the designated box. Data (binary) can then be put in or taken out. The Address Bus consists of 16 wires, therefore 16 bits. Its "width" is 16 bits. A 16 bit binary number allows 216 different numbers, or 65536 different numbers, i.e., 0000000000000000 up to 1111111111111111. Because memory consists of boxes, each with a unique address, the size of the address bus determines the size of memory which can be used. To communicate with memory the microprocessor sends an address on the address bus, eg0000000000000011 (3 in decimal), to the memory. The memory selects box number 3 for reading or writing data. Address bus is unidirectional, i.e. numbers only sent from microprocessor to memory. b). Data Bus Data Bus: carries data, in binary form, between P and other external units, such as memory. Typical size is 8 or 16 bits. Size determined by size of boxes in memory and P size helps determine performance of P. The Data Bus typically consists of 8 wires, therefore, 28 combinations of binary digits. Data bus used to transmit "data", i.e. information, results of arithmetic, etc, between memory and the microprocessor. Bus is bi-directional. Size of the data bus determines what arithmetic can be done. If only 8 bits wide then largest number is 11111111 (255 in decimal). Therefore, larger number has to be broken down into chunks of 255 which slow down the microprocessor. Data Bus also carries instructions from memory to the microprocessor. Size of the bus therefore limits the number of possible instructions to 256, each specified by a separate number. c). Control Bus: Control Bus consists of various lines which have specific functions for coordinating and controlling P operations. eg: Read/Not Write line, single binary digit. Control whether memory is being written to (data stored in memory) or read from (data taken out of memory) 1 = Read, 0 = Write. There May also be clock line(s) for timing/synchronizing, interrupts, reset etc.
MEMORY MACHINE L MNEOADDRESS CODE/DATA A MONICS B E L 2000 21 LXI 2001 01 2002 25 2003 7E MOV 2004 23 INX 2005 2006 2007 2008 86 23 77 76 ADD INX MOV HLT
OPERANDS COMMENTS
H,2501
A,M H M H M,A
First no. in accumulator Increment contents of HL pair Add first and second no. Contents of HL pair become 2503 H Store sum in 2503 H stop
10
MEMORY MACHINE LABEL MNEOMONICS OPERANDS COMMENTS ADDRESS CODE/DATA 2000 2A LHLD H,2501H Load first no. in HL pair 2001 01 2002 25 2003 EB XCHG Get first no. in DE pair 2004 2A LHLD H,2503H Load second no. in HL pair 2005 03 2006 25 2007 0E MVI C,00 Move MSB in C(initially 00H) 2008 00 2009 19 DAD D Add first and second no. 200A D2 JNC AHEAD Jump to label if no carry 200B 0E 200C 20 200D 0C INR C If yes,then increment C 200E 22 AHEAD SHLD H,2505 Stores the sum in 2505&2506H 200F 05 2010 25 2011 79 MOV A,C Carry of sum in A 2012 32 STA 2507H Store contents of
11
HLT
Stop
12
13
MEMORY MACHINE LABEL MNEOMONICS OPERANDS COMMENTS ADDRESS CODE/DATA 3501 21H LXI H,2501 Point first no. 3502 01 3503 25 3504 7E MOV A,M First no. in accumulator 3505 23 INX H Increments content of HL pair 3506 96 SUB M Subtract first and second no. 3507 23 INX H Contents of HL pair 3508 77 MOV M,A Store result 3509 EF HLT stop RESULT: 2503: 5B
14
15
MOV
A,M
23 96 32 05 25 23 7E
H M 2505H
INX MOV
H A,M
200B
23
INX
200C 200D
16
9E 32
SBB STA
M 2506H
Take MSB of first no. Move contents to accumulator Increment and take MSB of second no. Subtract two MSBs Store result at memory
MVI
A,00H
Move 00H to accumulator to borrow Rotate one left with carry Store result for borrow
00 17 32 07 25 EF
HLT
stop
17
6. Write a program to multiply two 8 bit numbers by repetitive addition using 8085.
MEMORY ADDRESS 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 200A 200B 200C 200D 200E 200F 2010 2011 2012 2013 2014 2015 Data: 2500-------20 2501-------03 Result: 2503-------60 2504-------00
18
MOV MVI
E,A D,00H
LDA
25O1H
MOV LXI
C,A H,0000H
BACK
D C BACK
SHLD
2503H
Stores result
HLT
Stop
EXPT 7: Write an assembly language program to generate Fibonacci series. MEMORY ADDRESS 2000 MACHINE LABEL CODE/DATA 21 MNEMONICS OPERANDS COMMENTS LXI H,2501H Load imm. Data 2501H to HL pair
01 25 0E
MVI
C,09H
Set the counter to 9 count Clear B Move D=01H Copy B to A A=A+D Copy B to D Copy A to B Store A into memory H=H+1 C=C-1 Jump if zero flag=0
2004 2005 2006 2007 2008 2009 200A 200B 200C 200D 200E 200F 2010 2011 2012 2013 Result:
09 06 00 16 01 78 82 50 47 77 23 0D C2 09 20 EF
MVI MVI
B,00 D,01H
Repeat
HLT
Stop
19
EXPERIMENT 8: Write a program to multiply two 8-bit nos. using rotation method. MEMORY ADDRESS 3000 MACHINE LABEL CODE/DATA 21 MNEMONICS OPERANDS COMMENTS LXI H,2501H Load data in HL register pair
01 25 5E
MOV
E,M
3004
16
MVI
D,00H
Move contents of memory to register E Move imm.data 00H to register D Increment contents of HL pair by one Move memory contents to accumulator Load immediate data to HL pair
3005 3006
00 23
INX
3007
7E
MOV
A,M
3008
21
LXI
H,0000H
00 00 06
MVI
B,O8H
Move imm.data 08H to register B Add contents of DE with HL pair and save result
300C 300D
08 29
DAD
20
300E
17
RAL
D2 13 30 19
JNC
3013
DAD
3013
05
DCR
C2 0D 30 22
JNZ
300D
Add contents of D with HL pair and store result in HL pair Decrement contents of register B by one Jump if no carry
SHLD
2503H
03 25 EF
HLT
Stop
21
EXPERIMENT 9: Write an assembly language program to multiply 16-bit no. with 8 bit no. MEMORY ADDRESS 2001 MACHINE LABEL CODE/DATA 2A MNEMONICS OPERANDS COMMENTS LHLD 2501H Load HL pair with contents of given address.
01 25 EB 21
XCHG LXI
H,2503H
03 25 4E 21
MOV LXI
C,M H,0000H
to
00 00 19 0D C2 0C 20 22
BACK
SHLD
2504H
HLT
Stop
EXPT 10: Write a program to sort series using bubble sort algorithm using 8085
MEMORY ADDRESS 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 200A 200B 200C 200D 200E 200F 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 201A 201B Subroutine: 2030 2031 2032 2033 2034
23
D=02
C=02
MOVE MEMORY TO B COPY A TO MEMORY DECREMENT H BY 1 MOVE CONTENTS OF B TO MEMORY INCREMENT H DECREMENT C JUMP IF ZERO FLAG IS 0
DCR JNZ
D 2005
M,A
TO THE
A, M H 2012
24
25
26
EXPT 12: Write an assembly language program to copy 12 bytes of data from source to destination using 8086 MP.
27
DATA SEGMENT TEST_MESS DB TIME FOR DESTINATION DB 100 DUP(?) NEW_LOC DB 12 DUP(0) DATA ENDS CODE SEGMENT ASSUME CS: CODE, DS: DATA, ES: DATA START: MOV AX, DATA MOV CX, 12 CLD MOV DS, AX MOV ES, AX LEA SI, TEST_MESS LEA DI, NEW_LOC REP MOVSB CODE ENDS END START Result: 12 Bytes will be transferred from SI to DI
28
MEMORY ADDRESS 2100 2102 2103 2104 2105 2106 2107 2108 2109 210A 210B 210C 210D 210E 210F 2110 2111 2112
MNEMONICS OPERANDS COMMENTS MOV AX, 0000 Clear A for first comparison Set data position Copy from memory Increment SI register Increment SI register Compare A with memory Jump if above or equal Again copy from memory Keep in the loop until CX becomes 0 Store the result at 2600H Stop
MOV
SI, 2500
JAE
GO
MOV
AX, [SI]
LOOP
BACK
A3 51 02 CC
MOV
[2600], AX
INT3
Data: 2500----05 2501----00 2502----41 2503----83 2504----58 2505----72 2506----39 2507----46 2508----53 2509----84 250A----30 250B----96 Result: 2600----30 2601----96
30