0% found this document useful (0 votes)
9 views58 pages

CS 2 Journal Writeup

The document outlines a series of assembly language experiments for computer science practicals, focusing on operations with hexadecimal and BCD numbers. Each experiment includes a flowchart, a description of the task, and the assembly language program needed to perform the operation. Key operations include addition, subtraction, multiplication, and counting zeros in hexadecimal numbers, with specific memory addresses used for data storage and results.

Uploaded by

Typical shlok
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views58 pages

CS 2 Journal Writeup

The document outlines a series of assembly language experiments for computer science practicals, focusing on operations with hexadecimal and BCD numbers. Each experiment includes a flowchart, a description of the task, and the assembly language program needed to perform the operation. Key operations include addition, subtraction, multiplication, and counting zeros in hexadecimal numbers, with specific memory addresses used for data storage and results.

Uploaded by

Typical shlok
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 58

COMPUTER SCIENCE

(D-9)
PAPER – II
PRACTICALS
SR.
NAME OF EXPERIMENT
NO.

1. Addition of two 1- byte HEX numbers.

2. Subtraction of two 1- byte HEX numbers.

3. Addition of two 8 bit BCD numbers.

4. Count number of zeros in an 8 bit HEX number.

5. Multiplication of two 1- byte HEX numbers.

6. Division of two 1- byte HEX numbers.

7. Addition of the BCD contents of the block.

8. Transfer the block in reverse order.

9. Exchange the contents of two blocks.

10. Product of two nibbles of a number.

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

Initialize HL with address D030H

Load value at D030H into Accumulator A

Increment HL address by 1

Add value at D031H to A

Increment HL address by 1

Store result from A into D032H

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 :-

Address Opcode Label Mnemonic/ Comment


Operand

; Initialize HL with address


C000 21 START LXI H, D030H
D030H

C001 30 ; Lower address byte

C002 D0 ; Higher address byte

; Load the value at D030H into


C003 7E MOV A, M
Accumulator A
; Increment HL address by 1
C004 23 INX H (point to D031H)

C005 86 ADD M ; Add the value at D031H to A

; Increment HL address by 1
C006 23 INX H
(point to D032H)

; Store the result from A into


C007 77 MOV M, A
D032H

C008 CF STOP RST 1 ; End program execution


Exp. 2) Flowchart :-

START

Set HL to point to D030H

Load the value at D030H into Accumulator A

Increment HL address by 1

Subtract value at D031H from A

Yes Is result
>=0 ?

No
Complement the bits in Accumulator A

Add 01H to A to get the positive result

Store the result (absolute difference) in D032H

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 :-

Address Opcode Label Mnemonic/ Comment


Operand

C000 21 START LXI H, D030 H ; Set HL to point to D030H

C001 30 ; Lower address byte

C002 D0 ; Higher address byte

; Load the value at D030H into


C003 7E MOV A, M
Accumulator A
; Increment HL address by 1
C004 23 INX H (Point to D031H)
; Subtract value at D031H
C005 96 SUB M
from A

C006 F2 JP SKIP ; If result >= 0, jump to SKIP

C007 0C ; Lower address byte

C008 C0 ; Higher address byte

; Complement Accumulator A
C009 2F CMA
(invert bits)
; Add 01H to A to complete
C00A C6 ADI 01H two's complement (make it
positive)

C00B 01 ; Immediate data

; Store the result (absolute


C00C 32 SKIP STA D032H
difference) in D032H

C00D 32 ; Lower address byte

C00E D0 ; Higher address byte

C00F CF STOP RST 1 ; End program execution


Exp.3] Flowchart :-
START

Initialize C = 00H

Load HL with address D030H

Load data from


memory to reg. A

Increment HL by 1

Add data of memory to reg. A

Decimal Adjust Accumulator

No
Is carry
present?

Yes
Increment C by 1

Increment HL by 1

Store data from reg. A to memory

Increment HL by 1

