You are on page 1of 20

Program No.

: 1
School of Electronics Engineering
VIT, Vellore

Reg.No 19BEC0365

Student Name Shivani R

L41+L42
Course Code ECE3003 Slot & Semester
FALL ~ 2020-21

Course Name Microcontroller and its applications

Program Title Stack Operations and BCD Addition

Date of
Date of Exp. 22-02-2021 25-02-2021
Submission

Faculty A.Karthikeyan
Reg no: 19BEC0365 Fall 2019-20 ECE3003 - 𝜇C and its applications

Question
1. Write and assemble a program to add the following data and then use the simulator
to examine the CY flag. INPUT DATA REG NO: Example 01 7B EC 02 75. Five max
8BIT NUMBERS (FF ,FF,FF,FF,FF)

2. Write and assemble a program to load values into each of registers R0 - R4 and then
push each of these registers onto the stack. Single-step the program, and examine
the stack and the SP register after the execution of each instruction.

3. Write an 8051 assemble language program to:


(a) Set SP = 0D,
(b) Load a different value in each of RAM locations 0D, 0C, 0B, 0A, 09, and 08,
(c) POP each stack location into registers R0 - R4. Use the simulator to single-step
and examine the registers, the stack, and the stack pointer.

4. Write and assemble a program to load values into each of registers R0 - R4 and
then push each of these registers onto the stack and pop them back. Single-step the
program, and examine the stack and the SP register after the execution of each
instruction.

5.Write a program to add 10 bytes of BCD data and store the result in R2 and R3.
The bytes are stored in ROM space starting at 300H.

The data would look as follows:


MYDATA: DB ; pick your data. (10 DATA )

EX: 22H,43H,23H,34H,31H,77H,91H,33H,43H,07H

Notice that you must first bring the data from ROM space into the CPU's RAM,
then add them together. Use a simulator to single-step the program and examine the
data.

SENSE, VIT Page 2 of 20


Reg no: 19BEC0365 Fall 2019-20 ECE3003 - 𝜇C and its applications

Question 1:
Aim: To write an 8051 ALP to perform addition of 5 8BIT NUMBERS using keil software
and to verify the result manually.
Tools Required- Keil Software
Algorithm:
1. Decide the numbers to be added- 01 9B EC 03 65
2. Assign the first two numbers to A and B
3. Add the first two numbers using ADD and store in A
4. Shift contents of A to B
5. Assign the next number to A and repeat the process again
6. Repeat the same till all the numbers are added

Program:

Label Mnemonics Operands addressing Machine Memory Type of Comment Flags


mode used cycle Byte Instruction s getting
Require Require affected by
d d the
Instruction.

MOV A Immediate 1 2 Data The No flag


Transfer input is
stored
to A

MOV B Immediate 1 2 Data The No flag


Transfer input is
stored
to B

ADD A, B Register 1 1 Arithmetic A and B C, AC, OV


are
added
and
stored in
A

JNC L1 Indexed 2 2 Boolean Control No flag


shifts to
L1 if no
carry

SENSE, VIT Page 3 of 20


Reg no: 19BEC0365 Fall 2019-20 ECE3003 - 𝜇C and its applications

INC R0 Immediate 1 1 Arithmetic Register No flag


R0 is
increme
nted by
1

L1 MOV B, A Register 1 1 Data Data No flag


Transfer stored in
A is
moved
to B

MOV A Immediate 1 2 Data The No flag


Transfer input is
stored
to A

ADD A, B Register 1 1 Arithmetic A and B C, AC, OV


are
added
and
stored in
A

JNC L2 Indexed 2 2 Boolean Control No flag


shifts to
L1 if no
carry

INC R0 Immediate 1 1 Arithmetic Register No flag


R0 is
increme
nted by
1

L2 MOV B, A Register 1 1 Data Data No flag


Transfer stored in
A is
moved
to B

MOV A Immediate 1 2 Data The No flag


Transfer input is
stored
to A

