Computer Science Practical XII 2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 32

Program 1

Program is stored from memory location 6000H to 6008H.


a. Copy the contents of these memory locations on paper and disassemble the program using
op-code sheet. 10M
b. Draw the flowchart and write the working of the program 10M
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 the five flags individually. Verify the results.
10M
Memory Address OPcode
6000 3E
6001 05
6002 06
6003 02
6004 90
6005 32
6006 00
6007 70
6008 76

Apparatus: Microprocessor 8085 simulator or kit

Procedure: Feed the program in appropriate memory locations. Execute the program and store
the result.

Memory Label Mnemonic Opcode Comments


address
6000 MVI A, 05H 3E Copy immediate data 05H to the accumulator
6001 05
6002 MVI B, 02H 06 Copy immediate data 02H to the register B
6003 02
6004 SUB B 90 Subtract the contents of the register B from the
contents of the accumulator and store the result
in accumulator
6005 STA 7000H 32 Contents of the accumulator is stored in the
6006 00 memory location 7000H
6007 70
6008 HLT 76 Stop

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

Load the numbers in registers


[A] = 05H, [B] = 02H

Subtract the numbers


[A] = [A] – [B]

Store the result in memory location


[7000H] = [A]

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.

Apparatus: Microprocessor 8085 simulator or kit

Procedure: Feed the program in appropriate memory locations. Execute the program and store
the result.

Memory Label Mnemonic Opcode Comments


address
6000 LXI H, 0000H 21
6001 00
6002 00
6003 LDA C005H 3A
6004 05
6005 C0
6006 MOV E, A 5F
6007 LDA C006H 3A
6008 06
6009 C0
600A MVI D, 00H 16
600B 00
600C Loop: DAD D 19
600D DCR A 3D
600E JNZ Loop C2
600F 0C
6010 60
6011 SHLD C000H 22
6012 00
6013 C0
6014 HLT 76

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

Contents of flag register:

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

[C000H, C001H] = Product

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

Apparatus: Microprocessor 8085 simulator or kit

Procedure: Feed the program in appropriate memory locations. Execute the program and store
the result.

Memory Label Mnemonic Opcode Comments


address
6000 LXI H, 2501H 21 HL pointer points to the memory
6001 01 location 2501H
6002 25
6003 MOV A, M 7E Copy the contents of memory
location pointed by HL pointer to
accumulator
6004 INX H 23 Increment the HL pointer
6005 SUB M 96 Subtract the contents of memory
location pointed by HL pointer from
the contents of accumulator and
store the result in accumulator
6006 INX H 23 Increment the HL pointer
6007 MOV M, A 77 Copy the contents of accumulator to
the memory location pointed by HL
pointer
6008 HLT 76 Stop

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

Contents of flag register for Case3:

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

Explanation for case4:


Result is FFH. Sign flag is 1 because the result is negative but we get FF which is 2’s
complement of -1. Parity flag is 1 because due to FFH, there are even number of 1s in the result.
CY is 1 because borrow is generated.

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

Load the numbers in the


memory locations
[2501H]= N1, [2502H]= N2

Subtract the numbers


N1-N2 = Result

Store the result in the memory location

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.

Apparatus: Microprocessor 8085 simulator or kit

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

Contents of flag register:

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

Load the numbers in


memory locations from
1050H to 1059H

