Assignment MP
Assignment MP
Problem 1
Calculate the sum of series of numbers. The length of the series is in memory location 3200H and the series
begins from memory location 3201H.
a. Consider the sum to be 8 bit number. So, ignore carries. Store the sum at memory location 3300H.
b. Consider the sum to be 16 bit number. Store the sum at memory locations 3300H and 3301H.
a. Sample problem
3200H
3201H
3202H
3203H
3204H
=
=
=
=
=
04H
1AH
45H
3BH
22H
Source program:
LDA 3200H
MOV C, A
SUB A
LXI H, 320lH
ADD M
INX H
DCR C
JNZ BACK
STA 3300H
EF
BACK:
: Initialize counter
: sum = 0
: Initialize pointer
: SUM = SUM + data
: increment pointer
: Decrement counter
: if counter 0 repeat
: Store sum
: Terminate program execution
b. Sample problem
3200H
320lH
3202H
3203H
3204H
=
=
=
=
=
04H
9AH
52H
89H
3EH
Results
3300H = Lower byte
3301H = Higher byte
Source program:
LDA 3200H
MOV C, A
LXI H, 3201H
SUB A
MOV B, A
BACK: ADD M
JNC SKIP
INR B
SKIP: INX H
DCR C
JNZ BACK
STA 3300H
: Initialize counter
: Initialize pointer
:Sum low = 0
: Sum high = 0
: Sum = sum + data
: Add carry to MSB of SUM
: Increment pointer
: Decrement counter
: Check if counter 0 repeat
: Store lower byte
MOV A, B
STA 3301H
EF
Problem 2
Multiply two 8-bit numbers stored in memory locations 3200H and 3201H by repetitive addition and store the
result in memory locations 3300H and 3301H.
Sample problem:
3200H = 03H
3201H = B2H
Result = B2H + B2H + B2H = 216H
3300H = 16H
3301H = 02H
Source program
LDA 3200H
MOV E, A
MVI D, 00
LDA 3201H
MOV C, A
LX I H, 0000 H
BACK: DAD
D
DCR
C
JNZ
BACK
SHLD 3300H
EF
Problem 3
Divide 16 bit number stored in memory locations 3200H and 3201H by the 8 bit number stored at memory
location 3202H. Store the quotient in memory locations 3300H and 3301H and remainder in memory locations
3302H and 3303H.
Sample problem
3200H = 60H
3201H = A0H
3202H = 12H
Result = A060H/12H = 08E8H Quotient and 10H remainder
3300H = E8H
3301H = 08H
3302H= 10H
3303H= 00H
Source program
LHLD 3200H
LDA 3202H
MOV C, A
LXI D, 0000H
BACK: MOV A, L
SUB C
MOV L, A
JNC SKIP
DCR H
SKIP: INX D
MOV A, H
CPI, 00
JNZ BACK
MOV A, L
CMP C
JNC BACK
SHLD 3302H
XCHG
SHLD 3300H
EF
Problem 4
Find the number of negative elements (most significant bit 1) in a block of data. The length of the block is in
memory location 3200H and the block itself begins in memory location 3201H. Store the number of negative
elements in memory location 3300H
Sample problem
3200H
3201H
3202H
3203H
3204H
=
=
=
=
=
04H
56H
A9H
73H
82H
: Initialize count
: Negative number = 0
: Initialize pointer
: Get the number
: Check for MSB
: If MSB = 1
: Increment negative number count
: Increment pointer
: Decrement count
: If count 0 repeat
: Store the result
: Terminate program execution
Problem 5
Find the largest number in a block of data. The length of the block is in memory location 3200H and the block
itself starts from memory location 3201H. Store the maximum number in memory location 3300H. Assume
that the numbers in the block are all 8 bit unsigned binary numbers.
Sample problem
3200H
3201H
3202H
3203H
3204H
= 04
= 34H
= A9H
= 78H
=56H
: Initialize counter
: Maximum = Minimum possible value = 0
: Initialize pointer
: Is number> maximum
: Yes, replace maximum
Problem 6
Write a program to count number of l's in the contents of D register and store the count in the B register.
Source program:
MVI B, 00H
MVI C, 08H
MOV A, D
BACK: RAR
JNC SKIP
INR B
SKIP: DCR C
JNZ BACK
EF
Problem 7
Write a program to sort given 10 numbers from memory location 3200H in the ascending order.
Source program:
START:
BACK:
SKIP:
MVI B, 09
LXI H, 3200H
MVI C, 09H
MOV A, M
INX H
CMP M
JC SKIP
JZ SKIP
MOV D, M
MOV M, A
DCX H
MOV M, D
INX H
DCR C
JNZ BACK
DCR B
JNZ START
EF
: Initialize counter
: Initialize memory pointer
: Initialize counter 2
: Get the number
: Increment memory pointer
: Compare number with next number
: If less, don't interchange
: If equal, don't interchange
Problem 8
Calculate the sum of series of even numbers from the list of numbers. The length of the list is in memory
location 3200H and the series itself begins from memory location 3201H. Assume the sum to be 8 bit number so
you can ignore carries and store the sum at memory location 3210H.
Sample problem:
3200H=
3201H=
3202H=
3203H=
3204H=
4H
20H
l5H
l3H
22H
Source program:
LDA 3200H
MOV C, A
MVI B, 00H
LXI H, 3201H
BACK: MOV A, M
ANI
0lH
JNZ SKIP
MOV A, B
ADD
M
MOV B, A
SKIP: INX H
DCR
C
JNZ
BACK
STA
3210H
EF
: Initialize counter
: sum = 0
: Initialize pointer
: Get the
number
: Mask Bit l to Bit7
: Don't add if number is ODD
: Get the sum
: SUM= SUM+ data
: Store result in B register
: increment pointer
: Decrement counter
: if counter 0 repeat
: store sum
: Terminate program execution
Problem 9
Find the square of the given numbers from memory location 3100H and store the result from memory location
3500H.
Source Program:
LXI H, 3200H
: Initialize lookup table pointer
LXI D, 3100H
: Initialize source memory pointer
LXI B, 3500H
: Initialize destination memory pointer
BACK: LDAX D
: Get the number
MOV L, A
: A point to the square
MOV A, M
: Get the square
STAX B
: Store the result at destination memory location
INX D
: Increment source memory pointer
INX B
: Increment destination memory pointer
MOV A, C
CPI 05H
: Check for last number
JNZ BACK
: If not repeat
EF
: Terminate program execution
Problem 10
Search the given byte in the list of 5 numbers stored in the consecutive memory locations and store the address
of memory location in the memory locations 3200H and 3201H. Assume byte is in the C register and starting
address of the list is 3500H. If byte is not found store 00 at 2200H and 2201H.
Source program:
LX I H, 3500H
: Initialize memory pointer
MVI B, 05H
: Initialize counter
BACK: MOV A, M
: Get the number
CMP C
: Compare with the given byte
JZ LAST
: Go last if match occurs
INX H
: Increment memory pointer
DCR B
: Decrement counter
JNZ B
: I f not zero, repeat
LXI H, 0000H
SHLD 3200H
: Store 00 at 3200H and 3201H
JMP END
LAST: SHLD 3200H
: Store memory address
END: EF
: Stop
Problem 11
Add 2 arrays having ten 8-bit numbers each and generate a third array of result. It is necessary to add the first
element of array 1 with the first element of array-2 and so on. The starting addresses of array l, array2 and
array3 are 3200H, 3300H and 3400H, respectively.
Source Program:
LXI H, 3200H
LXI B, 3300H
LXI D, 3400H
BACK: LDAX B
ADD M
STAX D
INX H
INX B
INX D
MOV A, L
CPI 0AH
JNZ BACK
EF
10