Store data from reg. C in to memory

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 :-

Address Opcode Label Mnemonic/ Comment


Operand
; Clear carry register C for
C000 0E START MVI C, 00H
addition

C001 00
; Point HL to first BCD
C002 21 LXI H, DO30 H
number at D030H

C003 30 ; Lower address byte

C004 D0 ; Higher address byte


; Load first BCD number
C005 7E MOV A, M from D030H into
Accumulator A
; Increment HL address by
C006 23 INX H
1 (point to D031H)
; Add the BCD number at
C007 86 ADD M
D031H to A
; Adjust the result in A to
C008 27 DAA BCD format

C009 D2 JNC SKIP ; If no carry, jump to skip

C00A 0D ; Lower address byte

C00B C0 ; Higher address byte

C00C 0C INR C ; If carry, increment C

; 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

C011 CF STOP RST 1 ; End program execution


Exp.4] Flowchart:-
START

Initialize B = 08

Initialize C = 00

Load HL with address D001H

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

Store data from reg. C to memory

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 :-

Address Opcode Label Mnemonic/ Comment


Operand
; Set B to 8 to represent the
C000 06 START MVI B, 08H
number of bits to check

C001 08
; Clear C to use it as a
C002 0E MVI C, 00H
counter for zeros

C003 00

C004 21 LXI H, D001H ; Load HL pair at D001H

C005 01 ; Lower address byte

C006 D0 ; Higher address byte

; Load the hexadecimal


C007 7E MOV A, M number from D001H into A
; Rotate Accumulator A
C008 0F UP RRC
right through carry
; If carry flag is set, jump to
C009 DA JC SKIP
SKIP

C00A 0D ; Lower address byte

C00B C0 ; Higher address byte

; 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

C00F 08 ; Lower address byte

C010 C0 ; Higher address byte

;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

C013 CF STOP RST 1 ; End program execution


Exp.5] Flowchart:-
START

Initialize A = 00H

Initialize C = 00H

Load HL with C030H

Load data in reg. B from memory

Increment HL by 1

Add the second number to A

Is Carry No
Set?

Yes

Increment C by 1

Decrement B by 1

No
Is B = 0 ?

Yes
Increment HL by 1

Store Acc. data in memory

Increment HL by 1

Store reg. C data in memory

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 :-

Address Opcode Label Mnemonic/ Comment


Operand
; Clear Accumulator A for
C000 3E START MVI A, 00 H multiplication result
C001 00
; Clear register C to hold the
C002 0E MVI C, 00 H higher byte of the result
C003 00
; Load the address of the
C004 21 LXI H, C030 H first number (C030H) into
HL
C005 30 ; Lower address byte

C006 C0 ; Higher address byte


; Move the first number
C007 46 MOV B, M
(from C030H) into register B
; Increment HL address by 1
C008 23 INX H (point to C031H)
; Add the second number
C009 86 UP ADD M (from C031H) to
Accumulator A
; Jump to SKIP if there's no
C00A D2 JNC SKIP
carry
C00B 0E ; Lower address byte

C00C C0 ; Higher address byte


; Increment C if there was a
C00D 0C INR C carry (higher byte)
; Decrement B (loop control
C00E 05 SKIP DCR B
for number of additions)
; If B is not zero, repeat the
C00F C2 JNZ UP multiplication process
C010 09 ; Lower address byte

C011 C0 ; Higher address byte


; Increment HL address by
C012 23 INX H
1(point to C032H)
; Store the lower byte of the
C013 77 MOV M, A
result in C032H
; Increment HL address by 1
C014 23 INX H
(point to C033H)
; Store the higher byte
C015 71 MOV M, C
(carry) in C033H
C016 CF STOP RST 1 ; End program execution
Exp.6] Flowchart:-
START

Initialize C = 00H

Load HL with D001H

Load data in reg. A from memory

Increment HL by 1

Compare data of reg. A with memory

Is Carry Yes
Set?

No

Subtract data of memory from A

