Está en la página 1de 30

LABORATORY MANUAL ECE-212

MICROPROCESSOR LAB

Prepared By: Gursharanjeet Singh (13586) P

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

18 19-20 21 22-23 24-25 26-27 28-29

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.

Following is 8085 trainer kit model:

EXPT2: Write a program to add two 8-bit numbers. FLOWCHART

DATA: 2501--------48H 2502--------52H


7

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

Points first no.

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

Result: The resultant will be stored at 2503. 2503----------- 9A

EXPT3: Write a program to add two 16-bit numbers.

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

A in 2507H 2013 2014 2015 07 25 76

HLT

Stop

12

EXPT4: Write an assembly language program to subtract two 8 bit numbers.

DATA: 2501-------- 84H 2502-------- 29H

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

Experiment 5: Write an assembly language program to subtract two 16-bit numbers.

15

Data: 1st no.= 8423H 2ND NO.=6926H

MEMORY ADDRESS 2000 2001 2002 2003

MACHINE LABEL CODE/DATA 21 01 25 7E

MNEMONICS OPERANDS COMMENTS LXI H,2501H Take LSB of first no.

MOV

A,M

2004 2005 2006 2007 2008 2009 200A

23 96 32 05 25 23 7E

INX SUB STA

H M 2505H

Move contents to accumumlator Increment Subtract two LSB Store result

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

location. 200E 200F 2010 06 25 3E

MVI

A,00H

Move 00H to accumulator to borrow Rotate one left with carry Store result for borrow

2011 2012 2013 2014 2015 2016 RESULT:

00 17 32 07 25 EF

RAL STA 2507H

HLT

stop

2505------FDH 2506------1AH 2507------00H

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

MACHINE LABEL CODE/DATA 3A 00 25 5F 16 00 3A 01 25 4F 21 00 00 19 0D C2 0D 20 22 03 25 EF

MNEMONICS OPERANDS COMMENTS LDA 2500H Points first no. to

MOV MVI

E,A D,00H

Move first no. to register

Clear register D Loads data

LDA

25O1H

MOV LXI

C,A H,0000H

Move contents of A in C Load HL pair immediately

BACK

DAD DCR JNZ

D C BACK

Add two nos. Decrement C


Jump to BACK if no zero

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

2001 2002 2003

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

MOV ADD MOV MOV MOV INX DCR JNZ

A,B D D,B B,A M,A H C Repeat

HLT

Stop

From 2501 to 2509: 01,01,02,03,05,08,0D,15,22.

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

3001 3002 3003

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

3009 300A 300B

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

300F 3010 3011 3012

D2 13 30 19

JNC

3013

in HL pair Rotate contents of A by 1 bit to left Jump if no carry

DAD

3013

05

DCR

3014 3015 3016 3017

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

Store contents of HL pair into memory

3018 3019 301A

03 25 EF

HLT

Stop

Data: 2501-------08H 2502-------09H Result: 2503-------48H 2504-------00H

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.

2002 2003 2004 2005

01 25 EB 21

XCHG LXI

H,2503H

Load HL pair with 2503H

2006 2007 2008 2009

03 25 4E 21

MOV LXI

C,M H,0000H

Move contents of memory to C

Move 0000H HL pair

to

200A 200B 200C 200D 200E 200F 2010 2011

00 00 19 0D C2 0C 20 22

BACK

DAD D DCR JNZ C BACK

Add contents DE pair with HL pair Decrement C by 1 Jump if no zero

SHLD

2504H

Store HL at 2504 and 2505H

2012 04 2013 25 2014 EF Data: 2501-----20H 2502----01H 2503----30H Result:2504----00H 2505----36H


22

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

MACHINE LABEL CODE/DATA 21 00 25 16 01 0E 02 7E 23 BE DA 30 20 46 77 2B 70 23 0D C2 07 20 15 C2 05 20 77 EF 77 23 C3 12 20

MNEMONICS OPERANDS COMMENTS LXI H, 2500H


HL=2500

MVI MVI MOV INX CMP JC

D, 02H C, 02H A, M H M 2030

D=02

C=02

MOVE CONTENTS OF MEMORY IN A INCREMENT


COMPARE A AND M IF CARRY FLAG IS 1 THEN JUMP TO 2030

MOV MOV DCX MOV INX DCR JNZ

B,M M,A H M,B H C 2007

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

DECREMENT D JUMP IF ZERO FLAG

MOV HLT MOV INX JMP

M,A

COPY A MEMORY HALT PROCESSOR

TO THE

A, M H 2012

COPY MEMORY TO A INCREMENT H JUMP TO 2012

Data input: 2500-----87 2501-----37 2502-----48 Result: 2500-----37 2501-----48 2502-----87

24

EXPT 11: Introduction to 8086 microprocessor kit.

25

26

EXPT 12: Write an assembly language program to copy 12 bytes of data from source to destination using 8086 MP.

This experiment can be performed by emulator available at: emu8086.com

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

EXPT 13: Write a program to find maximum no. in the series

MEMORY ADDRESS 2100 2102 2103 2104 2105 2106 2107 2108 2109 210A 210B 210C 210D 210E 210F 2110 2111 2112

MACHINE LABEL CODE/DATA B8 00 00 BE 00 25 8B 0C 46 BACK 46 3B 04 73 02 8B 04 E2 F6 GO

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

MOV INC INC CMP

CX, [SI] SI SI AX, [SI]

JAE

GO

MOV

AX, [SI]

LOOP

BACK

2113 2114 2115 2116


29

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