Computer Science Practical XII 2
Computer Science Practical XII 2
Computer Science Practical XII 2
Procedure: Feed the program in appropriate memory locations. Execute the program and store
the result.
Before execution:
[A] = 05H
[B] = 02H
[7000H] = unknown (random data or garbage value)
After execution:
[A] = 05H
[B] = 02H
[7000H] =03H
Result:
[A] 0000 0101
[B] 0000 0010
[7000H] 0000 0011
Contents of flag register:
Z S P CY AC
0 0 1 0 0
Zero flag contains 0 because result is non-zero. Sign flag contains 0 because result is positive.
Parity flag contains 1 because the number of 1’s in the result is even. Carry flag contains 0
because carry is not generated. Auxiliary carry flag contains 0 because carry is not carried from
4th bit to 5th bit in the final result.
Working: In the above program, the given opcodes are disassembled using opcode sheet. The
number 02H is stored in the register B and is subtracted from the contents of accumulator
containing 05H. Finally the result is stored in the memory location 7000H i.e. [7000H] = [A] –
[B] = 05H – 02H = 03H
Start
Stop
Program 2
a. Write a program that multiplies two 1-byte hex numbers stored in consecutive memory
locations starting from C005H. Store the two-byte result in consecutive memory locations
starting from C000H beginning with lower order byte.
b. Enter the program in the microprocessor kit.
c. Execute the program. Write the contents of data memory locations before and after
execution as well as the contents of the registers in the program after execution and also
the bit contents of all five flags individually. Verify the result.
Procedure: Feed the program in appropriate memory locations. Execute the program and store
the result.
Before execution:
[C005H] = 02H
[C006H] = 03H
[A] = 03H
After execution:
[C005H] = 02H
[C006H] = 03H
[C000H] = 06H
[C001H] = 00H
[A] = 00H
Result:
03H 0000 0011
02H 0000 0010
06H 0000 0110
Z S P CY AC
1 0 1 0 0
Zero flag contains 1 because accumulator contains 00H. Sign flag contains 0 because result is
positive. Parity flag contains 1 because the number of 1’s in the result is even. Carry flag
contains 0 because carry is not generated. Auxiliary carry flag contains 0 because carry is not
carried from 4th bit to 5th bit in the final result.
Working: In the above program, initially the multiplicand is available in C005H and multiplier
is available in C006H. Then both are copied to register E and A (accumulator) respectively. The
multiplicand is added with itself for multiplier times. After every addition the contents of
accumulator are decremented by 1. The addition is repeated until the contents of accumulator
become zero. Finally the result is stored in memory locations C000 and C001H.
Start
N1 = [C005H]
N2 = [C006H]
Product = 00H
Product = Product + N1
N2 = N2 - 1
No Is
N2 = 0
?
Yes
Stop
Program 3
a. Write a program that subtracts the number stored in 2502H from the number stored in
2501H. Store the absolute difference in the memory location 2503H as result.
20M
b. Enter the program on the microprocessor kit. 5M
c. Execute the program for a positive as well as negative difference. Write the contents of
data memory locations before and after execution as well as the contents of the registers
used in the program after execution and also the bit contents of all the five flags
individually. Verify the results. 5M
Procedure: Feed the program in appropriate memory locations. Execute the program and store
the result.
Result:
Case1:
Before execution:
[2501H] = 49H
[2502H] = 32H
After execution:
[2501H] = 49H
[2502H] = 32H
[2503H] = 17H
Case2:
Before execution:
[2501H] = F8H
[2502H] = 9BH
After execution:
[2501H] = F8H
[2502H] = 9BH
[2503H] = 5DH
Case3:
Before execution:
[2501H] = 03H
[2502H] = 02H
After execution:
[2501H] = 03H
[2502H] = 02H
[2503H] = 01H
Case4:
Before execution:
[2501H] = 02H
[2502H] = 03H
After execution:
[2501H] = 02H
[2502H] = 03H
[2503H] = FFH
Z S P CY AC
0 0 0 0 0
Contents of flag register for Case4:
Z S P CY AC
0 1 1 1 0
Working: In the above program, first number is stored in the memory location 2501H, second
number is stored in the memory location 2502H and the difference between two numbers is
stored in the memory location 2503H.
Start
Stop
Program 4
a. A block of data is stored in memory locations from 1050H to 1059H. Write a program that
searches for the first occurrence of the data byte FFH in the given block. Store the address of
this occurrence in the HL pair. If the number is not found, then HL pair must contain 0000H.
b. Enter the program on the microprocessor kit
c. Execute the program. Write the contents of the registers in the program after execution and
also the bit contents of all five flags individually. Verify the result.
Procedure: Feed the program in appropriate memory locations. Execute the program and store
the result.
Memory Label Mnemonic Opcode Comments
address
6000 LXI D, 1050H 11 DE points to the memory location
6001 50 1050H
6002 10
6003 LXI H, 0000H 21 HL points to the memory location
6004 00 0000H
6005 00
6006 MVI C, 0AH 0E Immediate data 0AH is moved to the
6007 0A register C
6008 Loop: LDAX D 1A Load accumulator with the contents
of memory location pointed by DE
pair
6009 CPI FFH FE Compare the contents of
600A FF accumulator with the immediate data
FFH
600B JNZ next C2 Jump to the memory location 6012H
600C 12 if the result is non-zero
600D 60
600E XCHG EB Exchange the contents of memory
pointed by DE pair and HL pair
600F JMP stop C3 Jump to the memory location 6017H
6010 17
6011 60
6012 Next: INX D 13 Make the DE pointer to point to the
next memory location
6013 DCR C 0D Decrement the contents of register C
by 1
6014 JNZ loop C2 Jump to the memory location 6000H
6015 00 if the contents of register C are not
6016 60 zero
6017 Stop: HLT Stop
Before execution:
[1050H] = 11H
[1051H] = 23H
[1052H] = 45H
[1053H] = 56H
[1054H] = 00H
[1055H] = FFH
[1056H] = 78H
[1057H] = 89H
[1058H] = 9AH
[1059H] = ABH
After execution:
[HL] = 1055H
Z S P CY AC
1 1 1 1 1
Working: In the above program various data elements are stored in a block starting from 1050H
to 1059H. Initially the contents of HL are 0000H and DE points to the first element of the block.
Successively the DE points to the next element and every element is compared with FFH. If it is,
its address is stored in HL. Here we got FFH into 1055H. So after execution the contents of HL
are 1055H.
Start
[C] = Counter
DE Pointer
[HL] = 0000H
Is Pointer
Yes pointing
to FFH
?
No
Increase pointer
Decrease counter
[HL] = pointer
Is
count=0 No
?
Yes
Stop
Program5
a. Write a program that adds a 4 byte integer stored in consecutive memory locations starting
from 2501H beginning with lower order byte to another 4 byte integer stored in consecutive
memory locations starting from 2601H beginning with lower order byte. Store the result in
consecutive memory locations starting from 2501H. 20M
The number of bytes in each number is stored in the memory location 2500H
b. Enter the program on the microprocessor kit. 5M
c. Execute the program. Write the contents of data memory locations before and after execution
as well as the contents of the registers used in the program after execution and also the bit
contents of all the five flags individually. Verify the results. 5M
Before execution:
[2500H] = 04H
[2501H] = 11H
[2502H] = 11H
[2503H] = 11H
[2504H] = 11H
[2601H] = 22H
[2602H] = 22H
[2603H] = 22H
[2604H] = 22H
After execution:
[2500H] = 04H
[2501H] = 33H
[2502H] = 33H
[2503H] = 33H
[2504H] = 33H
[2601H] = 22H
[2602H] = 22H
[2603H] = 22H
[2604H] = 22H
Z S P CY AC
0 0 1 0 0
Parity flag is 1 because due to 33333333H (the number of 1s in the result is even)
Working: In the above program, two 4-byte numbers are stored in consecutive memory locations
starting from 2501H and 2601H respectively. The number of bytes in each number is stored in
the memory location 2500H. The successive bytes from each byte are added together and finally
the 4-byte result is stored in the memory starting from 2501H.
Start
A
A
[C] = counter No
HL pointer 2501H
DE pointer 2601H
Clear Carry
Increase HL pointer
Increase DE pointer
Decrease counter
Is
No Counter=0
?
Yes
Stop
Program6:
a. Write a program that multiplies two 1-byte hex numbers stored in consecutive memory
locations by rotation. Store the two byte result in consecutive memory locations starting from
6504H beginning with lower order byte.
b. Enter the program on the microprocessor kit.
c. Execute the same. Write the contents of data memory locations before and after execution as
well as the contents of the registers used in the program after execution and also the bit
contents of all five flags individually. Verify the results.
Apparatus: Microprocessor 8085 simulator or kit
Procedure: Feed the program in appropriate memory locations. Execute the program and store
the result.
After execution:
[2501H] = 02H
[6503H] = 04H
[HL] = 0008H
[6504H] = 08H
[6505H] = 00H
Z S P CY AC
1 0 1 0 0
As accumulator contains 00H, parity flag contains 1 to maintain odd parity and zero flag
contains 1.
In the above program, multiplicand is stored in 2501H and multiplier is stored in 6503H.
The multiplication is done bit by bit. After every bit multiplication, the multiplier is
shifted left by one bit. Finally the product is available in HL pair and copied into the
memory location 6504H and 6505H.
Start
Initial product
0000H in HL pair
Counter C = 08H
A
A
No
Shift partial product
left by 1 bit
Rotate multiplier
left by 1 bit
Is
No multiplier
bit = 1
?
Yes
Product = product +
multiplicand
Decrease counter
Is
counter = 0 No
?
Yes
Store the product in HL
and [6504H, 6505H]
Stop
Program 7:
a. Write a program that adds the BCD contents of a block of memory. Block length in hex
not exceeding 63H = (99)10. The block is starting from the memory location 3000H. Store
the BCD sum as result starting from memory location 3005H.
b. Enter the program in the microprocessor kit.
c. Execute the program. Write the contents of data memory locations before and after
execution as well as the contents of the registers in the program after execution and also
the bit contents of all five flags individually. Verify the result.
Procedure: Feed the program in appropriate memory locations. Execute the program and store
the result.
Before execution:
[3000H] = 05H,
[3001H] = 02H,
[3002H] = 04H,
[3003H] = 04H,
[3004H] = 03H
After execution:
[3000H] = 05H,
[3001H] = 02H,
[3002H] = 04H,
[3003H] = 04H,
[3004H] = 03H
[3005H] = 18
[A] = 18
[HL] = 3005H
Z S P CY AC
0 0 1 0 0
The accumulator contains the result BCD 18 that is 12 in hexadecimal and 1100 in binary. To
maintain odd parity, parity flag contains 1
Working: In the above program the five BCD numbers are stored from memory location 3000H
to 3004H. The numbers are added one by one in the accumulator. After the addition the contents
of the accumulator are adjusted decimally. Finally the decimally adjusted result is stored in the
location 3005H.
Start
No Is
counter=0
?
Yes
Stop
Program 8
a. Write a program that separates the two nibbles of a number stored in 3000H and stores
the same in memory locations 3001H and 3002H. The program must also multiply the
two nibbles and stores the product in 3003H.
b. Enter the program on the microprocessor kit.
c. Execute the same. Write the contents of data memory locations before and after execution
as well as the contents of the registers used in the program after execution and also the bit
contents of all five flags individually. Verify the results.
Procedure: Feed the program in appropriate memory locations. Execute the program and store
the result.
Before execution:
[3000H] = 12H
After execution:
[3001H] = 01H
[3002H] = 02H
[3003H] = 02H
[A] = 02H
[B] = 02H
[HL] = 3000H
Working: In the above program, the number 12H is stored in the memory location 3000H.
Counter is set in the register C as 04H to rotate the number 4 times. The original number is
copied in the registers A and B. The accumulator is ANDed with F0H to get the first nibble.
The ANDed result is rotated left 4 times to get the first nibble from higher byte to lower byte
in register A. The result that is first nibble is stored in register C as well as in the memory
location 3001H. The original number which is now available in register B is now copied into
accumulator. The contents of accumulator are ANDed with 0FH to get the second nibble in
register A. The ANDed result is copied into the memory location 3002H and register B.
Accumulator is cleared. The register B is added together with register A for (contents of
register C times). The result that is multiplication is stored in the memory location 3003H
Start
Set pointer
Counter = 4
Decrease counter
No Is
Counter=0
A?
Yes
A
A
Clear accumulator
Is
No Counter=0
?
Yes
Store the result in memory location
Stop
Program 9:
a. A block of data is stored in memory locations from 3000H to 3004H. Write a program to
find the greatest number from the block using linear search. Store the result immediately
after the block.
b. Enter the program in the microprocessor kit.
c. Execute the program. Write the contents of data memory locations before and after
execution as well as the contents of the registers in the program after execution and also
the bit contents of all five flags individually. Verify the result.
Procedure: Feed the program in appropriate memory locations. Execute the program and store
the result.
Memory Label Mnemonic Opcode Comments
Address
6000 MVI C, 05H 0E Counter C
6001 05
6002 LXI H, 3000H 21 HL pointer pointing to the
6003 00 starting of the block
6004 30
6005 MOV A, M 7E
6006 Loop1 INX H 23
6007 MOV B, M 46
6008 CMP B B8
66
6009 JNC Loop D2
600A 0D
600B 60
600C MOV A, B 78
600D Loop DCR C 0D
600E JNZ Loop1 C2
600F 06
6010 60
6011 STA 3005 32
6012 05
6013 30
6014 HLT 76
Before execution:
[3000H] = 05H
[3001H] = 02H
[3002H] = 04H
[3003H] = 08H
[3004H] = 03H
After execution:
[3005H] = 08H
[A] = 08H
[HL] = 3005H
Working: In the above program the five numbers are stored from memory location 3000H to
3004H. The first number is copied into the accumulator. After all the comparisons, the greatest
number is available in the accumulator and is copied into the specified memory location also.
Start
Counter = 5
Set pointer
Increase pointer
Is
No
Carry=0
?
Yes
Copy the contents of register B in register A
Decrease counter
Is
No Counter=0
?
Yes
A
A
Stop
Program 10
a. A block of data is stored in memory locations from _____ to _____. Write a program to
find the smallest number from the block using linear search. Store the result immediately
after the block.
b. Enter the program in the microprocessor kit.
c. Execute the program. Write the contents of data memory locations before and after
execution as well as the contents of the registers in the program after execution and also
the bit contents of all five flags individually. Verify the result.
Procedure: Feed the program in appropriate memory locations. Execute the program and store
the result.
Before execution:
[3000H] = 05H
[3001H] = 02H
[3002H] = 04H
[3003H] = 08H
[3004H] = 03H
After execution:
[3005H] = 02H
[A] = 02H
[HL] = 3005H
Working: In the above program the five numbers are stored from memory location 3000H to
3004H. The first number is copied into the accumulator. After all the comparisons, the smallest
number is available in the accumulator and is copied into the specified memory location also.
Start
Counter = 5
Set pointer
Increase pointer
Is
Yes
Carry=0
?
No
Copy the contents of register B in register A
Decrease counter
Is
No Counter=0
?
Yes
A
A
Stop