Running 2 Youtube Channel : The Masti Adda (Fun based ) : The Knowledge Adda (Knowledge based) : Subscribe for Knowledge with Fun....

How to write a program in Microprocessor

Written by @
Example : Write a program to add 05 H and 04 H using Register A and B.
Suppose we have to write a program to add two given number 05 H and 04 H using Register A and B.
In this given program you have to write a program to add two number 05 H and 04 H using Register A and B. In this program data are already given. But sometimes data are not given ,and you have to write a addition program which is applicable for every addition program. Sometimes data is refer as Byte because one byte contains 8 bit and both given data are 8-bit data.
Now you have to add these data using Register A and B.
Firstly we have to load data in corresponding Given Register A and B.
05 H and 04 H both are 8-bit data. To store these data we have to use MVI. MVI instruction generally used to load or store the data in given register. Suppose we have to store 05 H in Register A. Then
MVI A,05 H - Now 05 H has been store in Register A . Same as
MVI B,04 H - 04 H has been store in Register B
Now we have already store 05 H and 04 H in given corresponding register A and B.
Now we have to add A and B.
ADD B- This will ADD A and B.
ADD instruction add the content of given register to A. So ADD B will add the Content of Register B to Content of Accumulator.Now this program is complete but we have write RST 5 and END also.
RST 5 - This is a break point ,used to execute the program step by step.
END- Used to ending the Program. Now your complete program is

MVI A,05 H
MVI B,04 H
ADD B
RST 5
END



This is theoretical aspect of Microprocessor programming. Now in the Microprocessor Lab.
In microprocessor kit ,you need not write to H because by default microprocessor kit accept Hexadecimal Value.
In Microprocessor kit you have to provide RAM address to write any instruction and it also represent the starting address of program. Suppose you have written

2000 MVI B,04 H
Where 2000 represent the RAM address for this particular Instruction. Each instruction occupy the RAM address and it is also depend on the nature of instruction. Which type of instruction are (1 Byte,2 Byte,3 Byte). 1 Byte occupy 1 RAM address,2 Byte-2 RAM address, 3 Byte-3 RAM address.
RAM addresses are 16 bit data.
Now in this given example

2000 MVI A,05 H


2000 is RAM address for MVI A. Now next RAM address depend on the nature of MVI A. MVI instruction is two byte instruction so it contains 2 byte instruction. So next RAM address will be 2002.

2000 MVI A
2001 05 H

But in the machine when you write first line and press the Enter then it will show 2002 because MVI is 2-byte instruction and by default it will consume 2 RAM address. Same as

2000 MVI A,05 H
2002 MVI B,04 H
2004 ADD B
Now ADD B is one byte instruction so it will contain only 1 RAM address. Now whole Program
2000 MVI A,05 H
2002 MVI B,04 H
2004 ADD B
2005 RST 5
2006 END


For subtraction program Just replace ADD B to SUB B
Write a program to Add two 8-bit number using memory location.
In above mention program you have to write a program to add two 8 bit number using memory location. In this program user can enter different data. No need to change the program again and again. In this program input is not fixed. Basically memory location is representation for the input.
Suppose we have to add two 8 bit number using memory location 2050 and 2051 H. Suppose first number is stored at 2050 H and Second Number is stored at 2051 H. Output will be stored at 2052 H.
Now first instruction is written as like this
LXI H, 2050 H-- Now this line indicates the we have load the memory location in H-L pair. Content of L will be 50 and Content of H will be 20 H. Now 2050 H is location for the first number.
MOV A,M- In this line the content of memory location (2500 H) will copy into accumulator. Now content of accumulator will be the first number.

INX H- This will increase the value of H-L pair,so we get 2051 next memory location that represent the second number.

ADD M . M represents the previous memory location (2051 H ) and we know ADD M means (A+M) where A is First Number and M is second number. Now output is stored in Accumulator.

STA 2052. It will store the content of accumulator at the given location. So Output is stored at 2052 H.

RST 5 - This is a break point ,used to execute the program step by step.
END- Used to ending the Program. Now your complete program is


2000 LXI H ,2050 H
2003 MOV A,M
2004 INX H
2005 ADD M
2006 STA 2052
2009 RST 5
200A END

For execution of the program ,After ending the program press ENTER then Press G and provide initial memory address (2000) and press SHIFT+4. Press M and write your first memory location 2050 and press ENTER.
2050: First Data-Press ENTER
2051:Second Data -Press ENTER
Press SHIFT+4- M and Provide output location (2052) and You will get output.

1 comment:

  1. sir how to download microprocessor lab manual

    ReplyDelete