0% found this document useful (0 votes)
3 views

CS2 Solutions

The document outlines several assembly language programs for manipulating data stored in specific memory locations, including transferring data in reverse order, subtracting numbers, counting odd and even numbers, multiplying two hex numbers, finding the smallest and largest numbers, adding a block of memory, sorting data, and converting BCD to binary. Each program is accompanied by an algorithm detailing the steps to be followed, along with memory and register operations. The document serves as a guide for implementing these operations using assembly language instructions.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

CS2 Solutions

The document outlines several assembly language programs for manipulating data stored in specific memory locations, including transferring data in reverse order, subtracting numbers, counting odd and even numbers, multiplying two hex numbers, finding the smallest and largest numbers, adding a block of memory, sorting data, and converting BCD to binary. Each program is accompanied by an algorithm detailing the steps to be followed, along with memory and register operations. The document serves as a guide for implementing these operations using assembly language instructions.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

Q.

A block of data is stored in memory locations from C030H to


C039H. Write a program to transfer the data in reverse order to
memory locations starting from C090H.​

Algorithm

1 Start

2 Initialise HL pair by C039H

3 Initialize DE pair by C090H

4 Initialize Register C by OAH

5. Copy data from memory location pointed by HL register pair to accumulator

6. Store the accumulator data into the memory location pointed by DE register pair.

Decrease HL register pair by 1.

Increase DE register pair by 1.

9. If C=\0 then go to step 5 Step

10 Stop

memory Label Hex mnemonics


Location code
COOOH 21 LXIH, CO39H
COO1H 39
C002H CO
COO3H 11 LXID,CO90H
COO4H 90
COO5H CO
COO6H OE MVIC,OAH
COO7H CA
COO8H Back 7E mov A,M

COO9H 12 STAX D

COOAH 2B DCXH
COOBH 13 INX D
COOCH OD DCR C
COODH C2 JNZ Back
COOEH 08
COOFH CO
CO1OH CF RST1
Memory Table
Input

Output
Register value

Flag Register

Algorithm

1 Start

2 Initialise HL pair by C039H

3 Initialize DE pair by C090H

4 Initialize Register C by OAH

5. Copy data from memory location pointed by HL register pair to accumulator

6.copy the content of memory location pointed by DE pair to accumulator.

7.copy the content of accumulator to memory locations pointed by HL pair.

8.copy the content of accumulator from register B

9.store the contents of accumulator into memory location pointed by DE pair.


10.Increment HL pair by 1.

11.Increment DE pair by 1.
Q.Write a program that subtracts the number stored in C031H
from the number stored in C030H. Store the absolute difference
in memory location C090H as result.​

Algorithm:

1 Start:

2 Initialize HL pair by CO3OH

3 Copy the contents from the memory location pointed by HL pair into accumulator.

4 Increase HL pair by 1.

5.Subtract the data of memory location pointed by HL pair from the contents of

Accumulator.

6.If the difference is positive then go to step 9

7. Complement the content of accumulator.

8.Ade O1H to the contents of accumulator.

9. Store the contents of accumulator as result in memory location C090H

10 Stop.
​ ​ ​ ​ ​
Q.A block of data is stored in memory location from C030H to
C039H. Write a program to find the number of odd as well as
even number in the given block. Store the results immediately
after the end of block.

Algorithm
1.Start

2. Initialize HL pair CO30H

3.Copy OAH in register C

4. Copy OOH in registеr B

5. Copy OOH in register D

6.Copy the data from the memory location pointed

7.Rotate the contents of accumulator towards right by 1 bit.

8.If CY=1 then go to step 11

9.Increase register B by 1.

10. Jump Conditionally to Step 13.

11.Increase register D by 1.

12 Increase HL pair by 1.

13.Decrease register C by 1.

14.If Register C#0 then go to step 6.

15.copy the data from register C into the memory location pointed by HL pair.

16.Increase HL pair by 1

17.copy the data from register C into the memory location pointed by HL pair.

18.stop
Hex Table
Q.Write a program that multiplies two 1 byte hex numbers
stored in consecutive memory locations starting from C030H.
Store the two byte result in consecutive memory location
starting from C090H beginning with lower order byte.
​ ​ ​ ​

Algorithm:-

1.Start.