SENSE, VIT Page 4 of 20


Reg no: 19BEC0365 Fall 2019-20 ECE3003 - 𝜇C and its applications

ADD A, B Register 1 1 Arithmetic A and B C, AC, OV


are
added
and
stored in
A

JNC L3 Indexed 2 2 Boolean Control No flag


shifts to
L1 if no
carry

INC R0 Immediate 1 1 Arithmetic Register No flag


R0 is
increme
nted by
1

L3 MOV B, A Register 1 1 Data Data No flag


Transfer stored in
A is
moved
to B

MOV A Immediate 1 2 Data The No flag


Transfer input is
stored
to A

ADD A, B Register 1 1 Arithmetic A and B C, AC, OV


are
added
and
stored in
A

JNC L4 Indexed 2 2 Boolean Control No flag


shifts to
L1 if no
carry

INC R0 Immediate 1 1 Arithmetic Register No flag


R0 is
increme
nted by
1
SENSE, VIT Page 5 of 20
Reg no: 19BEC0365 Fall 2019-20 ECE3003 - 𝜇C and its applications

L4 END

Output: Registers containing the Result:


A = F0H R0 = 01H

Manual Calculation:
BINARY DECIMAL

01 01 Decimal Addition:
01+155+236+03+101 = 496
9B 155
Decimal to Hexadecimal:
EC 236 (496)10 = (1F0)16

03 03

65 101

Results and Observations


Print Screen of the Program and registers before execution:

SENSE, VIT Page 6 of 20


Reg no: 19BEC0365 Fall 2019-20 ECE3003 - 𝜇C and its applications

Print Screen of the Program and registers after execution:

Inferences:
1. There is a carry

2. Final result (1F0) is stored in A

Result: The 8051 ALP to perform addition of 5 8BIT NUMBERS is executed using keil
software and the results are verified manually

Question 2:
Aim: To get values and load them to register and push them onto the stack.
Tools Required- Keil Software
Algorithm:
1. Decide the numbers to be loaded- 05 15 25 35 45
2. Assign the values to registers R0 to R4
3. Push each value into the stack
SENSE, VIT Page 7 of 20
Reg no: 19BEC0365 Fall 2019-20 ECE3003 - 𝜇C and its applications
4. Check for execution on the memory window

Program:

Label Mnemonics Operands addressing Machine Memory Type of Comments Flags


mode used cycle Byte Instruction getting
Required Required affected
by the
Instructio
n.

MOV R0 Immediate 1 2 Data The input No flag


Transfer is stored
to R0

MOV R1 Immediate 1 2 Data The input No flag


Transfer is stored
to R1

MOV R2 Immediate 1 2 Data The input No flag


Transfer is stored
to R2

MOV R3 Immediate 1 2 Data The input No flag


Transfer is stored
to R3

MOV R4 Immediate 1 2 Data The input No flag


Transfer is stored
to R4

PUSH Direct 2 2 Data The value No flag


Transfer is pushed
to stack

PUSH Direct 2 2 Data The value No flag


Transfer is pushed
to stack

PUSH Direct 2 2 Data The value No flag


Transfer is pushed
to stack

PUSH Direct 2 2 Data The value No flag


Transfer is pushed
to stack

SENSE, VIT Page 8 of 20


Reg no: 19BEC0365 Fall 2019-20 ECE3003 - 𝜇C and its applications

PUSH Direct 2 2 Data The value No flag


Transfer is pushed
to stack

END

Output: Registers containing the Result:


R0=05 R1=15 R2=25 R3=35 R4=45

Manual Calculation: None

Results and Observations


Print Screen of the Program and registers before execution:

Print Screen of the Program and registers after execution:

SENSE, VIT Page 9 of 20


Reg no: 19BEC0365 Fall 2019-20 ECE3003 - 𝜇C and its applications

Inferences:
1. All the data are pushed into the stack

2. We can view the operations through memory window