Increment quotient C by 1

Increment HL by 1

Store quotient from reg. C to memory

Increment HL by 1

Store remainder from reg. A to memory

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 :-

Address Opcode Label Mnemonic/ Comment


Operand
C000 0E START MVI C, 00 H ; Initialize C (quotient) to 0

C001 00
; Load HL with the address
C002 21 LXI H, D001 H
of the dividend (D001H)
C003 01 ; Lower address byte

C004 D0 ; Higher address byte


; Move the dividend into
C005 7E MOV A, M
the Accumulator (A)
; Increment HL address by
C006 23 INX H
1 (point to D002H)
; Compare the dividend (A)
C007 BE UP CMP M
with the divisor (M)
; If Carry Set (A < M), jump
C008 DA JC SKIP
to SKIP
C009 10 ; Lower address byte

C00A C0 ; Higher address byte


; Subtract the divisor from
C00B 96 SUB M
the dividend
; Increment C (the
C00C 0C INR C quotient) by 1
C00D C3 JMP UP ; Repeat the loop

C00E 07 ; Lower address byte

C00F C0 ; Higher address byte


;Increment HL address by 1
C010 23 SKIP INX H
(point to D003H)
; Store the quotient in
C011 71 MOV M, C
memory location D003H
;Increment HL address by 1
C012 23 INX H
(point to D004H)
; Store the remainder
C013 77 MOV M, A
(value in A) at D004H
C014 CF STOP RST 1 ; End program execution
Exp. 7) Flowchart:-
START

Set sum in Accumulator to 0

Set carry counter C to 0

Load the HL pair as memory pointer at D000

B
Copy bock length as location counter from memory to reg. B

Increment HL address by 1

Add memory content with accumulator

Decimal Adjust Accumulator

No
Is carry
present?

Yes

Increment carry counter C

Decrement location counter B

Is location
No
counter
zero?

Yes

Load the HL pair as memory pointer at D060

Copy sum from Accumulator to HL memory

Increment HL address by 1

Copy carry from Reg. C to HL memory

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 :-

Address Opcode Label Mnemonic/ Comment


Operand
;Set sum in Accumulator to
C000 3E START MVI A, 00H 0
C001 00
C002 0E MVI C, 00H ;Set carry counter C to 0

C003 00
;Load the HL pair as
C004 21 LXI H, D000H
memory pointer at D000
C005 00 ;Lower address byte

C006 D0 ;Higher address byte


;Copybock length as
C007 46 MOV B, M location counter from
memory to reg. B
C008 23 UP INX H ;Increment HL address by 1
;Add memory content with
C009 86 ADD M accumulator
;Decimal Adjust
C00A 27 DAA
Accumulator
C00B D2 JNC SKIP ;jump if no carry to SKIP

C00C 0F ;Lower address byte

C00D C0 ;Higher address byte

C00E 0C INR C ;Increment carry counter C


;Decrement location
C00F 05 SKIP DCR B
counter B
;Is location counter zero?
C010 C2 JNZ UP No – jump to UP
C011 08 ;Lower address byte

C012 C0 ;Higher address byte


;Load the HL pair as
C013 21 LXI H, D060H
memory pointer at D060
C014 60 ;Lower address byte

C015 D0 ;Higher address byte


;Copy sum from
C016 77 MOV M, A
Accumulator to memory
C017 23 INX H ;Increment HL address by 1
;Copy carry from Reg. C to
C018 71 MOV M, C
memory
C019 CF STOP RST 1 ;Stop program execution
Exp.8] Flowchart:-

START

Set location counter in reg. B

Load the HL pair as memory pointer at


D050

Load the DE pair as memory pointer at D084

Move memory data to Accumulator

Store Accumulator data to memory of DE

Increment HL address by 1

Decrement DE address by 1

Decrement location counter

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 :-

Address Opcode Label Mnemonic/ Comment


Operand
;Setlocation counter in reg.
C000 06 START MVI B, 05 H
B

