0% found this document useful (0 votes)
49 views27 pages

Microprocessor Assignment3

Soutrik Acharya is a student with University registration number d01-1111-0016-18. He is working on microprocessor and microcontroller laboratory assignments involving adding, multiplying, and summing numbers stored in memory locations using assembly language code. The code provided performs the requested operations and stores results correctly.

Uploaded by

Cazz Hustlers
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
49 views27 pages

Microprocessor Assignment3

Soutrik Acharya is a student with University registration number d01-1111-0016-18. He is working on microprocessor and microcontroller laboratory assignments involving adding, multiplying, and summing numbers stored in memory locations using assembly language code. The code provided performs the requested operations and stores results correctly.

Uploaded by

Cazz Hustlers
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 27

Name: Soutrik acharya

Class roll no: 438

University roll no: T91/ECE/184065


University registration no: d01-1111-0016-18

Subject: microprocessor & Microcontroller


Laboratory (EC3.2.6)

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.

0807H DAD D 19H Add contents of HL and DE


and store the sum in HL.
0808H MVI C,02H 0EH 02H Initialize C register by 02H.

080AH L1 DAD H 29H Multiply the HL contents by 2

080BH DCR C 0DH Decrement of C by 1.

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.

0812H HLT 76H Terminate program

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.

7708H DAA 27H Change the contents of the A


into BCD format.

7709H JC L1 DAH 0FH 77H If carry arises jump on L1.


770CH JMP L2 C3H 11H 77H Jump on L2.
770FH L1 INR C 0CH Increment C by 1.
7710H MOV L,C 69H Copy contents of C to L.
7711H L2 MOV H,A 67H Copy contents of A to H.
7712H SHLD A110H 22H 10H A1H Store the contents of HL pair
into the memory locations
A111H and A110H.
7715H HLT 76H Program Termination

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:

COMMENT: The program has been executed successfully.

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

0808H LXI H,8051H 21H 51H 80H Load HL by 8051H


080BH L3 MOV E,M 5EH Copy the contents of memory
to E.
080CH INX H 23H Increment HL content by 1
080DH MOV D,M 56H Copy the contents of memory
to D register
080EH XTHL E3H Exchange H and L with the
top of stack.
080FH DAD D 19H Add the contents of HL with
DE register pair.
0810H JC L1 DAH If carry arises jump on L1
level.
0813H JMP L2 C3H Jump on level L2

0816H L1 INR B 04H Increment the contents of B


by 1
0817H JMP L2 C3H Jump on level L2

081AH L2 XTHL E3H Exchange H and L with the


top of stack.

8
081BH INX H 23H Increment HL content by 1

081CH DCR A 3DH Decrement the contents of A


by 1.
081DH JNZ L3 C2H If C is non zero jump on L3
level.
0820H XTHL E3H Exchange H and L with the
top of stack.
0821H SHLD 8010H 22H 10H 80H Store the contents of HL pair
into the memory locations
8011H and 8010H.
0824H HLT 76H Terminate program

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.

0801H MVI D,00H 16H Initialize D by 00 H.

0802H MVI E,00H 1EH Initialize E by 00 H.

0803H LXI H,A050H 21H 50H A0H Load HL pair by A050 H

0806H L2 MOV A,M 7EH Copy the contents of memory


address specified by HL pair
to Accumulator.
0807H RAR 1FH Rotate accumulator right
through carry.
0808H JC L1 DAH 11H 08H If carry arises jump on level
L1.
080BH RAL 17H Rotate accumulator left
through carry.
080CH ADD D 82H Add the contents of D with A.

080DH MOV D,A 57H Copy the contents of A into D.

080EH JMP L3 C3H 14H 08H Jump on level L3.

0811H L1 RAL 17H Rotate accumulator left


through carry.
0812H ADD E 83H Add the contents of E with A.

0813H MOV E,A 5FH Copy the contents of A into E

0814H L3 INX H 23H Increment the contents of HL


