8/13/2019 Presentation on microprocessor programming
1/25
UNIVERSITY OF CALCUTTA.DEPARTMENT OF APPLIED PHYSICS.
SAIBAL KUMAR MITRA.INSTRUMENTATION ENGINEERING.
ROLL NO: 24.
8/13/2019 Presentation on microprocessor programming
2/25
Some unsigned single byte numbers are storedat consecutive memory locations starting fromX. Write a programme to add those numbers
taking into account of any possible overflow ateach step. Store the result as a double precisionnumber at two consecutive memory locations Y
and Y+1. Number of data to be added is givenat the memory location X-1 .
8/13/2019 Presentation on microprocessor programming
3/25
Step 1. START.Step 2. Initialize H-L pair as pointer to memory location X-1.Step 3. Move data from memory location X-1 , to register C, which will be used asa counter.Step 4. Clear register D, and register E.Step 5. Increment the pointer.Step 6. Move data from memory location currently pointed to by H-L pair, toaccumulator.Step 6. Add content of register E to that of accumulator.Step 7. Move the result to register E.Step 8. Clear the accumulator.Step 9. Add the content of register D, and accumulator A with carry.Step 10. Move data from accumulator to register D.Step 11. Decrement the count in register C.Step 12. Jump to step 5 if the count is not zero.Step 13. Exchange contents of D-E pair with H-L pair.Step 14. Store contents of H-L pair to memory location Y and Y+1.Step 15. STOP.
8/13/2019 Presentation on microprocessor programming
4/25
Address Mnemonic Opcode/ data Comment
8000 LXI H 84FF 21 H-L pair initializedto 1 st address 84FF.
8001 FF
8002 84
8003 MOV C, M 4E C is loaded with thecontent of memory
location.
8004 MVI D, 00 16 D is made empty by loading 00
8005 00
8006 MOV E, D 5A E is also madeempty by loading
00
8007 INX H 23 Content of H-L pairis incremented by
1.
8/13/2019 Presentation on microprocessor programming
5/25
Address Mnemonic Opcode/ data Comment
8008 MOV A, M 7E Content of thememory location
currently pointed to
by H-L pair, istransferred toaccumulator.
8009 ADD E 83 Content of E isadded to that of aand the result is
stored in A.
800A MOV E, A 5F Content of A istransferred back toE. E contains theleast significcant
byte of the double precision number.
800B MVI A, 00 3E A is made empty byloading 00
800C 00
8/13/2019 Presentation on microprocessor programming
6/25
address Mnemonic Opcode/ data Comment
800D ADC D 8A Content of D andthe carry bit of flag
register(from theoperation ADD E)
are added to thecontent of A, and
the result stored inA.
800E MOV D, A 57 Now the content ofA is transferred
back to D.
800F DCR C 0D Counter isdecremented by 1after each addition
process
8/13/2019 Presentation on microprocessor programming
7/25
Address Mnemonic Opcode/ data Comment
8010 JNZ 8007 C2 Jump to memorylocation 8007 if
Z=08011 07
8012 808013 XCHG EB Content of D-E pair
and H-L pair areexchanged.
Hcontains the
higher byte, while Lcontains the lower byte.
8014 SHLD 9500 22 Content of L goesto the address given
in the instructionwhile content of H
goes to the nextaddress.
8015 00
8016 95
8017 HLT 76 End of programme.
8/13/2019 Presentation on microprocessor programming
8/25
Memory location Data
84FF 05
8500 F6
8501 E88502 AD
8503 C9
8504 BC
OUTPUT
Memory location Data
9500 10
9501 04
8/13/2019 Presentation on microprocessor programming
9/25
Ten 8-bit numbers are stored starting from
memory location 3100 H. Find thegreatest of the ten numbers and store it atmemory location 3500 H.
8/13/2019 Presentation on microprocessor programming
10/25
1. START2. Store 0A in the register D.3. Point the HL pair to the starting
address of the data block.4. Move the content of memory
location to accumulator.5. Decrement register D.6. Check if the D register is 0. if
yes go to step 10.7. Increment pointer.8. Compare content of memory
location with accumulator.9. Check for CY Flag. If CY=1 go
to step 4, else go to 5.10.Store accumulator at the
memory location 9050H.
11.STOP
8/13/2019 Presentation on microprocessor programming
11/25
Address Mnemonic Opcode/ data Comment
8000 MVI D, 0A 16 D register is loadedwith 0A.
8001 0A
8002 LXI H 9000 21 H-L pair initializedto 1 st address 9000.
8003 00
8004 90
8005 MOV A, M 7E Content of thememory location
currently pointed to by H-L pair, is
transferred toaccumulator.
8/13/2019 Presentation on microprocessor programming
12/25
Address Mnemonic Opcode/ data Comment
8006 DCR D 15 Counter is
decremented by 1after each addition process
8007 JZ 8012 CA Jump to memorylocation 8012 if Z=1
8008 12
8009 80
800A INX H 23 Content of H-L pair is
incremented by 1.
800B CMP M Content of thememory location is
compared with that ofthe accumulator.
8/13/2019 Presentation on microprocessor programming
13/25
Address Mnemonic Opcode/ data Comment
800C JC 8005 Jump to memorylocation 8005 if
CY=1800D 05
800E 80
800F JMP 8006 Jumpunconditionally to
address 80068010 06
8011 80
8012 STA 9050H 32 Store accumulator
in the memorylocation 90508013 50
8014 90
8015 HLT 76 End of programme.
8/13/2019 Presentation on microprocessor programming
14/25
Memory location Data
9000 109001 20
9002 30
9003 40
9004 509005 60
9006 70
9007 80
9008 90
9009 A0
INPUT
8/13/2019 Presentation on microprocessor programming
15/25
Memory location Data9050 A0
OUTPUT
8/13/2019 Presentation on microprocessor programming
16/25
Write a programme that reads the gray code bits
from a memory location, find the binary codecorresponding to the gray code and store it inanother location.
8/13/2019 Presentation on microprocessor programming
17/25
The following algorithm converts an 8 bit graycode g 7, g7, g1, g0 into an 8 bit binary number
b7, b6 , b 1, b0 b7= g 7 b i = g i gi+1 0 i 7
8/13/2019 Presentation on microprocessor programming
18/25
Step 1. START.Step 2. load the accumulator with the data taken from a
specified locationStep 3. copy that data to register B from Accumulator.Step 3. Do AND operation between 80 and the content ofaccumulator.
Step 4. copy data from accumulator to register B.Step 5. rotate content of accumulator to right.Step 6. do XOR operation between content of accumulatorand that of register B.Step 7. do OR operation between content of register C andthat of accumulator.Step 8. store result in a specified memory location.Step 9. STOP.
8/13/2019 Presentation on microprocessor programming
19/25
Address Mnemonic Opcode/ data Comment
A000 LDA A200 3A A is loaded withthe content of the
memory locationA200.
A001 00
A002 A2
A003 MOV B, A 47 B Is loaded with
the content of A to preserve the inputdata.
A004 ANI 80 E6 Content of A isANDed with 80.
This is done tocreate a numberwhose msb is same
as that of theoriginal input data,
with other data being 0.
A005 80
8/13/2019 Presentation on microprocessor programming
20/25
Address Mnemonic Opcode/ data Comment
A006 MOV C,A 4F This newlycreated number is
stored in C
A007 MOV A,B 78 Original inputdata is again
taken into B.A008 RRC 0F Input data in A is
roatated right.
A009 XRA B A8 Original input
data is XORedwith the number
created byshifting the inputdata by one place
to the right.
8/13/2019 Presentation on microprocessor programming
21/25
Address Mnemonic Opcode/ data CommentA00A ORA C B1 The result of XORing
is ORed with thecontent of C, so thatthe msb of the outputdata is same as that of
input data
A00B STA A300 32 Content of a is stored
at memory locationA300 as final output.
A00C 00
A00D A3
A00E HLT 76 End of programme.
8/13/2019 Presentation on microprocessor programming
22/25
Memory location DataA200 28H
Input
8/13/2019 Presentation on microprocessor programming
23/25
Memory location DataA300 3CH
OUTPUT
8/13/2019 Presentation on microprocessor programming
24/25
Here28H = 0010 1000 2
And its converted gray code is
0011 1100
which is equal to 3CH
8/13/2019 Presentation on microprocessor programming
25/25
THANK YOU.
ARE THERE ANY QUESTIONS?
Top Related