Result: The 8051 ALP to perform PUSH of 5 8BIT NUMBERS is executed using keil software and
the results are verified manually

Question 3:
Aim: To get values and load them to register and pop them out of the stack.
Tools Required- Keil Software
Algorithm:
1. Pop the already fed values out of the stack

Program:

Label Mnemonics Operands addressing Machine Memory Type of Comments Flags


mode used cycle Byte Instruction getting
Required Required affected by
the
Instruction.

SENSE, VIT Page 10 of 20


Reg no: 19BEC0365 Fall 2019-20 ECE3003 - 𝜇C and its applications

MOV R0 Immediate 1 2 Data The input No flag


Transfer is stored
to R0

MOV R1 Immediate 1 2 Data The input No flag


Transfer is stored
to R1

MOV R2 Immediate 1 2 Data The input No flag


Transfer is stored
to R2

MOV R3 Immediate 1 2 Data The input No flag


Transfer is stored
to R3

MOV R4 Immediate 1 2 Data The input No flag


Transfer is stored
to R4

POP Direct 2 2 Data The value No flag


Transfer is popped
from
stack

POP Direct 2 2 Data The value No flag


Transfer is popped
from
stack

POP Direct 2 2 Data The value No flag


Transfer is popped
from
stack

POP Direct 2 2 Data The value No flag


Transfer is popped
from
stack

POP Direct 2 2 Data The value No flag


Transfer is popped
from
stack

END

SENSE, VIT Page 11 of 20


Reg no: 19BEC0365 Fall 2019-20 ECE3003 - 𝜇C and its applications

Output: Registers containing the Result:


R0=00 R1=00 R2=00 R3=5 R4=45

Manual Calculation: None

Results and Observations


Print Screen of the Program and registers before execution:

Print Screen of the Program and registers after execution:

SENSE, VIT Page 12 of 20


Reg no: 19BEC0365 Fall 2019-20 ECE3003 - 𝜇C and its applications

Inferences:
1. All the data are popped out of the stack

2. We can view the operations through memory window

Result: The 8051 ALP to perform POP of 5 8BIT NUMBERS is executed using keil software and the
results are verified manually

Question 4:
Aim: To get values and load them to register and push them onto the stack.
Tools Required- Keil Software
Algorithm:
1. Decide the numbers to be loaded- 05 15 25 35 45
2. Assign the values to registers R0 to R4
3. Push each value into the stack
4. Pop each value back from the stacks
5. Check for execution on the memory window

Program:

SENSE, VIT Page 13 of 20


Reg no: 19BEC0365 Fall 2019-20 ECE3003 - 𝜇C and its applications

Label Mnemonics Operands addressing Machine Memory Type of Comments Flags


mode used cycle Byte Instruction getting
Required Required affected by
the
Instruction.

MOV R0 Immediate 1 2 Data The input No flag


Transfer is stored
to R0

MOV R1 Immediate 1 2 Data The input No flag


Transfer is stored
to R1

MOV R2 Immediate 1 2 Data The input No flag


Transfer is stored
to R2

MOV R3 Immediate 1 2 Data The input No flag


Transfer is stored
to R3

MOV R4 Immediate 1 2 Data The input No flag


Transfer is stored
to R4

PUSH Direct 2 2 Data The value No flag


Transfer is pushed
to stack

PUSH Direct 2 2 Data The value No flag


Transfer is pushed
to stack

PUSH Direct 2 2 Data The value No flag


Transfer is pushed
to stack

PUSH Direct 2 2 Data The value No flag


Transfer is pushed
to stack

PUSH Direct 2 2 Data The value No flag


Transfer is pushed
to stack

POP Direct 2 2 Data The value No flag


is popped
SENSE, VIT Page 14 of 20
Reg no: 19BEC0365 Fall 2019-20 ECE3003 - 𝜇C and its applications

Transfer from
stack

POP Direct 2 2 Data The value No flag


Transfer is popped
from
stack

POP Direct 2 2 Data The value No flag


