0% found this document useful (0 votes)
43 views4 pages

CS2 2020 Q 5 Programs

This document contains three Assembly Language Programs (ALPs) with the following functions: 1. The first ALP counts the number of occurrences of the data byte 02H in a block of memory and stores the count in memory location D100H. 2. The second ALP copies a block of data from one memory location to another. 3. The third ALP subtracts a 3-byte number stored in register EHL from a BCD number, generates the 2's complement of values in a block, calculates the sum of values in a block, and divides two values storing the quotient and remainder in memory.

Uploaded by

Amitava Ghosh
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)
43 views4 pages

CS2 2020 Q 5 Programs

This document contains three Assembly Language Programs (ALPs) with the following functions: 1. The first ALP counts the number of occurrences of the data byte 02H in a block of memory and stores the count in memory location D100H. 2. The second ALP copies a block of data from one memory location to another. 3. The third ALP subtracts a 3-byte number stored in register EHL from a BCD number, generates the 2's complement of values in a block, calculates the sum of values in a block, and divides two values storing the quotient and remainder in memory.

Uploaded by

Amitava Ghosh
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/ 4

CS2 – Board Paper 2020 – Programs Solution

Q5A
a. ALP to count 02H
LABEL MNEMONICS COMMENTS
LXI H, D000H ;Load address to HL pair
MOV C, M ;Store the length of block to C
MVI B, 00H ;Initialise B to 0 for counting data byte 02H
UP: INX H ;Increment HL pair
MOV A,M ;copy value at memory to Acc
CPI 02H ;compare acc with 02H
JNZ DN ;If not equal, jump down on DN
INR B ;If equal, increment B
DN: DCR C ;decrement block counter
JNZ UP ;jump up for further value comparison
MOV A,B ;copy count of 02H to accumulator
STA D100H ;Store the count from Acc to Memory Location

RST1 ;Stop Execution

b. ALP to copy block of data to another memory location


LABEL MNEMONICS COMMENTS
LXI H, D001H ;Load address to HL pair
LXI B, 2501H ;Load address to BC pair
MVI D, 05H ;Initialise D to 5 – Block size
UP: MOV A,M ;copy value at memory to Acc
STAX B ;store value from acc to address in BC
INX H ;increment HL pair
INX B ;increment BC pair
DCR D ;decrement block counter
JNZ UP ;jump up for next value transfer

RST1 ;Stop Execution

c. ALP to Subtract 3 byte number in EHL from BCD.


LABEL MNEMONICS COMMENTS
MOV A,D ;Copy value in Reg. D to A
SBB L ;Subtract L from A
MOV D,A ;Store the result back to D
MOV A, C ;Move value of C to A
SBB H ;Subtract H with borrow from A
MOV C,A ;Store the result back to C
MOV A, B ;Move value of B to A
SBB E ;Subtract E with borrow from A
MOV B,A ;Store the result back to B

RST1 ;Stop Execution


Q5B
a. ALP to generate 2’s compliment of each value in a block
LABEL MNEMONICS COMMENTS
LXI H, 2FFFH ;Load address to HL pair
MOV D, M ;Store the length of block to D
LXI H, 3330H ;Load HL pair with starting address of the block
LXI B, 4100H ;Load address to BC pair
UP: MOV A,M ;copy value at memory to Acc
CMA ;compliment accumulator
INR A ;add 1 to compliment for 2’s compliment
STAX B ;Store 2’s compliment at memory in BC pair
INX H ;increment HL pair
INX B ;increment BC pair
DCR D ;decrement block counter
JNZ UP ;jump up for the next value

RST1 ;Stop Execution


b. ALP to calculate SUM of values in a block of data
LABEL MNEMONICS COMMENTS
LXI H, C000H ;Load address to HL pair
MOV B, M ;Store the length of block to B
MVI C, 00H ;Initialise C to 0 for carry
INX H ;Increment HL pair
MOV A,M ;copy value at memory to Acc
DCR B ;decrement block counter as 1st value moved
UP: INX H ;increment HL pair
ADD M ;Add value at ML to Acc
JNC DN ;Jump down if no carry
INR C ;Increment carry
DN: DCR B ;decrement block counter
JNZ UP ;jump up for further value comparison
LXI H, C050H ;Load address in HL pair to store result
MOV M,A ;Store sum at ML
INX H ;Increment HL pair
MOV M,C ;Store carry at next ML

RST1 ;Stop Execution

c. ALP to divide 2 values


LABEL MNEMONICS COMMENTS
LXI H, 4060H ;Load address to HL pair
MOV A, M ;Store dividend in Acc
INX H ;Increment HL pair
MOV B,M ;Store divisor in B
MVI C,00H ;Initialise C to 0 for Quotient
UP: CMP B ;Compare A with B
JC DN ;Jump down if A<B
SUB B ;Subtract B from A
INR C ;Increment Quotient
JMP UP ;Jump UP
DN: INX H ;Increment HL pair
MOV M,C ;Store quotient at ML
INX H ;Increment HL pair
MOV M,A ;Store remainder at next ML

RST1 ;Stop Execution

You might also like