CO Lab Manual
CO Lab Manual
CLASS : BSC
YEAR : I BSC
SEMESTER : II
SUBCODE : 125C21
INTRODUCTION TO COMPUTER ARCHITECTURE AND
MICROPROCESSOR LAB MANUAL
CLASS : BSC
YEAR : I BSC
SEMESTER : II
SUBCODE : 125C21
Prepared by Approved by
I : Addition and Subtraction
1. 8 - bit addition
2. 16 - bit addition
3. 8 - bit subtraction
4. BCD subtraction
Aim:
Algorithm:
Program Coding:
LDA 2050
MOV B,A
LDA 2051
ADD B
STA 2052
HLT
Input:
2050 04
2051 02
Output
2052 06
RESULT:
Thus the above program has been successfully executed and completed.
2. 16 Bit Addition
Aim:
Algorithm:
1. Load both the lower bit and higher bit of first number at once.
2. Copy the content HL pair to DE pair register.
3. Now the load the lower and higher bit of second number in HL pair register.
4. ADD both the register pair content using DAD operation.
5. Result will store in HL register
6. Stop
Program coding:
LXI D,1122H
LXI H,1122H
DAD D
HLT
Input:
DE 1122
HL 1122
Output:
HL 2244
RESULT:
Thus the above program has been successfully executed and completed.
3. 8 Bit Subtraction
Aim:
Algorithm:
Program Coding:
LDA 2050
MOV B,A
LDA 2051
SUB B
STA 2052
HLT
Input:
2050 02
2051 04
Output
2052 02
RESULT:
Thus the above program has been successfully executed and completed.
4 . BCD Subtraction
Aim:
Algorithm –
Program coding:
LDA 2051H
MOV C,A
MVI A,99H
SUB C
INR A
MOV B,A
LDA 2050H
ADD B
DAA
STA 2080H
HLT
OBSERVATION:
INPUT:
2050: 70
2051: 30
OUTPUT:
2080: 40
RESULT:
Thus the above program has been successfully executed and completed.
Algorithm:
1. Load the data from the address 2050 to the HL pair register.
2. Move the contents from the register M to B register.
3. Increment the HL pair register
4. Move the contents from the register M to C register.
5. Clear the A register
6. Add the memory contents with the register B
7. Decrement the register C
8. Jump to loop when Z flag is not 1
9. Increment the HL pair register
10. Store Acc contents into the memory
11. Terminate the program.
Program coding:
LXI H,2050H
MOV B,M
INX H
MOV C,M
MVI A,00H
TOP:ADD B
DCR C
JNZ TOP
INX H
MOV M,A
HLT
Observation:
Input:
2050: 03
2051: 04
Output:
2052: 0C
RESULT:
Thus the above program has been successfully executed and completed.
BCD MULTIPLICATION
Aim:
To perform BCD multiplication of two 8 bits numbers using 8085 simulator.
Algorithm:
1. Load the BCD multiplier
2. Initialize counter
3. Set Result register to 0000
4. Load the multiplicand
5. Extend the registers to 16-bits
6. Result = Result + Multiplicand
7. Get the lower byte of the result
8. Adjust the lower byte of result to BCD.
9. Store the lower byte of result
10. Increment counter, adjust it to BCD and store it
11. Compare if count = multiplier
12. Jump to loop when Z flag is not 1
13. Terminate the program
Program coding:
MVI C,03H
MVI B,00h
LXI H,0000H
MVI E,03h
MVI D,00H
BACK:DAD D
MOV A,L
ADI 00H
DAA
MOV L,A
MOV A,H
ACI 00H
DAA
MOV H,A
MOV A,B
ADI 01H
DAA
MOV B,A
CMP C
JNZ BACK
HLT
Input:
BC: 03 03
DE: 00 03
Output:
HL: 00 09
RESULT:
Thus the above program has been successfully executed and completed.
8 BIT DIVISION
Aim:
Algorithm:
1. Load the data from the address 2051 into the Acc
2. Move the contents from register A to register B
3. Load the second data into accumulator.
4. Clear the register C
5. Compare the two numbers to check carry.
6. Subtract two numbers.
7. Increment the value of carry.
8. Check whether the repeated subtraction is over.
9. Then store the results (quotient and remainder) in given memory location.
10. Terminate the program.
Program coding:
LDA 2051H
MOV B,A
LDA 2052H
MVI C,00H
LOOP2:CMP B
JC LOOP1
SUB B
INR C
JMP LOOP2
LOOP1:STA 2053H
MOV A,C
STA 2054H
HLT
Observation:
Input:
2051: 03
2052: 07
Output:
2053: 01
2054: 02
RESULT:
Thus the above program has been successfully executed and completed.
III: Sorting and Searching
Program coding:
2000 LXI H 2050
2003 MOV C, M
2004 LDA 3050
2007 MOV B, A
2008 INX H
2009 MOV A, M
200A CMP B
200B JNZ 2014
200E MVI A F0
2010 STA 3051
2013 HLT
2014 MVI A 0F
2016 STA 3051
2019 DCR C
201A JNZ 2008
201D HLT
Input:
2050 04
2051 49
2052 F2
2053 14
2054 39
Output:
3050 F2
3051 F0
3050 17
3051 0F
RESULT:
Thus the above program has been successfully executed and completed.
Algorithm:
Program coding:
MVI B,09H
START:LXI H,2200H
MVI C,09H
BACK: MOV A, M
INX H
CMP M
JC SKIP
JZ SKIP
MOV D, M
MOV M, A
DCX H
MOV M, D
INX H
SKIP:DCR C
JNZ BACK
DCR B
JNZ START
HLT
INPUT:
2200 : FF
2201: 08
2202: DD
2203: E7
2204: 95
OUTPUT:
2205: 08
2206: 95
2207: DD
2208: E6
2209: FF
RESULT:
Thus the above program has been successfully executed and completed.
Aim:
To find the largest & smallest elements from an array using 8085 simulator.
Algorithm:
1. Load the address of the first element of the array in HL pair.
2. Move the count to B - reg.
3. Increment the pointer.
4. Get the first data in A - reg.
5. Decrement the count.
6. Increment the pointer.
7. Compare the content of memory addressed by HL pair with that of A - reg.
8. If carry = 1, go to step 10 or if Carry = 0 go to step 9.
9. Move the content of memory addressed by HL to A - reg.
10. Decrement the count.
11. Check for Zero of the count. If ZF = 0, go to step 6, or if ZF = 1 go to next step.
12. Store the smallest data in memory.
13. Terminate the program.
Program coding:
a. SMALLEST ELEMENTS FROM AN ARRAY
LXI H,2000H
MOV C,M
INX H
MOV B,M
DCR C
LOOP:INX H
MOV A,M
CMP B
JNC SKIP
MOV B,A
SKIP:DCR C
JNZ LOOP
LXI H,2072H
MOV M,B
HLT
Observation
Input:
2000 : 05
2001: 2B
2002: 91
2003: 06
2004: 35
2005: 02
OUTPUT:
2072: 02
b. LARGEST ELEMENT IN AN ARRAY
Aim:
To find the largest element in an array using 8085 simulator.
Algorithm:
1. Load HL pair with address of first operand’s memory address location.
2. Move the first operand from memory to Acc
3. Increment HL pair to point to next memory location.
4. Move the second operand from memory to the register
5. Compare it with the two registers
6. If jump not carry, move the data from register to the Acc.
7. Increment HL pair register
8. Move the result from Acc to memory
9. Terminate the program.
PROGRAM:
LXI H,2000H
MOV B,M
INX H
MOV A,M
DCR B
NEXT:INX H
CMP M
JNC LOOP
MOV A,M
LOOP:DCR B
JNZ NEXT
STA 2072H
HLT
Input:
2000 : 03
2001: 91
2002: 25
2003: 4B
2004: 61
OUTPUT:
2072: 91
RESULT:
Thus the above program has been successfully executed and completed.
Algorithm:
1. Take the block size into C
3. Load M into A
7. Decrease C by 1
Program coding:
MVI C,5
LXI H,2004H
LXI D,2070H
NEXT:MOV A,M
STAX D
DCX H
INX D
DCR C
JNZ NEXT
HLT
Observation
Input:
2000 : 10
2001: 20
2002: 30
2003: 40
2004: 50
Output:
2070 : 50
2071: 40
2072: 30
2073: 20
2074: 10
RESULT:
Thus the above program has been successfully executed and completed.
Block move
Aim:
To move the block of contents from one memory location to another memory
location.
Algorithm:
1. Load register pair H-L with the address 2000H
2. Load register pair D-E with the address 2070H
3. Move the content at memory location into accumulator
4. Store the content of accumulator into memory pointed by D-E
5. Increment value of register pair H-L and D-E by 1
6. Decrements value of register C by 1
7. If zero flag not equal to 1, go to step 3
8. Terminate the program
Program coding:
MVI C,5
LXI H,2000H
LXI D,2070H
NEXT:MOV A,M
STAX D
INX H
INX D
DCR C
JNZ NEXT
HLT
Input:
2000 : 10
2001: 20
2002: 30
2003: 40
2004: 50
Output:
2070 : 10
2071: 20
2072: 30
2073: 40
2074: 50
RESULT:
Thus the above program has been successfully executed and completed.
Aim:
To perform the sorting in descending order using 8085 simulator.
Algorithm:
1) Initialize HL pair as memory pointer.
2) Get the count at 2200 in to C register.
3) Copy it in the register.
4) Get the first vale in Accumulator.
5) Compare it with the value at next location.
6) Jump if not carry go the label skip.
7) If they are out of order, exchange the contents of accumulator and memory.
8) Decrement H register’s content by 1.
9) Repeat steps 5 and 7 till the value in the register become zero.
10) Decrement B register’s content by 1.
11) Repeat steps 3 to 9 till the value in the register becomes zero.
12) Terminate the program.
Program:
MVI B,09H
START:LXI H,2200H
MVI C,09H
BACK: MOV A, M
INX H
CMP M
JNC SKIP
JZ SKIP
MOV D, M
MOV M, A
DCX H
MOV M, D
INX H
SKIP:DCR C
JNZ BACK
DCR B
JNZ START
HLT
OBSERVATION:
INPUT:
2200 : FF
2201: 08
2202: DD
2203: E7
2204: 95
OUTPUT:
2200 : FF
2201: E7
2202: DD
2203: 95
2204: 08
RESULT:
Thus the above program has been successfully executed and completed.
IV: Code Conversion
l. BCD to Hex and Hex to BCD
Aim:
To convert Binary coded decimal into Hexadecimal using 8085 simulator.
Algorithm:
1. Load HL pair in 2000H & 2001H
2. Move contents into A
3. Add A(A*2)
4. Store in Register B
5. Add A(A*4)
6. Add A(A*8)
7. Add B(A*10)
8. Increment the memory location
9. Store the result in 2002H
10. Terminate the Program.
Program Coding:
LXI H,2000H
MOV A,M
ADD A
MOV B,A
ADD A
ADD A
ADD B
INX H
ADD M
INX H
MOV M,A
HLT
Input:
2000 02
2001 09
Output:
2002 00
RESULT:
Thus the above program has been successfully executed and completed.
Aim:
To convert binary to ASCII using 8085 simulator.
Algorithm:
1. Load the address 2200 to the accumulator.
2. Compare the content of accumulator with 0A
3. Start the loop
4. ADI 07 will add 07 to the content of the accumulator.
5. It will add 37 to the content of the accumulator.
6. Store the result in the address 2260.
7. Terminate the program.
Program coding:
INPUT:
2200 : 0B
OUTPUT:
2260: 42
2002 55
RESULT:
Thus the above program has been successfully executed and completed.
Aim:
To convert ASCII to binary using 8085 simulator.
Algorithm:
1. Load the address 2200 to the accumulator.
2. SUI 30 will subtract 30 to the content of the accumulator.
3. Compare the content of accumulator with 0A
4. Start the loop
5. SUI 07 will subtract 07 to the content of the accumulator.
6. It will subtract 37 to the content of the accumulator.
7. Store the result in the address 2270.
8. Terminate the program.
Program coding:
INPUT:
2200 : 44
OUTPUT:
2270: 0D
RESULT:
Thus the above program has been successfully executed and completed.
Program coding:
LDA 8010H
SUI 30H
STA 8080H
HLT
INPUT:
8010: 35
OUTPUT:
8080: 05
RESULT:
Thus the above program has been successfully executed and completed.
Program coding:
LDA 8010H
ADI 30H
STA 8080H
HLT
INPUT:
8010: 08
OUTPUT:
8080: 38
RESULT:
Thus the above program has been successfully executed and completed.
V: Applications
1. Square of a single byte Hex number
Aim:
To find the square of a single byte to hex number using 8085 simulator.
Algorithm:
1. Load the HL pair register to a memory location
2. Initialize the Acc
3. Move the contents of the memory location which is indirectly specified by M
in register C
4. Add the contents of the memory location
5. Decrement value of register C by 1.
6. Jump to the loop if ZF=0
7. Stores the values in 2051
8. Terminate the program
Program coding:
LXI H,2000H
MVI A,00H
MOV B,M
MOV C,M
LOOP:ADD B
DCR C
JNZ LOOP
STA 2051H
HLT
Input:
2000 : 05
Output:
2051 : 19
RESULT:
Thus the above program has been successfully executed and completed.
3. Increase HLpair
6. Compare C with A
8. Add B with A
9. Decimal Adjust
10. Store A to D
INX H
MOV C, M
MVI E, 00H
MOV H, E
MOV A, E
CMP C
JZ DONE
LOOP ADD B
DAA
MOV D, A
JNC NINC
MOV A, H
ADI 01H
DAA
MOV H, A
NINC MOV A, E
ADI 01H
DAA
MOV E, A
CMP C
MOV A,D
JNZ LOOP
DONE MOV L, A
SHLD 8050H
HLT
Input:
8000 12
8001 20
Output:
8050 40
8051 02
Result:
Thus the above program has been successfully executed and completed.
Aim:
To find the square root of a single byte to hex number using 8085
simulator.
Algorithm:
1. Load the value, stored at memory location 2200 in accumulator A
2. Assign 01 to register B and C
3. Subtract value stored at accumulator A from register B
4. Check if accumulator holds 0, if true then jump to step 8
5. Increment value of register D by 2
6. Increment value of register C by 1
7. Jump to step 3
8. Move value stored at register C in A
9. Store the value of A in memory location 2272
10. Terminate the program
Program coding:
LDA 2200H
MVI B,01H
MVI C,01H
AGAIN:SUB B
JZ OVER
INR C
INR B
INR B
JMP AGAIN
OVER:MOV A,C
STA 2272H
HLT
Input:
2200 09
Output:
2272 03
RESULT:
Thus the above program has been successfully executed and completed.
Aim:
To find the square root of a two digit binary coded decimal number using 8085
simulator.
Algorithm:
1. Assign 01 to register D and E
2. Load the value, stored at memory location 2050 in accumulator A
3. Subtract value stored at accumulator A from register D
4. Check if accumulator holds 0, if true then jump to step 8
5. Increment value of register D by 2
6. Increment value of register E by 1
7. Jump to step 3
8. Move value stored at register E in A
9. Store the value of A in memory location 3050
Program coding:
MVI D, 01
MVI E, 01
LDA 2050
SUB D
JZ 2011
INR D
INR D
INR E
JMP 2007
MOV A, E
STA 3050
HLT
INPUT:
2050 09
Output
3050 03
RESULT:
Thus the above program has been successfully executed and completed.
ADDITIONAL EXERCISES:
Aim:
Algorithm:
1. HL Points 2500H
2. Get first operand
3. HL Points 2501H
4. Add second operand
5. HL Points 2502H
6. Store the lower byte of result at 2502H
7. Initialize higher byte result with 00H
8. Add carry in the high byte result
9. HL Points 2503H
10. Store the higher byte of result at 2503H
11. Terminate program execution
Program
1. LXI H, 2500H
2. MOV A, M
INX H
ADD M
INX H
MOV M, A
MVIA, 00
ADC A
INX H
MOV M, A
HLT
OUTPUT:
(2500H) = 7FH
(2501H) = 89H
Result = 7FH + 89H = lO8H
(2502H) = 08H
(2503H) = 01H
Aim:
Algorithm:
PROGRAM:
LDA 2501H
1. CMA
2. STA 2502H
3. HLT
4.
OUTPUT:
(2501H) = 96 H = 1001 0110
(9) (6)
One's complement = 0110 1001 = 69 H
Result = (2502H) = 69H
AIM:
ALGORITHM:
PROGRAM:
1. LDA 2501 H
2. CMA
3. ADI, 01 H
4. STA 2502 H
5. HLT
OUTPUT:
To find the two's complement of 96.
96 = 1001 0110
1's complement = 0110 1001 = 69
+ 0000 0001
2's complement = 0110 1010 = 6A
AIM:
Algorithm:
Program
Count number of 1's of the content of the register D and store the count in the register B.
1. MVI B, 00H
2. MVI C, 08H
3. MOV A, D
4. BACK: RAR
5. JNC SKIP
6. INR B
7. SKIP: DCR C
8. JNZ BACK
9. HLT
OUTPUT:
2501 H = 04
2502 H = 34 H
2503 H = A9H
2504 H = 78H
2505 H = 56H
Result = 2503 H = A9H
Aim:
Algorithm:
1. Initialize counter
2. Initialize pointer
3. Sum low = 0
4. Sum high = 0
5. Get the number"
6. Mask Bit 1 to Bit-7
7. Don't add if number is even
8. Get the lower byte of sum
9. Sum = sum + data
10. Store result in E register
11. Add carry to MSB of SUM
12. Increment pointer
Program
1. LDA 2500H
2. MOV C, A
3. LXI H, 2501H
4. MVI E, 00
5. MOV D, E
6. BACK: MOV A, M
7. ANI 01H
8. JZ SKIP
9. MOV A, E
ADD M
MOV E, A
JNC SKIP
INR D
SKIP: INX H
OUTPUT:
2500 H = 4H
2501 H = 9AH
2502 H = 52H
2503 H = 89H
2504 H = 3FH
Result = 2505 H = 89H + 3FH= C8H