2 Initialize HL pair with C030H.

3 Copy data from memory locations pointed by HL pair into register B.

4.Increment HL pair by 1.

5.Copy data from memory location pointed by HL pair into register c.


6.Perform EX-OR operation between the contents of the accumulator and content of the

accumulator..

7.Copy data OOH into registerD.

8 Add the contents of register B with accumulator..

9 If CY= 0 then go to step 11.

10. Increment register D by 1.

11.Decrement register C by 1.

12 If z=o then go to step 8.

13 Initialize HL pair by C090H

14 Copy data from the accumulator to memory locations pointed by HL pair.

15 Increment HL pair by 1.

16 copy data from register D to memory location pointed by HL pair.

17 Stop.
​ ​ ​ ​ ​ ​
​ ​ ​

Q.A block of data is stored in memory location from C030H to


C039H. Write a program to find the smallest as well as greatest
number from this block using linear search. Store the results
immediately after the end of the block. ​
​ ​ ​ ​ ​ ​
Algorithm:

1.Start

2 Initialize HL pair by C030H

3 Copy data from memory location pointed by HL pair to register B.

4. Copy data from memory location pointed by HL pair to register D.

5 Increment HL pair by 1.

6 Copy 09H into register C.

7 Copy data from memory location pointed by HL Pair to accumulator.

8 compare the value of accumulator with Register B.

9 If CY # 0 then go to step 13

10 If Z=1 then go to step 13

11 Copy data from accumulator to register B.

12 Unconditional jump go to step 17

13 compare the contents of accumulator with the contents of registеr D.

14 If CY=1 then go to step 17

15. If Z=1 then go to step 17

16 Copy data from accumulator to register D

17Increment HL pair by 1.

18 Decrement register c by 1.

19 If Content of register C to then go to step 7.

20 Copy the content of register B to memory location pointed by HL pair

21 Increment HL pais by 1.

22 Copy the content of register D to the memory location pointed by HL past.

23 Stop
Memory Label Hex mnemonics comments.

Location code

to register B .

CO11H C3 IMPNEXT unconditional Jump to Next

CO12H IC

CO13H CO

CO14H skip BA CMPD compare the contents of

accumulator with the

contents of register D.

C015H DA JC NEXT If CY=1 then Jump to Next

COI6H 1C

COI7H CO

COI8H CA JZ NEXT If Z=1 then Jump to Next

COI9H 1C
COIAH CO

CO1BH Next 57 mov DA copy data from accumulator

to register D .

CO1CH 23 INX H Increment HL pair by 1.

CO1DH OD DCRC Decrement register C by 1.

CO1EH C2 INZ BACK If the content of register

CO1FH 08 C#O then jump to back

CO2OH 00

CO21H TO mov M, B copy data from memory location

to register B pointed by HL pair

CO22H 23 INX H Increment HL pair by 1.

CO23 H 72 mov m, D copy data from register D to memory

location pointed by HL pair.

C024H CF RST 1 Stop


Memory Table
Input

memory Before After

Location execution execution

CO3OH 05 05

COBIH 02 02

CO32H oa 09

CO33H 06 06

CO34H 03 03

CO35H 01 01

CO36H 01 01

CO37A 08 08

CO38H 04 04

CO39H OA OA
Output

memory Before After

Location execution execution

COBAH - 01

CO3BH - OA

Register value

Register contents Register contents

A OA H CO

B 01 L 3B

C 00 SPH 84

D OA SPL 21

E 9A PCH CO

F 40 PCL 25

Flag Register

S Z X AC X P X CY
0 1 - 0 - 0 - 0
Conclusion:
Thus we have executed the program to find out the smallest as well as largest
number out of the block.

Q.Write a program that adds the contents of a block of memory


using DAD instruction. Block length is stored at C030H and starting
address of block is C031H. Store the 2 bytes results below the end
of the block.​
​ ​ ​ ​
​ ​ ​

​ ​
Q.A block of data is stored in memory location C030H. The length of
the block is10 bytes. Write a program that sorts the given data in
ascending order.
​ ​ ​ ​

​ ​ ​
HEx Table​
Q.Write a program to convert a 2-digit BCD number stores at memory
location C030H in to its binary equivalent and store the binary value in
memory location C090H.

You might also like