Transfer is popped
from
stack

POP Direct 2 2 Data The value No flag


Transfer is popped
from
stack

POP Direct 2 2 Data The value No flag


Transfer is popped
from
stack

END

Output: Registers containing the Result:


R0=45 R1=35 R2=25 R3=15 R4=05

Manual Calculation: None

Results and Observations


Print Screen of the Program and registers before execution:

SENSE, VIT Page 15 of 20


Reg no: 19BEC0365 Fall 2019-20 ECE3003 - 𝜇C and its applications

Print Screen of the Program and registers after execution:

Inferences:
1. All the data are pushed into the stack and then popped from it

2. We can view the operations through memory window

SENSE, VIT Page 16 of 20


Reg no: 19BEC0365 Fall 2019-20 ECE3003 - 𝜇C and its applications
Result: The 8051 ALP to perform PUSH and POP of 5 8BIT NUMBERS is executed using keil
software and the results are verified manually

Question 5:
Aim: Write a program to add 10 bytes of BCD data and store the result in R2 and R3.
The bytes are stored in ROM space starting at 300H.
Tools Required- Keil Software
Algorithm:
1. Take 10 bytes of BCD Data and store in DB
2. Move data pointer to 300
3. Set a loop with 10 counts to:
a. Take the data from DB
b. Add the data to and store it to A
c. Increment the data pointer and register to read the next data value
4. On completion of 10 iterations, the control exits from the loop
5. Short jump (SJMP) is executed to make the control come out of the loop
6. The program then ends

Program:

Label Mnemonic Operands addressing Machine Memory Type of Comments Flags


-s mode used cycle Byte Instruction getting
Required Required affected by
the
Instruction.

ORG

MOV DPTR Immediate 2 3 Data Data No flag


Transfer Pointer is
moved to
desired
location

MOV R0 Immediate 1 2 Data The input No flag


Transfer is stored
to R0

LOOP CLR A 1 1 Logical Clear No flag

SENSE, VIT Page 17 of 20


Reg no: 19BEC0365 Fall 2019-20 ECE3003 - 𝜇C and its applications

register

MOVC A, DPTR Register 1 2 Data Move No flag


Transfer code byte
to
accumulat
or

ADD A, R2 Register 1 1 Arithme Add to C, AC, OV


-tic accumulat
or

DA A 1 1 Adjusts C
the 8 bit
value to
BCD
format
(Decimal
Adjust)

JNC Indexed 2 2 Boolean Jump on No flag


no carry

INC R3 Immediate 1 1 Arithme Incremen No flag


-tic t register

NEXT INC DPTR Immediate 2 2 Arithme Incremen No flag


-tic t DPTR

MOV R2, A Immediate 1 1 Data Move No flag


Transfer memory

DJNZ R0 Register 2 2 Program Decremen No flag


Branchi- t and
ng jump on
non-zero

HERE SJMP Indexed 2 2 Program Short No flag


Branchi- jump
ng

ORG

DB

END

SENSE, VIT Page 18 of 20


Reg no: 19BEC0365 Fall 2019-20 ECE3003 - 𝜇C and its applications

Output: Registers containing the Result:


R0=00 R1=00 R2=04 R3=04 A=04

Manual Calculation:
Hex 22 43 23 34 31 77 91 33 43 7
Dec 34 67 35 52 49 119 145 51 67 7
34+67+35+52+49+119+145+51+67+7 = 626
(626)10 = (272)16

Results and Observations


Print Screen of the Program and registers before execution:

Print Screen of the Program and registers after execution:

SENSE, VIT Page 19 of 20


Reg no: 19BEC0365 Fall 2019-20 ECE3003 - 𝜇C and its applications

Inferences:
1. The data are taken one by one from DB and are added

Result: The 8051 ALP to perform ADDITION of 10 BCD NUMBERS is executed using keil software
and the results are verified manually

SENSE, VIT Page 20 of 20

You might also like