C001 05
;Load the HL pair as
C002 21 LXI H, D050 H
memory pointer at D050

C003 50 ;Lower address byte

C004 D0 ;Higher address byte

;Load the DE pair as


C005 11 LXI D, D084 H
memory pointer at D084

C006 84 ;Lower address byte

C007 D0 ;Higher address byte

;Move memory data to


C008 7E UP MOV A, M
Accumulator
;Store Accumulator data to
C009 12 STAX D
memory of DE

C00A 23 INX H ;Increment HL address by 1

C00B 1B DCX D ;Decrement DE address by 1

;Decrement location
C00C 05 DCR B
counter
;Is location counter zero?
C00D C2 JNZ UP No – jump to UP

C00E 08 ;Lower address byte

C00F C0 ;Higher address byte

C010 CF STOP RST 1 ;Stop program execution


Exp.9] Flowchart:-
START

Set location counter in reg. B

Load the HL pair as memory pointer at D041

Load the DE pair as memory pointer at D071

Load Accumulator from memory of DE

Copy data from HL memory to reg. C

Copy Accumulator data to HL memory

Copy reg. C data to Accumulator

Store Accumulator data to memory of DE

Increment HL address by 1

Increment DE address by 1

Decrement location counter 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 :-

Memory Data Memory Data


location location
D041 AA D071 11
D042 BB D072 22
D043 CC D073 33
D044 DD D074 44
D045 EE D075 55

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 :-

Address Opcode Label Mnemonic/ Comment


Operand

C000 06 START MVI B, 05H ;Set location counter in reg. B

C001 05
;Load the HL pair as memory
C002 21 LXI H, D041H
pointer at D041

C003 41 ;Lower address byte

C004 D0 ;Higher address byte

;Load the DE pair as memory


C005 11 LXI D, D071H
pointer at D071

C006 71 ;Lower address byte

C007 D0 ;Higher address byte

;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

C00D 23 INX H ;Increment HL address by 1

C00E 13 INX D ;Increment DE address by 1

;Decrement location counter


C00F 05 DCR B
by 1
;Is location counter zero? No
C010 C2 JNZ UP – jump to UP

C011 08 ;Lower address byte

C012 C0 ;Higher address byte

C013 CF STOP RST 1 ;Stop program execution


Exp. 10] Flowchart:-
START

Load the HL pair as memory pointer at C060

Move data of HL memory to Accumulator

B
AND the data of Accumulator with 0F. This will separate the
lower nibble from 2 digit number.

Copy lower nibble from Accumulator to B reg.

Again move memory content to Accumulator

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.

Copy higher nibble from Accumulator to reg. C

C
Increment HL address by 1
B

Copy lower nibble from reg. B to HL memory

Increment HL address by 1

Copy higher nibble from reg. C to HL memory

Make Accumulator content to zero

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

Add Accumulator content with reg. C

Decrement counter by 1

Is
No counter
zero?

Yes
Increment HL address by 1

Copy product from Accumulator to HL memory

STOP
PROGRAM :-

Address Opcode Label Mnemonic/ Comment


Operand
;Load the HL pair as
C000 21 START LXI H, C060 H
memory pointer at C060

C001 60 ;Lower address byte

C002 C0 ;Higher address byte

;Move data of HL memory to


C003 7E MOV A, M
Accumulator
;AND the data of
Accumulator with 0F. This
C004 E6 ANI 0F H will separate the lower
nibble from 2 digit number.

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

C00F 23 INX H ;Increment HL address by 1

;Copy lower nibble from reg.


C010 70 MOV M, B
B to HL memory

C011 23 INX H ;Increment HL address by 1

;Copy higher nibble from


C012 71 MOV M, C reg. C to HL memory
;Make Accumulator content
C013 3E MVI A, 00 H
to zero

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

C016 05 DCR B ;Decrement counter by 1

;Is counter zero? No – jump