pair by 1
0815H DCR C 0DH Decrement the contents of C
by 1

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

081AH MOV L,E 6BH Copy the contents of E into L

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:

COMMENT: The program has been executed successfully.Here we completed the


program having logic that- LSB decides awhether a number is odd or even. so we
do RAR.

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.

0806H LXI H,A101H 21H 01H A1H Load HL pair by A101 H.

0809H L3 MOV A,M 7EH Copy the contents of


memory(address hold by HL)
into A.
080AH CPI FFH FEH FFH Compare the contents of
accumulator with FFH
080CH JNZ L1 C2H 13H 08H If the Zero flag is reset jump
on the level L1.
080FH INR B 04H Increment the contents of B
by 1
0810H JMP L2 C3H 16H 08H Jump on level L2

0813H L1 JMP L2 C3H 16H 08H Jump on level L2

0816H L2 INX H 23H Increment the contents of HL


by 1
0817H DCR C 0DH Decrement of C register
content by 1
0818H JNZ L3 C2H 09H 08H If the Zero flag is reset jump
on the level L3.
081BH MOV A,B 78H Copy the contents of B into A.

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

0804H LXI H,A050H 21H 50H A0H Load HL pair by A050 H.

0807H MOV B,M 46H Copy the contents of memory


into B.
0808H L3 INX H 23H Increment the HL pair content
by 1
0809H MOV A,M 7EH Copy the contents of memory
into A.
080AH CMP B 88H Compare the content of
register B with the content of
A.
080BH JNC L1 D2H Jump on level L1 if carry flag
is reset.
080EH JMP L2 C3H Jump on level L2.

0811H L1 MOV B,A 47H Copy the contents of A into B


register
0812H JMP L2 C3H Jump on level L2

0815H L2 DCR C 0DH Decrement the content of C


by 1
0816H JNZ L3 C2H Jump on level L3 if Zero flag is
reset.
0819H LXI H,A060H 21H 60H A0H Load HL pair by A060H

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.

0802H LXI B,A060H 01H 60H A0H Load BC pair by A060H

0805H LXI H,A070H 21H 70H A0H Load HL pair by A070H

0808H L1 LDAX B 0AH Copy the data into A from the


memory address hold by BC
pair.
0809H MOV E,M 5EH Copy the contents of memory
into E.
080AH MOV M,A 77H Copy the contents of A into
memory .
080BH MOV A,E 7BH Copy the contents of E into A

080CH STAX B 02H Copy the data from A to


memory location specified in
BC pair
080DH INX H 23H Increment the contents of HL
by 1
080EH INX B 03H Increment the contents of BC
by 1
080FH DCR D 15H Decrement the content of D
by 1
0810H JNZ L1 C2H 08H 08H Jump on level 1 if Zero flag is
reset.
0813H HLT 76H Program termination.

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

0802H LXI B,A109H 01H 09H A1H Load BC pair by A109H

0805H LXI H,A10EH 21H 0EH A1H Load HL pair by A10E H

0808H L1 LDAX B 0AH Copy the data into A from the


memory address hold by BC
pair.
0809H MOV M,A 77H Copy the contents A into
memory address hold by HL
pair
080AH MVI A,00H 3EH 00H Initialize A by 00H

080CH STAX B 02H Copy the data from A to


memory location specified in
BC pair
080DH DCX B 0BH Decrement the content of BC
by 1

080EH DCX H 2BH Decrement the content of HL


by 1

080FH DCR D 15H Decrement the content of D


by 1

0810H JNZ L1 C2H 08H 08H Jump on level L1 if Zero flag is


reset.

0813H HLT 76H Program Termination.

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

0803H MVI A,1FH 3EH 1FH Initialize A by the multiplier


value 1F H

0805H MVI B,08H 06H 08H Initialize B by 08 H.

0807H LXI H,0000H 21H 00H 00H Initialize HL by 0000 H

080AH L2 RAR 1FH Rotate accumulator right


