48922857 Microprocessor Programs
-
Upload
manoj-kumar -
Category
Documents
-
view
269 -
download
0
Transcript of 48922857 Microprocessor Programs
MICROPROCESSOR LABORATORY
LIST OF EXPERIMENTS
I. 8085 Programming 50 Marks
Study of 8085 Microprocessor1. 8 bit Addition, Subtraction2. 8 bit Multiplication and Division.3. 16 bit Addition4. 16 bit Subtraction5. BCD to Hex 6. Hex to BCD code conversion.7. Largest and smallest of a given set of numbers.8. Block Movement of Data.
NOTE:Write “Procedure” in the record after algorithm:PROCEDURE:Entering the program in the kit, entering input in the kit, executing the program and observing the output (In your own words- Not as given here)
RECORD NOTEBOOK / OBSERVATION WRITING FORMAT
LEFT HAND SIDE(UNRULED)
RIGHT HAND SIDE(RULED)
1. SAMPLE INPUT AND OUTPUT 1 AIM2. INPUT AND OUTPUT 2 APPARATUS REQUIRED3. DIAGRAM IF ANY REQUIRED(INSTRUCTED BY INCHARGE) (in record only)
3 ALGORITHM
4 PROCEDURE5 PROGRAM6 RESULT
1
8085 PROGRAMMING
1. STUDY OF 8085 PROCESSORDraw 8085 architecture diagram in the record
WRITE ABOUT ARCHITECHTURE OF 8085 FOR 4 PAGES. (LEAVE FOUR –FIVE PAGES FOR THIS STUDY)
2
2. 8-BIT ADDITION AND SUBTRACTION
AIM:To write and execute an assembly language program to perform the addition and
subtraction two eight bit numbers using 8085 kit.
a) ADDITION
ALGORITHM:
Step 1 : Start.Step 2 : Clear C register for carryStep 3 : Load the first data from memory to accumulator and move it to B register.Step 4 : Load the second data from memory to accumulator.Step 5 : Add the content of B register to the accumulator.Step 6 : Check for carry. If carry = 1, go to step 7 else if carry =0, go to step 8.Step 7 : Increment the C register. Step 8 : Store the sum in memoryStep 9 : Move the carry to accumulator and store in memory
Step 10 : End Program
PROGRAM:
MemoryAddress
LabelHex code
Mnemonics&& Comments
Opcode Operand8000 0E,00 MVI C,00 Clear C register for carry8002 3A, 00, 90 LDA 9000 Load the first data from memory to
accumulator 8005 47 MOV B,A Move the data to B register.8006 3A, 01, 90 LDA 9001 Load the second data from
memory to accumulator.8009 80 ADD B Add the content of B register to the
accumulator.800A D2, 0E, 80 JNC 800E (L1) Check for carry. If carry = 1,
increment carry register else if carry =0 store the result
800D 0C INR C Increment the C register for carry800E L1 32, 00, 95 STA 9500 Store the sum in memory8011 79 MOV A,C Move the carry to accumulator 8012 32, 01, 95 STA 9501 Store Carry in memory8015 CF RST 1 End the program
Note: RST 1 can be replaced by HLT also to terminate the program. Hex code for HLT is 76.
3
SAMPLE INPUT & OUTPUT:
Before ExecutionMemory Address
Data
9000 AE Addend9001 FD Augend
b) SUBTRACTION:
ALGORITHM:
Step 1 : Start.Step 2 : Clear C register to account for sign of the result.
Step 3 :Load the subtrahend (the data to be subtracted) from memory to accumulator and move it to B register.
Step 4 : Load the minuend from memory to accumulator.Step 5 : Subtract the content of B register from the content of the accumulator.Step 6 : Check for carry. If carry = 1, go to step 7 else if carry =0, go to step 8.Step 7 : Increment the C register. Complement the accumulator and add 01H.Step 8 : Store the difference in memory.
Step 9 :Move the content of C register (sign bit) to accumulator and store in memory.
Step 10 : End program
PROGRAM:
Memory Address Lab
el
Hex Code
MnemonicsCommentsOpcod
eOperand
8000 0E, 00 MVI C,00 C register is used as a carry counter and initiated
8002 3A, 00, 90 LDA 9000 Subtrahend is loaded in B register through Acc, 8005 47 MOV B,A
8006 3A, 01, 90 LDA 9001 Minuend is loaded in Acc.8009 90 SUB B Subtraction is performed and
the result is checked for carry. If carry is present carry counter is incremented
800A D2, 0E, 80 JNC 800E (L1)800D 0C INR C
800E L1 2F CMA If carry is present then the answer is in twos compliment form. So convert it in to original form
800F 3C INR A
8010 32, 01, 95 STA 9501 Store the result in memory location 9501
8013 79 MOV A,C Move the carry from c register to Acc and store it in memory location 9502
8014 32, 02, 95 STA 9502
8017 CF RST 1 Program ends.
4
5
SAMPLE INPUT & OUTPUT:
Before ExecutionMemory Address
Data
9000 EF Subtrahend9001 AF Minuend
RESULT:An assembly language program to perform the addition and subtraction two eight bit
numbers using 8085 kit is written and executed.
6
3. 8 BIT MULTIPLICATION AND DIVISION.
AIM:To write and execute an assembly language program to perform the
multiplication and division of two eight bit numbers using 8085 kit.
a) MULTIPLICATION
ALGORITHM:
Step 1 : Start.Step 2 : Clear Reg D for CarryStep 3 : Load 1st Number ( Multiplicand in Reg B through reg AStep 4 : Load 2nd Number ( Multiplier in Reg C through reg AStep 5 : Clear Reg A ( Accumulator)Step 6 : Now add content of Reg B with Reg AStep 7 : Check for Carry if carry NOT exists then skip next stepStep 8 : Decrement 2nd number ( multiplier) in Reg CStep 9 : Check for Reg C for zero, If NOT zero go to step 6 Else continue
Step 10 : Store the result ( product) in reg A into output memory addressStep 11 : Store the Carry in Reg D into next output memory addressStep 12 : End Program
PROGRAM:
MemoryAddress
Label Hex CodeMnemonics
CommentsOpcode Operand
8000 16,00 MVI D, 00 D register is initiated and used as a carry counter
8002 3A,00,90 LDA 9000 The multiplier in memory location 9000 is moved to B register through Acc
8005 47 MOV B, A
8006 3A,01,90 LDA 9001 The multiplicand in memory location 9001 is moved to c register through Acc
8009 4F MOV C, A
800A 3E,00 MVI A, 00 Acc is initiated for repeated addition
800C L2 80 ADD B In repeated addition carry is tested. If any carry is present then carry counter is incremented
800D D2,11,80 JNC L1 (8011)8010 14 INR D
8011 L1 0D DCR C Repeated addition is tested for multiplicand times8012 C2,0C,80 JNZ L2 (800C)
8015 32,00,95 STA 9500 The result is stored in the memory location 9500 and 9501
8018 7A MOV A, D8019 32,01,95 STA 95018022 CF RST 1 Program ends
7
SAMPLE INPUT & OUTPUT:
d) DIVISION
ALGORITHM:
Step 1 : Start.Step 2 : Clear C register to account for quotient.Step 3 : Load the divisor in accumulator and move it to B register.Step 4 : Load the dividend in the accumulator.Step 5 : Check whether divisor is less than dividend. If divisor is less than
dividend, go to step 9, else go to next step.Step 6 : Subtract the content of B register from accumulator.Step 7 : Increment the content of C register (quotient).Step 8 : Go to step 5.Step 9 : Store the content of accumulator (remainder) in memory.Step 10: Move the content of C register (quotient) to accumulator and store in
memory.Step 11 : End program.
PROGRAM:
Memory Address
Label Hex CodeMnemonics
CommentsOpcode Operand
8000 0E, 00 MVI C,00 Clear C register to account for quotient
8002 3A, 00, 90 LDA 9000 Load the divisor in accumulator and move it to B register.8005 47 MOV B,A
8006 3A, 01, 90 LDA 9001 Load the dividend in the accumulator.
8009 L2 B8 CMP B Check whether divisor is less than dividend. If so quotient is zero. Devisor is the Remainder .Go and store the results
800A DA, 12 ,80 JC 8012 (L1)
800D 90 SUB B Repeated subtraction starts.For each subtraction quotient register is incremented. This continues till the devisor becomes less than the devider
800E 0C INR C800F C3, 09, 80 JMP 8009 (L2)
8012 L1 32, 00, 95 STA 9500 The remainder is stored in memory location 9500
8015 79 MOV A,C Quotient is stored in the memory location through Acc8016 32, 01, 95 STA 9501
8019 CF RST 1 Program Ends
8
Before Execution
Memory Address
Data
4200 EF Multiplicand4201 AF Multiplier
After ExecutionMemory Address
Data
4202 61 LSB of Product
4203 A3 MSB of the Product
9
SAMPLE INPUT & OUTPUT:
RESULT:An assembly language program to perform the multiplication and division of two
eight bit numbers using 8085 is written and executed.
10
Before Execution
Memory Address
Data
9000 EF Divisor9001 AF Dividend
4. ADDITION OF TWO SIXTEEN BIT NUMBERS
AIM:
To write an assembly language program to perform the addition of two sixteen bit
numbers.
a) ADDITION
ALGORITHM:
Step 1 : Start.Step 2 : Clear C register for carry.Step 3 : Load the first data in HL register pair.Step 4 : Move the first data to DE register pair.Step 5 : Load the second data in HL register pair.Step 6 : Add the content of DE register pair to HL register pair.Step 7 : Check for carry. If carry = 1, go to step 8 else if carry =0, go to step
9.Step 8 : Increment the C register to account for carry. Step 9 : Store the sum in memory.Step 10: Move the carry to accumulator and store in memory.Step 11: End program.
PROGRAM:
Memory Address Label Hex Code
MnemonicsComments
Opcode Operand8000 0E, 00 MVI C,00 Initiate C register to store carry8002 2A, 00, 90 LHLD 9000 Load the first data in HL register pair
and move it to DE register pair8005 EB XCHG8006 2A, 02, 90 LHLD 9002 Load the second data in HL register pair8009 19 DAD D (HL)(HL)+(DE)800A D2, 0E, 80 JNC 800E (L1) If carry occurs increment the carry
counter800D 0C INR C800E L1 22, 00, 95 SHLD 9500 Store the 16 bit addition result in the
memory location starting form 9500 8011 79 MOV A,C Move the carry to the memory location
9502 through the Accumulator8012 32, 02, 95 STA 95028015 CF RST 1 Program ends
11
SAMPLE INPUT & OUTPUT:
RESULT:
An assembly language program to perform addition of two 16-bit numbers using 8085 is
written and executed.
12
Before Execution
Memory Address
Data
9000 CD Upper Byte (addend)
9001 AB Lower Byte (Addend)
9002 AA Upper Byte (Augend)
9003 AA Lower Byte (Augend)
After ExecutionMemory Address
Data
9500 77 Lower Byte Sum9501 56 Upper Byte Sum9502 01 Carry
5. SUBTRACTION OF TWO SIXTEEN BIT NUMBERS AIM:
To write an assembly language program to perform the subtraction of two sixteen
bit numbers.
ALGORITHM:
Step 1 : Start.Step 2 : Load the first data in HL register pair.Step 3 : Move the first data to DE register pair.Step 4 : Load the second data in HL register pair.Step 5 : Move the content of E to A. Step 6 : Subtract Content of L from A (Lower Bytes)Step 7 : Store the difference in the memoryStep 8 : Move the content of D to A. Step 9 : Subtract Content of H from A with borrow (higher Bytes)Step 10: Store the difference in the memoryStep 11: End program.
PROGRAM:
Memory Address Label Hex Code
MnemonicsComments
Opcode Operand8000 2A, 00, 90 LHLD 9000 The 16 bit minuend is stored in the DE
register pair through HL register pair8003 EB XCHG8004 2A, 02, 90 LHLD 9002 The subtrahend is stored in the HL register pair
8007 7B MOV A, E The lower byte of the minuend is moved to the accumulator
8008 95 SUB L The lower byte of the subtrahend is subtracted from the accumulator contents
8009 32, 00, 95 STA 9500 The lower byte result is stored in the memory location 9500
800C 7A MOV A, D Higher byte of the minuend is moved to Acc.
800D 9C SBB H Higher byte of the subtrahend is subtracted with borrow
800E 32, 01, 95 STA 9501 The higher byte result is stored in the memory location 9501
8011 CF RST 1 Program Ends
13
SAMPLE INPUT & OUTPUT:
RESULT:
An assembly language program to perform subtraction of two 16-bit numbers using 8085
is written and executed.
14
Before Execution
Memory Address
Data
9000 CD Upper Byte (Subtrahend)
9001 AB Lower Byte (Subtrahend)
9002 AA Upper Byte (Minuend)
9003 AA Lower Byte (Minuend)
After ExecutionMemory Address
Data
9500 23 Lower Byte Difference
9501 01 Upper Byte Difference
6. CONVERTING A BCD NUMBER TO HEX NUMBER
AIM:To write an assembly language program to convert BCD number in memory to
the equivalent HEX number using 8085.
a) BCD TO HEX CONVERSION
ALGORITHM:
Step 1 : StartStep 2 : Load the BCD number in accumulator (Reg A)Step 3 : Copy it to Reg EStep 4 : Mask the Lower Nibble of the BCD numberStep 5 : Rotate it 4 times to move Upper nibble to lower nibble placeStep 6 : Copy the number to Reg BStep 7 : Clear Reg A Step 8 : Copy number “0A” in Reg C (Decimal number 10)Step 9 : Multiply the number in B by 10dStep 10: Then move the product in Reg BStep 11: Copy the original number in Reg E to Reg AStep 12: Mask the Upper Nibble of the BCD NumberStep 13: Add the Number in Reg B with the number in Reg AStep 15: The number is copied to a memory locationStep 14: End program.
PROGRAM:
MemoryAddress
Label Hex CodeMnemonics
CommentsOpcode Operand
8000 3A, 00, 90 LDA 9000 Load the BCD number in Acc and copy it in E register.8003 5F MOV E, A
8004 E6, 0F ANI F0 The first digit of the BCD is masked.8006 0F RRC By rotating four times the lower
nibble and higher nibble are exchanged. ( that is the ten’s digit is bought to the Ones place)
8007 0F RRC8008 0F RRC8009 0F RRC800A 47 MOV B, A That is saved in the B register800B 3E,00 MVI A,00 The accumulator is initiated and
added with the B register contents continuously for ten times.(For this C register is stored with 0A and used as a counter
800D 0E, 0A MVI C,0A800F L1 80 ADD B8010 OD DCR C8011 C2, 0F, 80 JNZ 800F(L1)8014
47MOV B, A The ten’s value is stored in the B
register8015 MOV A, E The BCD number is stored in the
accumulator and the higher byte is masked to get the one’s value
8016 E6, F0 ANI 0F
8018 80 ADD B One’s value is added with the ten’s value
801932, 00, 95
STA 9500 The resulting hexadecimal number is stored in the memory location 9500
801C CF RST 1 The program ends
15
16
SAMPLE INPUT & OUTPUT:
RESULT:An assembly language program to convert the Binary coded decimal (BCD) into Hexadecimal number (HEX) has been written and executed using microprocessor 8085.
17
Before ExecutionMemory Address
Data
9000 29 (BCD)
After ExecutionMemory Address
Data
9500 1D (HEX)
7. CONVERTING HEXADECIMAL NUMBER TO BCD NUMBER
AIM:To write an assembly language program to convert HEX numbers in memory to the equivalent BCD number using 8085.
ALGORITHM:
Step 1 : StartStep 2 : Clear Reg D and E to store tens and hundreds respectivelyStep 3 : Load the HEX number in accumulator (Reg A)Step 4 : Compare Hex number with 64h (100d)(Check for Hundreds)Step 5 : If carry , HEX <64 so go to Check Tens ( Step 8 ) NO Carry Next stepStep 6 : Subtract 64 h (100s) from the number. Step 7 : Increment Reg E for each hundred and repeat step 6 until HEX
becomes less than 100d (64H)Step 8 : Compare Remaining Hex number with 0Ah (10d) (Check for Tens)Step 9 : If carry , Remaining HEX <10 so go to Check ones ( Step ) NO Carry
Next stepStep 10: Subtract 0A h (10s) from the number. Step 11: Increment Reg D for each hundred and repeat step 6 until HEX
becomes less than 10d (0AH)Step 12: Now the remaining is ones and is stored in Reg CStep 13: Now tens are copied from reg D to Reg AStep 15: The number is rotated 4 times to move it to tens position (upper
Nibble)Step 14: Then the number is added with ones in Reg cStep 15: Store the Combined tens and ones in reg A to memory location Step 16: Store the Hundreds in Reg E to next memory locationStep 17: End program.
18
PROGRAM:
MemoryAddress
Label
Hex CodeMnemonics
CommentsOpcode
Operand
8000 16, 00 MVI D, 00 Clear Reg D and E to store tens and hundreds respectively8002 1E, 00 MVI E, 00
8004 3A, 00, 90 LDA 9000 Get the hexadecimal number to the Acc and compare it with the decimal 100(ie64H)
8007 L2 FE, 64 CPI 64
8009 DA, 0B, 80 JC 8012 (L1) If the Acc content is less go for comparing 10s
800C D6, 64 SUI 64 If the Acc content is high subtract 64h from it
800E 1C INR E Increment the 100s counter800F
C3, 06, 80JMP 8007 (L2) Repeat the sequence till the Acc content
is less than 64H8012 L1 FE, 0A CPI 0A Compare the Acc contents with decimal
10(ie 0AH).If it is less go for comparing ones.
8014 DA, 1C, 80 JC 801D (L3)
8017 D6, 0A SUI 0A Subtract 10 from the Acc and continue doing so till its content less than 10.8019 14 INR D
801A C3, 0B, 80 JMP 8012 (L1)801D L3 4F MOV C, A Move the ones to the C register801E 7A MOV A, D Move the 10s to Acc801F 0F RRC Rotate it four times to make it as 10’s digit8020 0F RRC8021 0F RRC8022 0F RRC8023
81ADD C Add the ones with it to get the BCD
number8024
32, 00, 95STA 9500 Store the two digit BCD number in
memory location 95008027 7B MOV A, E Bring the 3rd digit from the E register to
Acc and store it in the next location8028 32, 01, 95 STA 9501802B CF RST 1 Program ends.
SAMPLE INPUT & OUTPUT:
RESULT:The program to convert the hexadecimal number (HEX) into Binary coded decimal (BCD) has been written and executed using microprocessor 8085.
19
Before ExecutionMemory Address
Data
9000 1D (Hex)
After ExecutionMemory Address
Data
9500 29 (BCD) Tens and ones9501 00 Hundreds
8. LARGEST AND SMALLEST DATA OF A GIVEN ARRAY
AIM:To write assembly language programs to search the largest and smallest data of a given
array using 8085.
a) LARGEST
ALGORITHM:
Step 1 : Start.Step 2 : Load the address of the first element of the array in HL register pair (pointer).Step 3 : Move the count to B register.Step 4 : Increment the pointer.Step 5 : Get the first data in the accumulator.Step 6 : Decrement the count.Step 7 : Increment the pointer.Step 8 : Compare the content of memory addresses by HL pair with that of accumulator.Step 9 : If CF=0, go to step 11 else go to step 10.Step 10: Move the content memory addressed HL to accumulator.Step 11: Decrement the count.Step 12: Check for zero for the count. If ZF=0, go to step 7 else go to next step.Step 13: Store the largest data in the memory.Step 14: End program.
PROGRAM:
Memory Address
Label Hex CodeMnemonics
CommentsOpcode Operand
8000 21, 00, 90 LXI H,9000 Use HL register pair as memory pointer and load the count in the B register form 90008003 46 MOV B,M
8004 23 INX H Increment the memory pointer to point the first number in the array.
8005 7E MOV A,M Move that number to the Acc and decrement the counter8006 05 DCR B
8007 L2 23 INX H Increment the memory pointer and compare the next data of the array with the Acc content
8008 BE CMP M
8009 D2, 0D, 80 JNC 800D (L1) If the Acc content is small then interchange it with the memory content800C 7E MOV A,M
800D L1 05 DCR B Decrement the counter and test it for zero .if not continue the loop.At the end the largest number will be in the Acc.
800E C2, 08, 80 JNZ 8007 (L2)
8011 32, 00, 95 STA 9500 Store the result in the memory location 9500
8014 76 HLT Program ends.
20
SAMPLE INPUT & OUTPUT:
b) SMALLEST ALGORITHM:
Step 1 : Start.Step 2 : Load the address of the first element of the array in HL register pair (pointer).Step 3 : Move the count to B register.Step 4 : Increment the pointer.Step 5 : Get the first data in the accumulator.Step 6 : Decrement the count.Step 7 : Increment the pointer.Step 8 : Compare the content of memory addresses by HL pair with that of accumulator.Step 9 : If CF=1, go to step 11 else go to step 10.Step 10: Move the content memory addressed HL to accumulator.Step 11: Decrement the count.Step 12: Check for zero for the count. If ZF=0, go to step 7 else go to next step.Step 13: Store the smallest data in the memory.Step 14: End program.
PROGRAM:
Memory Address
Label
Hex CodeMnemonics
CommentsOpcode
Operand
8000 21, 00, 90 LXI H, 9000 Use HL register pair as memory pointer and load the count in the B register form 90008003 46 MOV B,M
8004 23 INX H Increment the memory pointer to point the first number in the array.
8005 7E MOV A,M Move that number to the Acc and decrement the counter8006 05 DCR B
8007 L2 23 INX H Increment the memory pointer and compare the next data of the array with the Acc content
8008 BE CMP M
8009 DA, 0D, 80 JC 800D (L1) If the Acc content is big then interchange it with the memory content800C 7E MOV A,M
800D L1 05 DCR B Decrement the counter and test it for zero .if not continue the loop.At the end the smallest number will be in the Acc.
800E C2 , 08, 80 JNZ 8007 (L2)
8011 32, 00, 95 STA 9500 Store the result in the memory location 9500
8014 76 HLT Program ends.
21
Before ExecutionMemory Address
Data
9000 05 Count9001 EF Data 19002 DA Data 29003 FD Data 39004 12 Data 49005 05 Data 5
After ExecutionMemory Address
Data
9500 FD Largest
SAMPLE INPUT & OUTPUT:
RESULT:The programs to find the Largest and smallest number has been written and executed using microprocessor 8085.
NOTE: Largest and smallest programs are the same except the commands JC and JNC.
22
Before ExecutionMemory Address
Data
9000 05 Count9001 EF Data 19002 DA Data 29003 FD Data 39004 12 Data 49005 05 Data 5
After ExecutionMemory Address
Data
9500 05 Smallest
9. BLOCK MOVEMENT OF DATA
AIM:To write an assembly language program to move a block of data from one set of memory location to other using 8085 microprocessor.
ALGORITHM:
Step 1: StartStep 2: Load the starting address of the destination block in DE pair (9100)Step 3: Load the address of the Length of the block in HL pair (9000).
From the next address (9001) the source block startsStep 4: Move the length of the block to Reg BStep 5: Increment the HL pair to Starting address of the source blockStep 6: Move the first source data to Accumulator ( Reg A)Step 7: Move the Data to Destination block by Pointing with DE pair.Step 8: Increment the destination address ( DE Pair)Step 9: Decrement the Block count in Reg BStep 10: Check whether the block count is 0, if NOT zero Go to step 4, else next stepStep 11: Terminate the program.
PROGRAM:
Memory Address
Label Hex CodeMnemonics
CommentsOpcode Operand
8000 11,00,91 LXI D, 9100 DE register pair is stored with the address 9100
8003 21,00,90 LXI H, 9000 HL register pair is stored with the address 9000
8006 46 MOV B, M Move the count to B register8007 L1 23 INX H Increment the memory pointer 8008 7E MOV A, M Move the contents addressed by
the HL register pair to the Acc.8009 12 STAX D Move the data to the memory location
addressed by the DE register pair800A 13 INX D Increment the De register pair
decrement the counter and repeat the process till the counter becomes zero
800B 05 DCR B800C C2,07,80 JNZ 8007 (L1)800F CF RST 1 Program ends
SAMPLE INPUT & OUTPUT:
23
Before ExecutionMemory Address
Data
9000 05 Number of Data (Count)9001 0A Data 19002 05 Data 29003 32 Data 39004 5B Data 49005 CA Data 5
After ExecutionMemory Address
Data
9100 0A Data 19101 05 Data 29102 32 Data 39103 5B Data 49104 CA Data 5
RESULT:The program to move a block of data from one set of memory location to another set of memory location has been written and executed using microprocessor 8085.
24