C017 C2 JNZ UP
to UP

C018 15 ;Lower address byte

C019 C0 ;Higher address byte

C01A 23 INX H ;Increment HL address by 1

;Copy product from


C01B 77 MOV M, A
Accumulator to HL memory

C01C CF STOP RST 1 ;Stop program execution


Exp. 11] Flowchart:-
START

Set reg. C as Odd counter to 0

Load the HL pair as memory pointer at D060

B
Set block length as location counter from HL memory to reg. B

Increment HL address by 1

Move memory data to Accumulator

B
Rotate right

No
Is carry
present?

Yes
Increment odd counter C

Decrement location counter B

No Is location
counter
zero?

Yes
Load Accumulator with the data of memory D060

Subtract odd count in reg. C from Accumulator to get even count

Load the HL pair as memory pointer at D100

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

Copy odd count from reg. C to HL memory

Increment HL address by 1

Copy even count from Accumulator to HL memory

STOP

BEFORE EXECUTION :- AFTER EXECUTION :-


Memory location Data Memory location Data
D060 D060
05 05
(Block length) (Block length)
D061 02 D061 02
D062 03 D062 03
D063 05 D063 05
D064 06 D064 06
D065 07 D065 07
D100 D100
(ODD COUNT)
00 (ODD COUNT)
03
D101 D101
(EVEN COUNT)
00 02
(EVEN COUNT)

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 :-

Address Opcode Label Mnemonic/ Comment


Operand
;Set reg. C as Odd counter
C000 0E START MVI C, 00 H
to 0
C001 00
;Load the HL pair as
C002 21 LXI H, D060 H
memory pointer at D060
C003 60 ;Lower address byte

C004 D0 ;Higher address byte


;Set block length as
C005 46 MOV B, M location counter from HL
memory to reg. B
C006 23 UP INX H ;Increment HL address by 1
;Move memory data to
C007 7E MOV A, M
Accumulator
C008 0F RRC ;Rotate right

C009 D2 JNC SKIP ;jump if no carry to SKIP

C00A 0D ;Lower address byte

C00B C0 ;Higher address byte

C00C 0C INR C ;Increment odd counter C


;Decrement location
C00D 05 SKIP DCR B
counter B
;Is location counter zero?
C00E C2 JNZ UP No – jump to UP
C00F 06 ;Lower address byte

C010 C0 ;Higher address byte


;Load Accumulator with the
C011 3A LDA D060 H
data of memory D060
C012 60 ;Lower address byte

C013 D0 ;Higher address byte


;Subtract odd count in reg.
C014 91 SUB C C from Accumulator to get
even count
;Load the HL pair as
C015 21 LXI H, D100 H
memory pointer at D100
C016 00 ;Lower address byte

C017 D1 ;Higher address byte


;Copy odd count from reg.
C018 71 MOV M, C C to HL memory
C019 23 INX H ;Increment HL address by 1
;Copyeven count from
C01A 77 MOV M, A
Accumulator to HL memory
C01B CF STOP RST 1 ;Stop program execution
Exp. 12] Flowchart:-
START

Set reg. C as counter to 0

Load the HL pair as memory pointer at D050

B
Set block length as location counter from HL memory to reg. B

Increment HL address by 1

Move memory data to Accumulator

B
Compare Accumulator with immediate data AD

Is result No
zero?

Yes
Increment counter C

Decrement location counter B

No Is location
counter
zero?

Yes
Load the HL pair as memory pointer at E000

Copy count from reg. C to HL memory

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 :-

Address Opcode Label Mnemonic/ Comment


Operand
C000 0E START MVI C, 00 H ;Set reg. C as counter to 0

C001 00
;Load the HL pair as
C002 21 LXI H, D050 H
memory pointer at D050
C003 50 ;Lower address byte

C004 D0 ;Higher address byte


