CS2 Journal
CS2 Journal
Instructions:
1. Write Program in Right side of the journal.
2. Write Output in Left side of the journal with pencil.
3. Write program and output in tabular form.
Index
Programs
Sr.No.
1. Transfer/copy of a block
10. Count the occurrence of the number AB H from the given block
17 Division
C005 H C0
C006 H MVI D, 05 H ;Set the counter for 05 numbers in
register D
C007 H 05
C008 H UP: MOV A,M ;Copy the data content of memory
location whose address is in HL pair to
Accumulator
C009 H STAX B ;Store the data content of accumulator
to memory location whose address is in
register pair BC
C00A H INX H ; To get next location ,increment
content of HL register pair by 1
C00B H INX B ;To get next location ,increment the
content of BC register pair by 1
C00C H DCR D ;Decrement the counter by 1
C00D H JNZ UP ;If counter 0 (reg. D 0)then jump
to memory location C008H
C00E H 08
C00F H C0
Before Execution:
C040 H = 01 H
C041 H = 02 H
C042 H = 03 H
C043 H = 04 H
C044 H = 05 H
After Execution:
A=
D=
F=
C040 H = 01 H C050 H =
C041H = 02 H C051 H =
C042 H = 03 H C052 H =
C043 H = 04 H C053 H =
C044 H = 05 H C054 H =
F= S Z X AC X P X CY
Program-2
A Block of data is stored in memory location starting from C040 H. Length of the block is stored in register
D. Write an Assembly language program to transfer the entire block of data to another memory location
starting from memory location C050 H in reverse order.
C005 H C0
C006 H MVI D, 05 H ;Set the counter for 05 numbers in
register D
C007 H 05
C008 H UP: MOV A,M ;Copy the data content of memory
location whose address is in HL pair to
Accumulator.
C009 H STAX B ;Store the data content of accumulator
to memory location whose address is in
register pair BC .
C00A H INX H ; To get next location ,increment
content of HL register pair by 1
C00B H DCX B ;Decrement the content of BC register
pair by 1
C00C H DCR D ;Decrement the counter by 1
C00D H JNZ UP ;If counter 0 (reg.D 0)then jump
to memory location C008H
C00E H 08
C00F H C0
C010 H RST 1 ;Stop the execution
OUTPUT:
Before Execution:
C040 H = 01 H
C041 H = 02 H
C042 H = 03 H
C043 H = 04 H
C044 H = 05 H
After Execution:
A=
D=
F=
C040 H = 01 H C050 H =
C041 H = 02 H C051 H =
C042 H = 03 H C052 H =
C043 H = 04 H C053 H =
C044 H = 05 H C054 H =
F= S Z X AC X P X CY
Program-3
A block of data is stored in memory location starting from memory location C040 H. Another block of data
is stored in memory location starting from memory location C050 H. Length of the blocks is stored in
register D. Write a program to exchange / swap the data contents of both these blocks
C002 H C0
C005 H C0
C012 H C0
Before Execution:
After Execution
:A =
D =
F=
C040H = C050H=
C041H = C051H=
C042H = C052H=
C043H = C053H=
C044H = C054H =
F= AC CY
Program-4
A block of data is stored in memory location starting from C040 H. Length of the block is stored in register
B. Write an Assembly language program to add the data content of the memory location and store 16-bit
result at the end of the block.
C00A H 0D
C00B H C0
C00C H INR C ;Increment reg. C for carry
C00D H Down: INX H ; Increment the content of HL register
pair by 1 to get next location.
C00E H DCR B ;Decrement the counter by 1
C00F H JNZ UP ;If counter 0 (reg. B 0 )then jump
C010 H 08 to memory location C008H.
C011 H C0
C012 H MOV M ,A ; Copy the data content of accumulator
to Memory Location pointed by HL
register pair.
C013 H INX H ;Increment the memory location HL
register pair by 1
C014 H MOV M,C ; Copy the data content(carry) of reg. C
to Memory pointed by HL register pair.
C015 H RST 1 ;Stop the execution
OUTPUT:
Before Execution:
C040 H = 01H
C041 H = 02H
C042 H = 03 H
C043 H = 04 H
C044 H = 05 H
C045 H = ?
C046 H = ?
After Execution:
A=
B=
C=
F=
C040 H = 01 H
C041 H = 02 H
C042 H = 03 H
C043 H = 04 H
C044 H = 05 H
C045 H =
C046 H =
F= S Z X AC X P X CY
Program-5
A block of data is stored in memory location starting from C041 H. Length of the block is stored in
memory location C040 H. Write an Assembly language program to add the data content of the memory
location and store the BCD result at the end of the block.
C00B H 0E
C00C H C0
C00D H INR C ;Increment reg. C for carry
C00E H Down: INX H ;Increment the memory location of HL
register pair by 1
C00F H DCR B ;Decrement the counter by 1
C010 H JNZ UP ;If counter 0 (reg. B 0 )then jump to
C011 H 08 memory location C008 H.
C012 H C0
C013 H MOV M ,A ;Copy the data content of accumulator
to Memory location pointed by HL
register pair.
C014 H INX H ;Increment the memory location HL
register pair by 1
C015 H MOV M,C ;Copy the data content of reg. C
to Memory location pointed by HL
register pair.
C016 H RST 1 ;Stop the execution
OUTPUT:
Before Execution:
C040 H = 05H
C041 H = 01 H
C042 H = 02H
C043 H = 03 H
C044 H = 04H
C045 H = 05H
C046 H = ?
C047 H = ?
After Execution:
A=
B=
C=
F=
C040 H = 05H
C041 H = 01 H
C042 H = 02H
C043 H = 03 H
C044 H = 04H
C045 H = 05H
C046 H =
C047 H =
F= S Z X AC X P X CY
Program-6
Two numbers are stored in consecutive memory location starting from C040 H. Write an Assembly
language program to subtract the numbers and store the absolute difference result in the next memory
location.
Case I:
Before Execution:
C040 H = 09 H
C041 H = 04 H
C042 H = ?
After Execution:
A=
F=
C040 H = 09 H
C041 H = 04 H
C042 H =
F= S Z X AC X P X CY
Case II:
Before Execution:
C040 H = 04 H
C041 H= 09 H
C042 H = ?
After Execution:
A=
F=
C040 H = 04 H
C041 H= 09 H
C042 H =
F= S Z X AC X P X CY
Program-7
A block of data is stored in memory location starting from C040 H. Length of the block is stored in register B.
Write an Assembly language program to find the largest number from the given block of data and store it at
the end of the block.
Before Execution:
C040 H = 01 H
C041 H = 02 H
C042 H = 0A H
C043 H = 04 H
C044 H = 05 H
C045 H = ?
After Execution:
B=
F=
C040 H = 01 H
C041 H = 02 H
C042 H = 0A H
C043 H = 04 H
C044 H = 05 H
C045 H =
F= S Z X AC X P X CY
Program-8
A block of data is stored in memory location starting from C040 H. Length of the block is stored in register
B. Write an Assembly language program to find the smallest number from the given block of data and
store it at the end of the block.
Before Execution:
C040 H = 06 H
C041 H = 07 H
C042 H = 0A H
C043 H = 08 H
C044 H = 01 H
C045 H = ?
After Execution:
A=
B=
F=
C040 H = 06 H
C041 H = 07 H
C042 H = 0A H
C043 H = 08 H
C044 H = 01 H
C045 H =
F= S Z X AC X P X CY
Program-9
A block of data is stored in memory location starting from C040 H. Length of the block is stored in
register B. Write an Assembly language program to find the first occurrence of the number AB H from
the given block of data and if the number is not found store FFFF H in HL – pair.
C002 H C0
C003 H MVI A, AB H ;Load the data AB H to accumulator
C004 H AB
C005 H MVI B, 05 H ;Set the counter for 05 numbers in
register B
C006 H 05
C007 H UP: CMP M ;Compare content of memory pointed
by HL register pair with the data
content of accumulator
C008 H JZ DOWN ;If Zero flag is set then jump to
memory location C013H.
C009 H 13
C00A H C0
C00F H C0
Case I:
Before Execution:
C040H = 01 H
C041H = 02 H
C042H = AB H
C043H = 04 H
C044H= AB H
After Execution:
A=
B=
H=
L =
F =
F= S Z X AC X P X CY
Case II:
Before Execution:
C040H= 01 H
C041H = 02 H
C042H = 03 H
C043H = 04 H
C044H = 05 H
After Execution:
A=
B=
H=
L =
F =
F= S Z X AC X P X CY
Program-10
A block of data is stored in memory location starting from C040 H. Length of the block is stored in register
B. Write an Assembly language program to find the number of times (COUNT) the data AB H occurred
from the given block of data and store the result at the end of the block.
C012 H C0
Before Execution:
C040 H = AB H
C041 H = 02 H
C042 H = AB H
C043 H = 04 H
C044 H = AB H
C045 H = ?
After Execution:
A=
B=
C=
F=
C040 H = AB H
C041 H = 02 H
C042 H = AB H
C043 H = 04 H
C044 H = AB H
C045 H =
F= S Z X AC X P X CY
Program-11
A block of data is stored in memory location starting from C040 H. Length of the block is stored in
register B. Write a program to find the total count of odd numbers from the given block of data and
stored it at the end of block.
C002 H C0
C003 H MVI B, 05 H ;Set the counter for 05 numbers in
register B
C004 H 05
C005 H MVI C , 00 H ;Clear the data content of register C
C006 H 00
C007 H UP: MOV A , M ;Copy the memory content pointed by HL
register pair to accumulator
C008 H RRC ;Rotate the data content of accumulator
1-bit position to the right L.S.B. will shift
in carry as well as in M.S.B.
C00B H C0
C00C H INR C ;Increment the data content of
Register C by 1
C00D H DOWN: INX H ;Increment the memory location of HL
register pair by 1
C00E H DCR B ;Decrement the counter by 1
C00F H JNZ UP ; If counter 0 (reg. B 0) then jump to
memory location C007H.
C010 H
07
C011 H
C0
C012 H MOV M , C ;Store the count of odd numbers in the
next memory location pointed by HL
register pair.
C013 RST 1 ;Stop the execution
OUTPUT:
Before Execution:
C040H = 01 H
C041H = 02 H
C042H = 03 H
C043H = 04 H
C044H = 05 H
After Execution:
A=
B=
C=
F=
C040H = 01 H
C041H = 02 H
C042H = 03 H
C043H = 04 H
C044H = 05 H
C045H=
F= AC CY
Program-12
A block of data is stored in memory location starting from C040 H. Length of the block is stored in
register B. Write a program to find the total count of even numbers from the given block of data and
stored it at the end of block.
Before Execution:
C040H = 01 H
C041H = 02 H
C042H = 03 H
C043H= 04 H
C044H = 05 H
After Execution:
A=
B=
C=
F=
C040H = 01 H
C041H = 02 H
C042H = 03 H
C043H = 04 H
C044H = 05 H
C045H=
F= AC CY
Program-13
An 8-bit number is stored in memory location C040H. Write a program to find the total number of
ones present in the given number and store result in C050H.
C004 H 08
C005 H MVI C , 00 H ;Clear the data content of register C
C006 H 00
C007 H MOV A , M ; Copy the memory content pointed by HL
register pair to accumulator.
C008 H UP: RRC ;Rotate the data content of accumulator 1-bit
position to the right L.S.B. will shift in carry as
well as in M.S.B.
C009 H JNC DOWN ;If carry flag is reset then jump to memory
location C00DH
C00A H 0D
C00B H C0
C00C H INR C ;Increment the data content of
register C by 1
C00D H DOWN: DCR B ;Decrement the counter by 1
C00E H JNZ UP ;If counter 0 (reg. B 0 )then jump to
memory location C008H.
C00F H
08
C010 H
C0
C011 H MOV A, C ; Move the data content of C register to
accumulator.
C012 H STA C050H ;Store the count of 1s in memory location
C050H
C013 H 50
C014 H C0
Before Execution:
C040H = 23 H
After Execution:
A=
B=
C=
F=
C040H = 23 H
C050H =
F= AC CY
Program-14
An 8-bit number is stored in memory location C040H. Write a program to find the total number of
zeros present in the given number and store result in C050H.
C004 H 08
C005 H MVI C , 00 H ;Clear the data content of register C
C006 H 00
C007 H MOV A , M ; Copy the memory content pointed by HL
register pair to accumulator
C008 H UP: RRC ;Rotate the data content of accumulator 1-bit
position to the right L.S.B. will shift in carry as
well as in M.S.B.
C009 H JC DOWN ;If carry flag is set then jump to memory
location C00DH
C00A H 0D
C00B H C0
C00C H INR C ;Increment the data content of
register C by 1
C00D H DOWN: DCR B ;Decrement the counter by 1
C00E H JNZ UP ;If counter 0 (reg. B 0 )then jump to
memory location C008H
C00F H
08
C010 H
C0
C011 H MOV A, C ; Move the data content of C register to
accumulator.
C012 H STA C050H ;Store the count of 0s in memory location
C050H
C013 H 50
C014 H C0
Before Execution:
C040H = 23 H
After Execution:
A=
B=
C=
F=
C040H = 23 H
C050H =
F= AC CY
Program-15
Two numbers are stored in consecutive memory location starting from C040 H. Write an Assembly
language program to multiply the numbers and store the result in the next memory location.
C010 H C0
C011 H INX H ; Increment the memory location pointed
by HL register to get next location.
C012 H MOV M ,A ;Copy the data content of accumulator to
memory location pointed by register pair
HL
C013 H INX H ; Increment the memory location pointed
by HL register to get next location.
C014 H MOV M, C ;copy carry content(reg. C) in memory
location pointed by register pair HL
C015 H RST 1 ;Stop the execution
OUTPUT:
Before Execution:
C040 H = 05H
C041 H = 02H
C042 H = ?
C043 H = ?
After Execution:
A=
B=
F=
C040 H = 05 H
C041 H = 02 H
C042 H =
C043 H =
F= S Z X AC X P X CY
Program-16
A one byte number is stored in memory location starting from C030 H. Write a program to separate the
two nibbles of the one byte number and store them in the next memory location. Also write a program to
multiply the separated nibbles and store the result at the end of the block
C018 H C0
OUTPUT:
Before Execution:
C030H = 32 H
After Execution:
A=
B=
C=
F=
C030 H = 32H
C031 H =
C032 H =
C033 H =
F= AC CY
Program-17
Two numbers are stored in memory location starting from C040H. Write a program to divide the two
numbers and store the quotient and remainder in the next consecutive memory locations.
C002 H C0
Before Execution:
C040 = 09 H
C041 = 02 H
After Execution:
A=
C=
F=
C042 =
C043 =
F= AC CY
Program-18
Write a program in assembly language to interchange digits of a number stored in C040H. Store
new number in C041H. Add new number with original number and store result in C042H.
C002 C0
C009 41
C00A C0
C00D 42
C00E C0
Before Execution:
C040 = 09 H
After Execution:
A=
B=
F=
C041 =
C042 =
F= AC CY
Program-19
Write a program in assembly language to fill the memory locations C400H to C40FH with hex
number 00H to 0FH.
C002 C0
C004 10
C006 00
C00D C0
After Execution:
A=
B=
F=
C040 H =
C041 H =
C042 H =
C043 H =
C044 H =
C045 H =
C046 H =
C047 H =
C048 H=
C049 H=
C04A H=
C04B H=
C04C H=
C04D H=
C04E H=
C04F H=
F= S Z X AC X P X CY