Task 1: School of Electronics Engineering Vit, Vellore
Task 1: School of Electronics Engineering Vit, Vellore
Reg.No
Student Name
L51+L52
Course Code MAME502P Slot & Semester
FALL ~ 2023-24
Date of
Date of Exp. 19/08/2023 01/09/2023
Submission
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: . 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.
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.
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.
EXPERIMENT 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: Five max 8BIT NUMBERS (FF ,FF,FF,FF,FF)
Aim:
To write an 8051 ALP to perform addition of the following data and then use the simulator to
examine the CY flag Tools Required. [ DATA: 02, 03, EA, 00, 06]
Tools Required:
Keil version5 Software.
Algorithm:
1. Initialize registers A and B with the value 02 and 3A.
2. Add the contents of A and B; it is stored in accumulator (A).
3. Check the carry flag (JNC) after the addition. If no carry is occurred, go to Label1;
otherwise Increment the value in register R0.
4. Label 1: Move the value of register A to B.
5. Initialize registers A with the value EA.
6. Add the contents of A and B; it is stored in accumulator (A).
SENSE, Page 2 of
2
Reg no: 23MEA0006 Fall 2023-24 MAME502L Microcontrollers
for
Vehicular Systems
7. Check the carry flag (JNC) after the addition. If no carry is occurred, go to Label 2;
otherwise increment the value in register R0.
8. Label 2: Move the value of register A to B.
9. Initialize registers A with the value 00.
10. Add the contents of A and B; it is stored in accumulator (A).
11. Check the carry flag (JNC) after the addition. If no carry is occurred, go to Label 3;
otherwise increment the value in register R0.
12. Label 3: Move the value of register A to B.
13. Initialize registers A with the value 06.
14. Add the contents of A and B; it is stored in accumulator (A).
15. Check the carry flag (JNC) after the addition. If no carry is occurred, go to Label 4;
otherwise increment the value in register R0.
16. End of program.
Program:
SENSE, Page 3 of
2
Reg no: 23MEA0006 Fall 2023-24 MAME502L Microcontrollers
for
Vehicular Systems
Instruction Carry
SENSE, Page 4 of
2
Reg no: 23MEA0006 Fall 2023-24 MAME502L Microcontrollers
for
Vehicular Systems
L4 END
Output:
Registers containing the Result:
r0 = 01 sp = 0x07
A = 2C
B = 26
SENSE, Page 5 of
2
Reg no: 23MEA0006 Fall 2023-24 MAME502L Microcontrollers
for
Vehicular Systems
Manual Calculation:
SENSE, Page 6 of
2
Reg no: 23MEA0006 Fall 2023-24 MAME502L Microcontrollers
for
Vehicular Systems
Inferences:
1. If there is a carry between D3 and D4 registers then Auxilary carry Flag is 1 [AC=1].
2. If there is a carry beyond D7 register then Carry Flag is 1 [CY = 1].
3. If there are odd no’s of 1 in register then Parity Flag is 1.
Result:
The 8051 ALP to perform addition of given data of 5 8BIT NUMBERS is executed using Keil
software and the results are verified manually.
EXPERIMENT 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.
Aim:
To write an 8051 ALP to perform register to stack pointer using Keil software and to verify the
result manually.
Tools Required
Keil version5 Software.
Algorithm:
SENSE, Page 7 of
2
Reg no: 23MEA0006 Fall 2023-24 MAME502L Microcontrollers
for
Vehicular Systems
ORG 000H
SENSE, Page 8 of
2
Reg no: 23MEA0006 Fall 2023-24 MAME502L Microcontrollers
for
Vehicular Systems
r1 = 35
r2 = 45
SENSE, Page 9 of
2
Reg no: 23MEA0006 Fall 2023-24 MAME502L Microcontrollers
for
Vehicular Systems
END
Output :
Registers containing the Result:
r0 = 25 sp = 0x0c
r1 = 35
r2 = 45
r3 = 55
r4 = 65
Manual Calculation:
SENSE, Page 10
2
Reg no: 23MEA0006 Fall 2023-24 MAME502L Microcontrollers
for
Vehicular Systems
Inferences:
1. The PUSH instruction is commonly used in microcontrollers to push data onto the stack.
2. The stack is a region of memory used to store data temporarily during program execution, typically to
save the context of a subroutine or function.
3. The Stack Pointer (SP) is decremented to point to the next available memory location on the stack.
SENSE, Page 11
2
Reg no: 23MEA0006 Fall 2023-24 MAME502L Microcontrollers
for
Vehicular Systems
Result:
The 8051 ALP to perform register to stack pointer using Keil software the results are verified manually.
EXPERIMENT 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.
Aim:
To write an 8051 ALP to load a different value in each of RAM locations and POP each stack
location into registers R0 - R4 using Keil software and to verify the result manually.
Tools Required
Keil version5 Software.
Algorithm:
1. Set the origin address of the program to 0000H.
2. Move the immediate value 0DH (13 in decimal) into the Stack Pointer (SP) register, potentially
setting up the stack's initial position.
3. Move the immediate value 10H (16 in decimal) into memory address 08H.
4. Move the immediate value 11H (17 in decimal) into memory address 09H.
5. Move the immediate value 12H (18 in decimal) into memory address 0AH.
6. Move the immediate value 13H (19 in decimal) into memory address 0BH.
7. Move the immediate value 14H (20 in decimal) into memory address 0CH.
8. Move the immediate value 15H (21 in decimal) into memory address 0DH.
9. Pop the top value from the stack into register 0.
10. Pop the next value from the stack into register 1.
11. Pop the following value from the stack into register 2.
12. Pop the subsequent value from the stack into register 3.
13. Pop the succeeding value from the stack into register 4.
14. Pop the last value from the stack into register 5.
15. End the program.
SENSE, Page 12
2
Reg no: 23MEA0006 Fall 2023-24 MAME502L Microcontrollers
for
Vehicular Systems
Program:
ORG 000H
sp = 0x0d
MOV SP, #0DH Immediate Data Transfer SP = 0DH
addressing Instruction Registers are
mode 0
sp = 0x0d
MOV 08H, #10H Immediate Data Transfer 08H<-10H
addressing Instruction Registers are
mode 0
sp = 0x0d
MOV 09H, #11H Immediate Data Transfer 09H<-11H
addressing Instruction Registers are
mode 0
sp = 0x0d
MOV 0AH, #12H Immediate Data Transfer 0AH<-12H
addressing Instruction Registers are
mode 0
sp = 0x0d
MOV 0BH, #13H Immediate Data Transfer 0BH<-13H
addressing Instruction Registers are
mode 0
sp = 0x0d
MOV 0CH, #14H Immediate Data Transfer 0CH<-14H
addressing Instruction Registers are
mode 0
sp = 0x0d
MOV 0DH, #15H Immediate Data Transfer 0DH<-15H
addressing Instruction Registers are
mode 0
SENSE, Page 13
2
Reg no: 23MEA0006 Fall 2023-24 MAME502L Microcontrollers
for
Vehicular Systems
END
Output:
Registers containing the Result:
r0 = 15 sp = 0x07
r1 = 14
r2 = 13
r3 = 12
SENSE, Page 14
2
Reg no: 23MEA0006 Fall 2023-24 MAME502L Microcontrollers
for
Vehicular Systems
r4 = 11
r5 = 10
Manual Calculation:
SENSE, Page 15
2
Reg no: 23MEA0006 Fall 2023-24 MAME502L Microcontrollers
for
Vehicular Systems
Inferences:
1. The "POP" instruction is used to retrieve data from the top of the stack.
2. The POP instruction operates by first moving the data at the current stack pointer location to the
destination register or memory location and then incrementing the stack pointer to point to the next
available location.
Result:
The 8051 ALP to load a different value in each of RAM locations and POP each stack location
into registers R0 - R4 using keil software and the results are verified manually
EXPERIMENT 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.
Aim:
To write an 8051 ALP load values into each of registers R0 - R4 and then push each of these
registers onto the stack and pop them back using keil software and to verify the result manually.
Tools Required
Keil version5 Software.
SENSE, Page 16
2
Reg no: 23MEA0006 Fall 2023-24 MAME502L Microcontrollers
for
Vehicular Systems
Algorithm:
1. Set the origin address of the program to 0000H.
2. Load the immediate value 25H into register R0.
3. Load the immediate value 35H into register R1.
4. Load the immediate value 45H into register R2.
5. Load the immediate value 55H into register R3.
6. Load the immediate value 65H into register R4.
7. Push the value in register 0 onto the stack.
8. Push the value in register 1 onto the stack.
9. Push the value in register 2 onto the stack.
10. Push the value in register 3 onto the stack.
11. Push the value in register 4 onto the stack.
12. Pop the value from the top of the stack into register 0.
13. Pop the value from the top of the stack into register 1.
14. Pop the value from the top of the stack into register 2.
15. Pop the value from the top of the stack into register 3.
16. Pop the value from the top of the stack into register 4.
17. End the program.
Program:
ORG 000H
SENSE, Page 17
2
Reg no: 23MEA0006 Fall 2023-24 MAME502L Microcontrollers
for
Vehicular Systems
mode Instruction
SENSE, Page 18
2
Reg no: 23MEA0006 Fall 2023-24 MAME502L Microcontrollers
for
Vehicular Systems
END
Output:
Registers containing the Result:
R0 = 65H sp = 0x07
R1 = 55H
R2 = 45H
R3 = 35H
R4 = 25H
Manual Calculation:
SENSE, Page 19
2
Reg no: 23MEA0006 Fall 2023-24 MAME502L Microcontrollers
for
Vehicular Systems
SENSE, Page 20
2
Reg no: 23MEA0006 Fall 2023-24 MAME502L Microcontrollers
for
Vehicular Systems
Inferences:
1. This program serves as an example of stack manipulation in assembly programming.
SENSE, Page 21
2
Reg no: 23MEA0006 Fall 2023-24 MAME502L Microcontrollers
for
Vehicular Systems
2. The PUSH instruction pushes the value of register onto the stack, and the POP instructions pops the
values from the stack back into registers.
3. The stack pointer is decremented to allocate space for the new data that will be pushed onto the
stack, this effectively moves the stack pointer downward in memory during push operation.
4. The data at the memory location pointed by the stack pointer is retrieved and loaded into a register
or memory location, the stack pointer is incremented to release the memory space that was previously
occupied by the data.
Result:
The 8051 ALP load values into each of registers R0 - R4 and then push each of these registers
onto the stack and pop them back using keil software and the results are verified manually
EXPERIMENT 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.
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.
Aim:
To write an 8051 ALP to perform 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. using keil software and to verify the result
manually.
Tools required:
Keil version 5 software.
Algorithm:
1. Set the origin address of the program to 000H.
2. Load the data pointer (DPTR) with the memory address 300H.
3. Load the immediate value 10H into register R0.
4. Start a loop labelled "LOOP".
- Clear the accumulator (A) register.
- Move a byte of data from the address pointed to by (A + DPTR) to the accumulator using
the MOVC instruction.
SENSE, Page 22
2
Reg no: 23MEA0006 Fall 2023-24 MAME502L Microcontrollers
for
Vehicular Systems
Program:
ORG 000H
SENSE, Page 23
2
Reg no: 23MEA0006 Fall 2023-24 MAME502L Microcontrollers
for
Vehicular Systems
DA A Arithmetic
Instruction
SENSE, Page 24
2
Reg no: 23MEA0006 Fall 2023-24 MAME502L Microcontrollers
for
Vehicular Systems
HERE
ORG 300H
22H,
DB
43H,
23H,
34H,
31H,
77H,
91H,
33H,
43H,
07H
END
Output: R2= 04
R3= 04
A= 04
Sp= 07
Dptr= 0x0310
Manual Calculation:
SENSE, Page 25
2
Reg no: 23MEA0006 Fall 2023-24 MAME502L Microcontrollers
for
Vehicular Systems
SENSE, Page 26
2
Reg no: 23MEA0006 Fall 2023-24 MAME502L Microcontrollers
for
Vehicular Systems
SENSE, Page 27
2
Reg no: 23MEA0006 Fall 2023-24 MAME502L Microcontrollers
for
Vehicular Systems
Inferences:
1. BCD is a way of representing decimal digits in binary form, where each decimal digit is
encoded using four binary bits.
2. To get result in BCD addition, we use DA A instruction, if lower nibble is greater than 9 or
AC=1 then add #06H(0110) to the lower nibble.
3. If higher nibble is greater than 9 or CY=1 then add #06H(0110) to the lower nibble.
Result:
The 8051 ALP to perform 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. is executed using keil software and the results are verified
manually.
SENSE, Page 28
2