;Set block length as
C005 46 MOV B, M location counter from HL
memory to reg. B
C006 23 UP INX H ;Increment HL address by 1
;Move memory data to
C007 7E MOV A, M
Accumulator
;Compare Accumulatorwith
C008 FE CPI AD H
immediate data AD
C009 AD
C00A C2 JNZ SKIP ;jump if no zero to SKIP

C00B 0E ;Lower address byte

C00C C0 ;Higher address byte

C00D 0C INR C ;Increment counter C


;Decrement location
C00E 05 SKIP DCR B counter B
;Is location counter zero?
C00F C2 JNZ UP
No – jump to UP
C010 06 ;Lower address byte

C011 C0 ;Higher address byte


;Load the HL pair as
C012 21 LXI H, E000 H
memory pointer at E000
C013 00 ;Lower address byte

C014 E0 ;Higher address byte


;Copy count from reg. C to
C015 71 MOV M, C HL memory
C016 CF STOP RST 1 ;Stop program execution
Exp. 13] Flowchart:-
START

Set reg. B as location counter to 0A

Load the HL pair as memory pointer at D040

B
Move memory content to reg. D assuming greatest no.

Move memory content to reg. E assuming smallest no.

Decrement location counter B by 1

Increment HL address by 1

Move next memory data to Accumulator

Compare whether reg. D contents are greater than reg. A

Is carry Yes
present?

No
Copy greatest number from reg. A to reg. D

Compare whether reg. E contents are smaller than reg. A

Is carry No
present?

Yes
Copy smallest number from reg. A to reg. E

Decrement location counter B

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

Copy greatest no. from reg. D to HL memory

Increment HL address by 1

Copy smallest no. from reg. E to HL memory

STOP
PROGRAM :-

Address Opcode Label Mnemonic/ Comment


Operand
;Set reg. B as location
C000 06 START MVI B, 0A H counter to 0A
C001 0A
;Load the HL pair as
C002 21 LXI H, D040 H memory pointer at D040

C003 40 ;Lower address byte

C004 D0 ;Higher address byte


;Move memory content
C005 56 MOV D, M to reg. D assuming
greatest no.
;Move memory content
C006 5E MOV E, M to reg. E assuming
smallest no.
;Decrement location
C007 05 DCR B
counter B by 1
;Increment HL address
C008 23 UP INX H
by 1
;Move next memory data
C009 7E MOV A, M
to Accumulator
;Compare whether reg. D
C00A BA CMP D contents are greater
than reg. A
C00B DA JC SKIP ;jump on carry to SKIP

C00C 0F ;Lower address byte

C00D C0 ;Higher address byte


;Copy greatest number
C00E 57 MOV D, A from reg. A to reg. D
;Compare whether reg. E
C00F BB SKIP CMP E contents are smaller
than reg. A
;jump on no carry to
C010 D2 JNC NEXT
NEXT
C011 14 ;Lower address byte

C012 C0 ;Higher address byte


;Copy smallest number
C013 5F MOV E, A from reg. A to reg. E
;Decrement location
C014 05 NEXT DCR B
counter B
;Is location counter
C015 C2 JNZ UP zero? No – jump to UP
C016 08 ;Lower address byte

C017 C0 ;Higher address byte


BEFORE EXECUTION :- AFTER EXECUTION :-
Memory Data Memory Data
location location
D040 06 D040 06
D041 56 D041 56
D042 04 D042 04
D043 01 D043 01
D044 59 D044 59
D045 64 D045 64
D046 77 D046 77
D047 35 D047 35
D048 05 D048 05
D049 12 D049 12
D04A D04A
(Largest no)
00 (Largest no)
77
D04B D04B
(Smallest no)
00 (Smallest no)
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
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

C018 23 INX H ;Increment HL address by 1

;Copy greatest no. from reg.


C019 72 MOV M, D
D to HL memory

C01A 23 INX H ;Increment HL address by 1

;Copy smallest no. from reg.


C01B 73 MOV M, E
E to HL memory

C01C CF STOP RST 1 ;Stop program execution

You might also like