through carry.

080BH JNC L1 D2H 0FH 08H Jump on level L1 if carry flag is


reset.

080EH DAD D 19H Add the contents of DE with


HL contents

080FH L1 XCHG EBH Exchange the contents of H


and L with D and E
respectively.
0810H DAD H 29H Left shifting by one bit

0811H XCHG EBH Exchange the contents of H


and L with D and E
respectively.
0812H DCR B 05H Decrement the contents of B
by 1

0813H JNZ L2 C2H 0AH 08H Jump on level l2 if Zero flag is


reset

0816H SHLD A100H 22H 00H A1H Store the content of HL pair in
memory location specified by

20
the address A101H and
A100H.

0819H XCHG EBH Exchange the contents of H


and L with D and E
respectively.
081AH SHLD A120H 22H 20H A1H Store the content of HL pair in
memory location specified by
the address A021H and
A020H.
081DH HLT 76H Program Termination

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

0803H MVI D,09H 16H 09H Initialize D by 09H

0805H L4 MVI C,09H 0EH 09H Initialize C by 09H

0807H L2 MOV A,M 7EH Copy the data from memory


to Accumulator.

0808H INX H 23H Increment the content of HL

0809H CMP M BEH Compare the content of


memory with that of A.

080AH JNC L1 D2H 14H 08H Jump on level L1 if carry flag is


reset

080DH DCR C 0DH Decrement the content of c


by 1

080EH JNZ L2 C2H 07H 08H Jump on level L2 if Zero flag is


reset.

0811H JMP L3 C3H 20H 08H Jump on level L3

0814H L1 MOV B,M 46H Copy the data from memory


to register B.

0815H MOV M,A 77H Copy the data from A to


memory.

0816H DCX H 2BH Decrement the content of HL


by 1

22
O817H MOV M,B 70H Copy the data from register B
to memory .

0818H INX H 23H Increment the content of HL


by 1

0819H DCR C 0DH Decrement the content of C


by 1

081AH JNZ L2 C2H 07H 08H Jump on level 2 if Zero flag is


reset.

081DH JMP L3 C3H 20H 08H Jump on the level L3

0820H L3 DCR D 15H Decrement the content of D


by 1

0821H LXI H,8050H 21H 50H 80H Load HL pair by 8050 H.

0824H JNZ L4 C2H 05H 08H Jump on level L4 if zero flag is


reset.

0827H HLT 76H Program Termination

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

0803H MVI D,09H 16H 09H Initialize D by 09H

0805H L4 MVI C,09H 0EH 09H Initialize C by 09H

0807H L2 MOV A,M 7EH Copy the data from memory


to Accumulator.

0808H INX H 23H Increment the content of HL

0809H CMP M BEH Compare the content of


memory with that of A.

080AH JC L1 D2H 14H 08H Jump on level L1 if carry flag is


set

080DH DCR C 0DH Decrement the content of c


by 1

080EH JNZ L2 C2H 07H 08H Jump on level L2 if Zero flag is


reset.

0811H JMP L3 C3H 20H 08H Jump on level L3

0814H L1 MOV B,M 46H Copy the data from memory


to register B.

0815H MOV M,A 77H Copy the data from A to


memory.

25
0816H DCX H 2BH Decrement the content of HL
by 1

O817H MOV M,B 70H Copy the data from register B


to memory .

0818H INX H 23H Increment the content of HL


by 1

0819H DCR C 0DH Decrement the content of C


by 1

081AH JNZ L2 C2H 07H 08H Jump on level 2 if Zero flag is


reset.

081DH JMP L3 C3H 20H 08H Jump on the level L3

0820H L3 DCR D 15H Decrement the content of D


by 1

0821H LXI H,8050H 21H 50H 80H Load HL pair by 8050 H.

0824H JNZ L4 C2H 05H 08H Jump on level L4 if zero flag is


reset.

0827H HLT 76H Program Termination

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

You might also like