Microprocessor Assignment3
Microprocessor Assignment3
1
Assignment 3
PROBLEM 1: Let two 16-bit numbers are stored in memory locations from
A050H to A053H. Add the numbers and multiply the result by 4 (decimal) and
store the result in memory locations A054H and A055H.
CODE:
Memory Level Mnemonics Op code Comments
Address
0800H LHLD A050H 2AH 50H A0H Load HL pair by the data from
memory locations A051H and
A050H respectively.
0803H XCHG EBH Exchange the contents of HL
and DE register pair.
0804H LHLD A052H 2AH 52H A0H Load HL pair by the data from
memory locations A053H and
A052H respectively.
080CH JNZ L1 C2H 0AH 08H For non zero value of C jump
on L1.
080FH SHLD A054H 22H 54H A0H Store the HL pair data in
memory locations A055H and
A054H.
2
RESULTS:
COMMENT: Here we have taken the counter register C initialized by 02H as we need to multiply the
sum by 4. The result is stored in memory location A061 and A060 respectively. The program has been
successfully executed.
3
PROBLEM 2: Add two BCD numbers stored in memory locations A100H and
A101H. Place the result in memory location A110H. The result should also be in
BCD.
CODE:
Memory Level Mnemonics Op code Comments
Address
7700H LHLD A100H 2AH 00H A1H Load HL pair by the data
from memory locations
A101H and A100H
respectively.
7703H MVI C,00H 0EH 00H Initialize C register by 00h
7705H MOV B,H 44H Copy the contents of H to B
register.
7706H MOV A,L 7DH Copy the contents of L to A
register.
7707H ADD B 80H Add contents of B with A.
4
RESULTS:
COMMENT: Here we have used DAA instruction. It actually coverts the binary number in
accumulator as BCD number. Using this DAA we can subtract two BCD numbers with the help
of complement’s method. the program has been executed successfully.
5
PROBLEM 3: Calculate the sum of series of 8 bit numbers. Length of the series is
stored in location A100H and the series begins from A101H. The sum will be
stored in some separate memory location.
CODE:
Memory Level Mnemonics Op code Comments
Address
0800H LDA A100H 3AH 00H A1H Load A by the data stored in
memory location A100H.
0803H MOV C,A 4FH Copy the contents of A to C.
0804H LXI H,A101H 21H 01H A1H Load HL pair by A101H.
0807H MVI A,00H 3EH 00H Initialize A by 00H.
0808H L1 ADD M 86H Add contents of memory
location specified in HL pair
with the contents of A.
0809H INX H 23H Increment contents of HL
pair by 1.
080AH DCR C 0DH Decrement the contents of C
by 1.
080BH JNZ L1 C2H 08H 08H If C is non zero jump on L1
level.
080EH STA A000H 32H 00H A0H Store the Accumulator result
in A000H address.
0811H HLT 76H Terminate program
6
RESULTS:
7
PROBLEM 4: Write an assembly language program to compute 16 bit sum of N
positive entries of a table. The first entry of the table contains the number of
elements N. The 16 bit sum will be kept in memory locations SUM-LO and SUM-
HI. If the sum requires more than 16 bits, only the lower bits will be kept and
the MSB is said to be truncated.
CODE:
Memory Level Mnemonics Op code Comments
Address
0800H LDA 8050H 3AH 50H 80H Load the Accumulator by the
data stored in 3050H location
of memory.
0803H MVI B,00H 06H 00H Initialize B by 00H
0805H LXI SP,8300H 31H 00H 83H Load SP by 8300H
8
081BH INX H 23H Increment HL content by 1
RESULTS:
COMMENT: The program has been executed successfully. Here we have used
XTHL instruction which means data exchange occurs between HL and Top of
Stack.
9
PROBLEM 5: Take any 10 natural numbers in consecutive memory locations
starting from A050H. Add the odd numbers and store the result in register E and
add the even numbers and store the result in register D.
CODE:
Memory Level Mnemonics Op code Comments
Address
0800H MVI C,0AH 0EH Initialize C by 0A H.
10
0816H JNZ L2 C2H 06H 08H If C is non zero jump on level
L2.
0819H MOV H,D 62H Copy the contents of D into H
081BH SHLD A070H 22H 70H A0H Store the content of HL pair in
memory location specified by
the address A070H and
A071H.
081EH HLT 76H Terminate the program.
RESULTS:
11
PROBLEM 6: Write an assembly language program to check a block of data and
count how many times a given data (say FFH) is found in the data block. The
size of the data block to be checked is stored in A100H and the data are stored
starting from A101H.
CODE:
Memory Level Mnemonics Op code Comments
Address
0800H MVI B,00H 06H 00H Initialize B by 00 H.
0802H LDA A100H 3AH 00H A1H Load accumulator by the data
from memory location
specified A100H.
0805H MOV C,A 4FH Copy the contents of A into C.
12
081CH STA A120H 32H 20H A1H Store the content of
accumulator in memory
location A120H
081DH HLT 76H Program termination.
RESULTS:
COMMENT: The program has been executed successfully. here we have chosen
the data=(FF)H. It may be anything else.
13
PROBLEM 7: Write an assembly language program to check a block of data to
find out the largest value stored in the block. The data is stored from A050H.
CODE:
Memory Level Mnemonics Op code Comments
Address
0800H LDA A04FH 3AH 4FH A0H Load the accumulator by the
data stored in memory
location A04F H.
0803H MOV C,A 4FH Copy the contents of A into C
14
081CH MOV M,B 70H Copy the contents of B into
memory location hold by HL
pair.
081DH HLT 76H Program Termination.
RESULTS:
COMMENT: The program has been executed successfully. The largest value is
stored in A060 H location in memory.
15
PROBLEM 8: Consider any two distinct memory segments of your choice and
name the starting location address of those segments as X and Y. Write an
assembly language program to exchange 10 bytes of data stored from location
X with 10 bytes of data stored from location Y.
CODE:
Memory Level Mnemonics Op code Comments
Address
0800H MVI D,0AH 16H 0AH Initialize D by 0A H.
16
COMMENT: Here we have taken X location as A060H and Y location as A070H.The
program has been executed successfully. Middle portions are deliberately taken
as Zero to reduce the effort of being entered the numbers.
17
PROBLEM 9: Let 10 bytes of data are stored from location A100H. Write an
assembly language program to transfer the entire block to another memory
location starting from A105H.
CODE:
Memory Level Mnemonics Op code Comments
Address
0800H MVI D,0AH 16H 0AH Initialize D by 0A H
18
COMMENT: the program has been executed successfully without any errors. We
can do the problem by another method that is- we have to store the numbers of
overlapped portions in another portion of memory then rest portion is shifted
and then the rest portion is brought back.But this will increase the time
complexity and program complexity.
19
PROBLEM 10: Write an assembly language program to multiply two unsigned
8 bit numbers using shift and add method.
CODE:
Memory Level Mnemonics Op code Comments
Address
0800H LXI D,002EH 11H 2EH 00H Load DE pair by 002E H where
2E is the multiplicand
0816H SHLD A100H 22H 00H A1H Store the content of HL pair in
memory location specified by
20
the address A101H and
A100H.
RESULTS:
COMMENT: The program has been executed successfully. Here at the end of
program multiplicand is stored at A121H location in memory. The multiplication
result is stored inA101H and A100H. Initially we have taken the multiplicand in
register D and multiplier in Accumulator direct. They can also be fetched from
memory.
21
PROBLEM 11: Store a block of any ten 8-bit numbers in any order starting from
a location of your choice. Write an assembly language program to arrange that
block of ten 8-bit numbers in ascending order.
CODE:
Memory Level Mnemonics Op code Comments
Address
0800H LXI H,8050H 21H 50H 80H Load HL pair by 8050 H
22
O817H MOV M,B 70H Copy the data from register B
to memory .
RESULTS:
23
COMMENT: The program has been executed successfully. Here we have used
Bubble sort algorithm to sort the numbers in ascending number. It must be
remembered that after execution of inner loop HL pointer must start again from
8050H location. This is why inside the outer loop having D counter we have
loaded the HL pair by 8050 H.
24
PROBLEM 12: Store a block of any ten 8-bit numbers in any order starting from
a location of your choice.Write an assembly language program to arrange that
block of ten 8-bit numbers in descending order.
CODE:
Memory Level Mnemonics Op code Comments
Address
0800H LXI H,8050H 21H 50H 80H Load HL pair by 8050 H
25
0816H DCX H 2BH Decrement the content of HL
by 1
RESULTS:
26
COMMENT: The program has been executed successfully. This program is entirely
same with the ascending order program except I have replaced JC in this program
instead of JNC that was used in ascending order problem. It must be remembered
that after execution of inner loop HL pointer must start again from 8050H
location. This is why inside the outer loop having D counter we have loaded the
HL pair by 8050 H.
27