[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

Memory Label Mnemonic Opcode Comments


Address
6000 LXI H, 2500H 21 Address of byte count in HL pair
6001 00
6002 25
6003 MOV C, M 2525
4E Byte count in register C
6004 INX H 23 Address of 1st byte of 1st number
6005 LXI D, 2601H 11 Address of 1st byte of 2nd number
6006 01
6007 26
6008 ORA A B7 Clear carry
66
6009 LOOP LDA X D 1A Get byte of 2nd number in accumulator
600A ADC M 8E
600B MOV M, A 77
600C INX H 23
600D INX D 13
600E DCR C 0D
600F JNZ LOOP C2 Is count = 0? No, jump to LOOP
6010 09
6011 24
6012 HLT 76

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

Contents of flag register:

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

Load the number (4 byte) in


memory locations 2501H
and 2601H

Load the number of


bytes in each number in
2500H

A
A

[C] = counter No
HL pointer 2501H
DE pointer 2601H

Clear Carry

Add the two bytes


with carry

Copy the result in the


memory location
pointed by HL pointer

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.

Memory Label Mnemonic Opcode Comments


Address
6000 LHLD 2501H 2A Get multiplicand in H-L pair
6001 01
6002 65
6003 XCHG EB Multiplicand in DE pair
6004 LDA 6503H 3A Multiplier in accumulator
6005 03
6006 65
6007 LXI H, 0000H 21 Initial value of product = 00 in HL pair
6008 00
66
6009 00
600A MVI C, 08H 0E Count = 8 in register C
600B 08
600C Loop DAD H 29 Shift partial product left by 1 bit
600D RAL 17 Rotate multiplier left one bit. Is
Multiplier’s bit = 1?
600E JNC AHEAD D2 NO, go to ahead
600F 12
6010 60
6011 DAD D 19 Product = Product + Multiplicand
6012 AHEAD DCR C 0D Decrement count
6013 JNZ LOOP C2
6014 0C
6015 60
6016 SHLD 6504H 22 Store the result
6017 04
6018 65
6019 HLT 76
Before execution:
[2501H] = 02H
[6503H] = 04H
[HL] = 0000H

After execution:
[2501H] = 02H
[6503H] = 04H
[HL] = 0008H
[6504H] = 08H
[6505H] = 00H

Contents of flag register:

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

Load 8-bit multiplicand in


the memory location 2501H

Load 8-bit multiplier from


6503H to accumulator

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.

Apparatus: Microprocessor 8085 simulator or kit

Procedure: Feed the program in appropriate memory locations. Execute the program and store
the result.

Memory Label Mnemonic Opcode Comments


Address
6000 LXI H, 3000H 21 HL pointer pointing to
6001 00 3000H
6002 30
6003 MVI A, 00H 3E Initially sum = 0
6004 00
6005 MVI C, 05H 0E Setting counter
6006 05
6007 Loop ADD M 86
6008 DAA 27 Decimally adjust
66 accumulator
6009 INX H 23
600A DCR C 0D
600B JNZ Loop C2 Jump if not zero
600C 07
600D 60
600E STA 3005H 32 Store the result
600F 05
6010 30
6011 HLT 76 Stop

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

Contents of flag register:

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

Load the five numbers in memory locations

Clear accumulator, counter = 5

Add the number

Decimally adjust the accumulator

Increase pointer pointing to MLs. Decrease counter

No Is
counter=0
?

Yes

Store the result in memory location

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.

Apparatus: Microprocessor 8085 simulator or kit

Procedure: Feed the program in appropriate memory locations. Execute the program and store
the result.

Memory Label Mnemonic Opcode Comments


Address
6000 LXI H, 3000H 21 HL pointer points to 3000H
6001 00
6002 30
6003 MVI C, 04H 0E Set counter
6004 04
6005 MOV A, M 7E
6006 MOV B, A 47
6007 ANI F0H E6 Setting second nibble as 0
6008 F0
66
6009 Loop RLC 07 Rotate left 4 times
600A DCR C 0D
600B JNZ Loop C2
600C 09
600D 60
600E MOV C, A 4F First nibble in register C
600F STA 3001H 32 Store the first nibble in
6010 01 3001H
6011 30
6012 MOV A, B 78 Copy original number in
accumulator
6013 ANI 0FH E6 Setting first nibble as 0
6014 0F
6015 STA 3002H 32 Copy second nibble in
6016 02 3002H
6017 30
6018 MOV B, A 47 Second nibble in register B
6019 MVI A, 00H 3E Clear accumulator
601A 00
601B Loop1 ADD B 80 Add second nibble for first
601C DCR C 0D nibble of times for
601D JNZ Loop1 C2 multiplication
601E 1B
601F 60
6020 STA 3003H 32
6021 03
6022 30
6023 HLT 76 Stop

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

Load the number in memory location

Set pointer

Counter = 4

Copy the number in registers A and B

AND contents of register A with F0H

Rotate result left by a single bit

Decrease counter

No Is
Counter=0
A?

Yes

Copy the result in register C and memory location

Copy the original number from register B to register A

A
A

AND with 0FH

Store the result in register B and memory location

Clear accumulator

Add the contents of register B

Decrease the contents of register C

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.

Apparatus: Microprocessor 8085 simulator or kit

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

Copy the first number in the accumulator

Increase pointer

Move the second number in register B

Compare with the contents of register A

Is
No
Carry=0
?

Yes
Copy the contents of register B in register A

Decrease counter

Is
No Counter=0
?

Yes

A
A

Store the result in the memory location

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.

Apparatus: Microprocessor 8085 simulator or kit

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 JC Loop
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] = 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

Copy the first number in the accumulator

Increase pointer

Move the second number in register B

Compare with the contents of register A

Is
Yes
Carry=0
?

No
Copy the contents of register B in register A

Decrease counter

Is
No Counter=0
?

Yes

A
A

Store the result in the memory location

Stop

You might also like