CS 2 Journal Writeup
CS 2 Journal Writeup
(D-9)
PAPER – II
PRACTICALS
SR.
NAME OF EXPERIMENT
NO.
11. Find the number of odd and even nos. from the block.
Find the count of occurren
12.
ces of the number in a block.
13. Find the smallest and greatest nos. from the block.
Exp.1] Flowchart:-
START
Increment HL address by 1
Increment HL address by 1
STOP
1.Write an Assembly Language Program (ALP) that adds 1–byte hex
number stored in D030H with 1-byte hex number stored in
D031H. Store the 1-byte sum in memory location D032H as
result.
BEFORE EXECUTION :- AFTER EXECUTION :-
Memory Memory
Data Data
location location
D030 06 D030 06
D031 08 D031 08
D032 D032
(SUM)
00 (SUM)
0E
GENERAL REGISTERS :-
(* indicates register not used in program. Data after execution
for these register can be changed)
A B* C* D* E* F H L
0E 01 00 00 00 00 DO 32
FLAG REGISTER :-
D7 D6 D5 D4 D3 D2 D1 D0
S Z - AC - P - CY
0 0 - 0 - 0 - 0
PROGRAM :-
; Increment HL address by 1
C006 23 INX H
(point to D032H)
START
Increment HL address by 1
Yes Is result
>=0 ?
No
Complement the bits in Accumulator A
STOP
2.Write an Assembly Language Program (ALP) that subtracts the
number stored in D031H from the number stored in D030H. Store
the positive result / absolute difference in memory location
D032H as result.
BEFORE EXECUTION :- AFTER EXECUTION :-
Memory location Data Memory location Data
D030 06 D030 06
D031 0A D031 0A
D032 D032
(Absolute 00 (Absolute 04
Difference) Difference)
GENERAL REGISTERS :-
(* indicates register not used in program. Data after execution
for these register can be changed)
A B* C* D* E* F H L
04 00 00 00 00 00 DO 31
FLAG REGISTER :-
D7 D6 D5 D4 D3 D2 D1 D0
S Z - AC - P - CY
0 0 - 0 - 0 - 0
PROGRAM :-
; Complement Accumulator A
C009 2F CMA
(invert bits)
; Add 01H to A to complete
C00A C6 ADI 01H two's complement (make it
positive)
Initialize C = 00H
Increment HL by 1
No
Is carry
present?
Yes
Increment C by 1
Increment HL by 1
Increment HL by 1
STOP
3.Write an Assembly Language Program (ALP) to do addition between
two 8 bit BCD numbers. Two numbers are stored in D030H &
D031H. Store the result in D032H onwards starting with least
significant bit.
BEFORE EXECUTION :- AFTER EXECUTION :-
Memory Data Memory Data
location location
D030 37 D030 37
D031 93 D031 93
D032 00 D032 30
(BCD SUM) (Lower byte) (BCD SUM) (Lower byte)
D033 00 D033 01
(CARRY) (Higher byte) (CARRY) (Higher byte)
GENERAL REGISTERS :-
A B* C D* E* F H L
30 01 01 00 00 01 DO 33
FLAG REGISTER :-
D7 D6 D5 D4 D3 D2 D1 D0
S Z - AC - P - CY
0 0 - 0 - 0 - 1
PROGRAM :-
C001 00
; Point HL to first BCD
C002 21 LXI H, DO30 H
number at D030H
; Increment HL address by
C00D 23 SKIP INX H
1 (point to D032H)
; Store the lower byte of
C00E 77 MOV M, A the result (sum) at D032H
; Increment HL address by
C00F 23 INX H
1 (point to D033H)
; Store the carry (if any) at
C010 71 MOV M, C
D033H
Initialize B = 08
Initialize C = 00
Load A with M
Rotate Right
Yes
Is Carry
Set?
No
Increment C by 1
Decrement B by 1
No Is
B=0?
Yes
Increment HL by 1
STOP
4. An 8 bit hexadecimal number stored at memory location D001H.
Write an Assembly Language Program (ALP) to count numbers of
zeros in it and Store the count in memory location D002H as
result.
BEFORE EXECUTION :- AFTER EXECUTION :-
Memory Memory
Data Data
location location
D001 75 D001 75
D002 D002
(Count of 00 (Count of 03
Zeros) Zeros)
GENERAL REGISTERS :-
(* indicates register not used in program. Data after execution
for these register can be changed)
A B C D* E* F H L
75 00 03 00 00 54 DO 02
FLAG REGISTER :-
D7 D6 D5 D4 D3 D2 D1 D0
S Z - AC - P - CY
0 1 - 1 - 1 - 0
PROGRAM :-
C001 08
; Clear C to use it as a
C002 0E MVI C, 00H
counter for zeros
C003 00
; Increment count in C
C00C 0C INR C
(found a zero)
; Decrement B (reduce bit
C00D 05 SKIP DCR B count)
; If B is not zero, repeat the
C00E C2 JNZ UP
loop
;Increment HL address by 1
C011 23 INX H
(point to D002H)
; Store the zero count from
C012 71 MOV M, C
C into D002H
Initialize A = 00H
Initialize C = 00H
Increment HL by 1
Is Carry No
Set?
Yes
Increment C by 1
Decrement B by 1
No
Is B = 0 ?
Yes
Increment HL by 1
Increment HL by 1
STOP
5. Write an Assembly Language Program (ALP) that multiplies TWO
1–byte Hex numbers stored in consecutive memory locations
starting from C030H. Store the two-byte result in the
consecutive memory locations starting from C032H beginning
with Lower order byte.
BEFORE EXECUTION :- AFTER EXECUTION :-
Memory Memory
Data Data
location location
C030 03 C030 03
C031 8A C031 8A
C032 00 C032 9E
(SUM) (Lower byte) (SUM) (Lower byte)
C033 00 C033 01
(CARRY) (Higher byte) (CARRY) (Higher byte)
GENERAL REGISTERS :-
(* indicates register not used in program. Data after execution
for these register can be changed)
A B C D* E* F H L
9E 00 01 00 00 54 C0 33
FLAG REGISTER :-
D7 D6 D5 D4 D3 D2 D1 D0
S Z - AC - P - CY
0 1 - 1 - 1 - 0
PROGRAM :-
Initialize C = 00H
Increment HL by 1
Is Carry Yes
Set?
No
Increment quotient C by 1
Increment HL by 1
Increment HL by 1
STOP
6. Write an Assembly Language Program (ALP) that divides TWO 1-
byte Hex numbers where the dividend is stored in D001H and
the divisor is stored in D002H. Store the quotient and the
remainder in the next consecutive memory locations
respectively.
BEFORE EXECUTION :- AFTER EXECUTION :-
Memory Memory
Data Data
location location
D001 0D D001 0D
D002 03 D002 03
D003 D003
(Quotient)
00 (Quotient)
04
D004 D004
(Remainder)
00 (Remainder)
01
GENERAL REGISTERS :-
(* indicates register not used in program. Data after
execution for these register can be changed)
A B* C D* E* F H L
01 01 04 00 00 81 DO 04
FLAG REGISTER :-
D7 D6 D5 D4 D3 D2 D1 D0
S Z - AC - P - CY
1 0 - 0 - 0 - 1
PROGRAM :-
C001 00
; Load HL with the address
C002 21 LXI H, D001 H
of the dividend (D001H)
C003 01 ; Lower address byte
B
Copy bock length as location counter from memory to reg. B
Increment HL address by 1
No
Is carry
present?
Yes
Is location
No
counter
zero?
Yes
Increment HL address by 1
STOP
7. Write an Assembly Language Program (ALP) that adds the BCD
contents of a block of memory. Block length in Hex not
exceeding 63H = (9910) is stored at D000H and starting address
of block is D001H. Store the BCD sum as result starting from
memory location D060H.
BEFORE EXECUTION :- AFTER EXECUTION :-
Memory location Data Memory location Data
D000 D000
05 05
(Block length) (Block length)
D001 02 D001 02
D002 03 D002 03
D003 05 D003 05
D004 06 D004 06
D005 07 D005 07
D060 D060
(BCD SUM of block)
00 (BCD SUM of block)
23
D061 D061
(CARRY)
00 (CARRY)
00
GENERAL REGISTERS :-
(* indicates register not used in program. Data after
execution for these register can be changed)
A B C D* E* F H L
23 00 00 00 00 54 D0 61
FLAG REGISTER :-
D7 D6 D5 D4 D3 D2 D1 D0
S Z - AC - P - CY
0 1 - 1 - 1 - 0
PROGRAM :-
C003 00
;Load the HL pair as
C004 21 LXI H, D000H
memory pointer at D000
C005 00 ;Lower address byte
START
Increment HL address by 1
Decrement DE address by 1
Is location
No counter
zero?
Yes
STOP
8. A block of data is stored in memory locations from D050H to
D054H. Write an Assembly Language Program (ALP) to transfer
the data in reverse order to memory locations starting from
D080H.
BEFORE EXECUTION :- AFTER EXECUTION :-
Memory Memory
Data Data
location location
D050 AA D080 EE
D051 BB D081 DD
D052 CC D082 CC
D053 DD D083 BB
D054 EE D084 AA
GENERAL REGISTERS :-
(* indicates register not used in program. Data after
execution for these register can be changed)
A B C* D E F H L
EE 00 00 D0 7F 54 DO 55
FLAG REGISTER :-
D7 D6 D5 D4 D3 D2 D1 D0
S Z - AC - P - CY
0 1 - 1 - 1 - 0
PROGRAM :-
C001 05
;Load the HL pair as
C002 21 LXI H, D050 H
memory pointer at D050
;Decrement location
C00C 05 DCR B
counter
;Is location counter zero?
C00D C2 JNZ UP No – jump to UP
Increment HL address by 1
Increment DE address by 1
No Is
location
counter
zero?
Yes
STOP
9. A block of data is stored in memory locations from D041H to
D045H. Another block of data having the same length is stored in
memory locations from D071H. Write an Assembly Language
Program (ALP) to exchange the contents of these two blocks.
BEFORE EXECUTION :-
Memory Data Memory Data
location location
D041 11 D071 AA
D042 22 D072 BB
D043 33 D073 CC
D044 44 D074 DD
D045 55 D075 EE
AFTER EXECUTION :-
GENERAL REGISTERS :-
(* indicates register not used in program. Data after execution
for these register can be changed)
A B C D E F H L
55 00 55 D0 76 54 D0 46
FLAG REGISTER :-
D7 D6 D5 D4 D3 D2 D1 D0
S Z - AC - P - CY
0 1 - 1 - 1 - 0
PROGRAM :-
C001 05
;Load the HL pair as memory
C002 21 LXI H, D041H
pointer at D041
;Load Accumulatorfrom
C008 1A UP LDAX D
memory of DE
;Copy data from HL memory
C009 4E MOV C, M
to reg. C
;Copy Accumulator data to HL
C00A 77 MOV M, A memory
;Copy reg. C data to
C00B 79 MOV A, C
Accumulator
;Store Accumulator data to
C00C 12 STAX D
memory of DE
B
AND the data of Accumulator with 0F. This will separate the
lower nibble from 2 digit number.
B
Rotate the Content of Accumulator to Right 4 times
AND the data of Accumulator with 0F. This will separate the
higher nibble from 2 digit number.
C
Increment HL address by 1
B
Increment HL address by 1
A
10.Write an Assembly Language Program (ALP) that separates the
two nibbles of a number stored in C060H and stores the same
in memory locations C061H and C062H. The program must also
multiply the two nibbles and stores the product in C063H.
A
Decrement counter by 1
Is
No counter
zero?
Yes
Increment HL address by 1
STOP
PROGRAM :-
C005 0F
;Copy lower nibble from
C006 47 MOV B, A
Accumulator to B reg.
;Again move memory
C007 7E MOV A, M content to Accumulator
;Rotate the Content of
C008 0F RRC Accumulator to Right 4
times
C009 0F RRC
C00A 0F RRC
C00B 0F RRC
;AND the data of
Accumulator with 0F. This
C00C E6 ANI 0F H
will separate the higher
nibble from 2 digit number.
C00D 0F
;Copy higher nibble from
C00E 4F MOV C, A
Accumulator to reg. C
C014 00
BEFORE EXECUTION :- AFTER EXECUTION :-
Memory Memory
Data Data
location location
C060 23 C060 23
C061 C061
(Lower Nibble)
00 (Lower Nibble)
03
C062 C062
(Higher Nibble)
00 (Higher Nibble)
02
C063 C063
(Product of 2 06 (Product of 2 06
Nibbles) Nibbles)
GENERAL REGISTERS :-
(* indicates register not used in program. Data after
execution for these register can be changed)
A B C D* E* F H L
06 00 02 00 00 54 C0 63
FLAG REGISTER :-
D7 D6 D5 D4 D3 D2 D1 D0
S Z - AC - P - CY
0 1 - 1 - 1 - 0
Address Opcode Label Mnemonic/ Comment
Operand
;Add Accumulator content
C015 81 UP ADD C
with reg. C
B
Set block length as location counter from HL memory to reg. B
Increment HL address by 1
B
Rotate right
No
Is carry
present?
Yes
Increment odd counter C
No Is location
counter
zero?
Yes
Load Accumulator with the data of memory D060
A
11.A block of data is stored in memory locations from memory
location D061H and onwards. The length of block is stored in
location D060H. Write an Assembly Language Program (ALP) to
find the number of odd as well as even numbers in the given
block. Store odd count in location D100H and even count at
D101H.
A
Increment HL address by 1
STOP
GENERAL REGISTERS :-
(* indicates register not used in program. Data after
execution for these register can be changed)
A B C D* E* F H L
02 00 03 00 00 10 D1 01
FLAG REGISTER :-
D7 D6 D5 D4 D3 D2 D1 D0
S Z - AC - P - CY
0 0 - 1 - 0 - 0
PROGRAM :-
B
Set block length as location counter from HL memory to reg. B
Increment HL address by 1
B
Compare Accumulator with immediate data AD
Is result No
zero?
Yes
Increment counter C
No Is location
counter
zero?
Yes
Load the HL pair as memory pointer at E000
STOP
12.A block of data is stored in memory locations from D051H. The
length of the block is stored at D050H. Write an Assembly
Language Program (ALP) that counts the occurrence of the
number ADH in the given block. Store the count in E000H.
BEFORE EXECUTION :- AFTER EXECUTION :-
Memory location Data Memory location Data
D050 D050
05 05
(Block length) (Block length)
D051 03 D051 03
D052 AD D052 AD
D053 AD D053 AD
D054 05 D054 05
D055 AD D055 AD
E000 E000
(Count of AD)
00 (Count of AD)
03
GENERAL REGISTERS :-
(* indicates register not used in program. Data after
execution for these register can be changed)
A B C D* E* F H L
AD 00 03 00 00 54 E0 00
FLAG REGISTER :-
D7 D6 D5 D4 D3 D2 D1 D0
S Z - AC - P - CY
0 1 - 1 - 1 - 0
PROGRAM :-
C001 00
;Load the HL pair as
C002 21 LXI H, D050 H
memory pointer at D050
C003 50 ;Lower address byte
B
Move memory content to reg. D assuming greatest no.
Increment HL address by 1
Is carry Yes
present?
No
Copy greatest number from reg. A to reg. D
Is carry No
present?
Yes
Copy smallest number from reg. A to reg. E
No
Is location
counter zero ?
Yes
A
13.A block of data is stored in memory locations from D040H to
D049H. Write an Assembly Language Program (ALP) 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.
A
Increment HL address by 1
Increment HL address by 1
STOP
PROGRAM :-
GENERAL REGISTERS :-
(* indicates register not used in program. Data after
execution for these register can be changed)
A B C* D E F H L
12 00 00 77 01 54 D0 4B
FLAG REGISTER :-
D7 D6 D5 D4 D3 D2 D1 D0
S Z - AC - P - CY
0 1 - 1 - 1 - 0
Address Opcode Label Mnemonic/ Comment
Operand