0% found this document useful (0 votes)
12 views19 pages

21bce3724 Da1

Microprocessor and Controllers

Uploaded by

Dharansh Neema
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views19 pages

21bce3724 Da1

Microprocessor and Controllers

Uploaded by

Dharansh Neema
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Name: Dharansh Neema

Reg No.: 21BCE3724

Course Title: Microprocessors and


Microcontrollers Lab

Lab Slot: L1+L2


AIM:
WAP to perform basic arithmetic operation using Keil micro vision

Tools Required: Keil Uvision 5.


Algorithm
1. Addition:
o Load 37H into A.
o Load 24H into B.
o Add A and B, store the result in 40H.
2. Subtraction:
o Load 37H into A.
o Load 24H into B.
o Subtract B from A, store the result in 41H.
3. Multiplication:
o Load 37H into A.
o Load 24H into B.
o Multiply A and B, store the result in 42H (lower byte) and 43H (upper byte).
4. Division:
o Load 37H into A.
o Load 24H into B.
o Divide A by B, store the quotient in 44H and the remainder in 45H.

Code:
MOV A,#37H

MOV B,#24H

ADD A,B

MOV 40H,A

MOV A,#37H

MOV B,#24H

SUBB A,B

MOV 41H,A

MOV A,#37H

MOV B,#24H

MUL AB

MOV 42H,A
MOV 43H,B

MOV A,#37H

MOV B,#24H

DIV AB

MOV 44H,A

MOV 45H,B

END

Output:
AIM:
Write and assemble a program to add the following data and then use the
simulator to examine the PSW flags. 29H, 32H, 56H, 78H, 5FH.

Tools Required: Keil Uvision 5.


Algorithm:
1. Initialize Program:

o Set the program's origin at 0000H.

2. Load Values and Perform Addition:

o Load 29H into the accumulator A.

o Add 32H to A.

o Add 56H to A.

o Add 78H to A.

o Add 5FH to A.

3. Store the Result:

o Store the final value of A into memory location 40H.

4. End Program:

o Enter an infinite loop to halt the program and allow examination of the PSW flags.
Code:
ORG 0000H

MOV A, #29H

ADD A, #32H

ADD A, #56H

ADD A, #78H

ADD A, #5FH

MOV 40H, A

SJMP $

END

Output
Verification:
AIM:
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.

Tools Required: Keil Uvision 5.


Algorithm:
Initialize Registers:

• Load R0 with 25H.

• Load R1 with 35H.

• Load R2 with 45H.

• Load R3 with 55H.

• Load R4 with 65H.

Push Register Values to Stack:

• Push the value of R0 (25H) onto the stack.

• Push the value of R1 (35H) onto the stack.

• Push the value of R2 (45H) onto the stack.

• Push the value of R3 (55H) onto the stack.

• Push the value of R4 (65H) onto the stack.

Code:
ORG 0000H

MOV R0,#25H

MOV R1,#35H

MOV R2,#45H

MOV R3,#55H

MOV R4,#65H

PUSH 0

PUSH 1

PUSH 2

PUSH 3
PUSH 4

END

Output:

AIM:

Write an 8051 assemble language program to:

(a) Set SP = 0B,

(b) Put a different value in each of RAM locations 0D, 0C, 0B, 0A, 09 and 08

(c) POP each stack location into registers R0 - R4 of Bank 1.

Tools Required: Keil Uvision 5.


Algorithm:
Initialize the stack pointer: Set SP to 0DH.

Push values onto the stack:

• Push 16H onto the stack.

• Push 14H onto the stack.

• Push 13H onto the stack.

• Push 12H onto the stack.

• Push 11H onto the stack.

• Push 10H onto the stack.

Pop values off the stack:


• Pop the top value from the stack and store it in memory location 0.

• Pop the top value from the stack and store it in memory location 1.

• Pop the top value from the stack and store it in memory location 2.

• Pop the top value from the stack and store it in memory location 3.

• Pop the top value from the stack and store it in memory location 4.

Code:
ORG 0000H

MOV SP,#0DH

MOV 0DH, #10H

MOV 0CH, #11H

MOV 0BH, #12H

MOV 0AH, #13H

MOV 09H,#14H

MOV 08,#16H

POP 0

POP 1

POP 2

POP 3

POP 4

END
OUTPUT:

AIM:
Write a program to transfer a string of data from code space starting at address 300H to RAM
locations starting at 30H. The data is as shown below:

0200H: DB "Dharansh Neema"

Algorithm:
Initialize:

• Set accumulator A to 00H.

• Set Data Pointer DPTR to the address 200H where the string is stored.

• Set register R1 to 0EH (loop counter).

• Set register R0 to 40H (starting address in RAM for data storage).

Loop Through String:

• Clear accumulator A.

• Read a byte of data from the code space (address pointed by DPTR), using MOVC, and store
it in A.

• Write the value of A to the RAM location pointed to by R0.

• Increment DPTR to point to the next byte in the string.

• Increment R0 to point to the next RAM location.


• Decrement loop counter R1 and repeat the loop until R1 reaches zero.

Code:
ORG 0000H

MOV A,#00H

MOV DPTR,#200H

MOV R1,#0EH

MOV R0,#40H

LOOP:CLR A

MOVC A,@A+DPTR

MOV @R0,A

INC DPTR

INC R0

DJNZ R1,LOOP

HERE:SJMP HERE

ORG 200H

DB "Dharansh Neema"

END
OUTPUT:
Verification:
AIM:
Write a program to add 10 bytes of data and store the result in registers R2 and R3. The bytes are
stored in the ROM space starting at 200H. The data would look as follows: MYDATA: DB 92, 34, 84,
129, Pick your own data. Notice that you must first bring the data from ROM space into the CPU's
RAM, and then add them together. Use a simulator to single-step the program and examine the data.

Algorithm:
Initialize:

• Set Data Pointer DPTR to 200H (start of the data array).

• Load R0 with 0AH (loop counter for 10 iterations).

Loop through Data:

• Clear accumulator A.

• Load data from the address pointed to by DPTR into A using MOVC.

• Add the value in R2 to A.

• If there is no carry (JNC), skip the next instruction.

• If there was a carry, increment R3.

• Increment DPTR to point to the next data byte.

• Update R2 with the result in A.

• Decrement R0 and repeat the loop until it reaches zero.

• Data will be stored at 200H(272 is the answer)

Code:
ORG 000H

MOV DPTR, #200H

MOV R0, #0AH

LOOP: CLR A

MOVC A,@A+DPTR

ADD A, R2

JNC NEXT

INC R3

NEXT: INC DPTR


MOV R2, A

DJNZ R0, LOOP

HERE: SJMP HERE

ORG 200H

DB 22H,43H,23H,34H,31H,77H,91H,33H,43H,7H END

Output:
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. The data would look as follows: MYDATA: DB 92H, 34H, 84H, 29H ,... ;
pick your own data. Notice that you must first bring the data from ROM space into the CPU's RAM,
and then add them together. Use a simulator to single-step the program and examine the data.

Algorithm:
Initialize:

• Set Data Pointer DPTR to 300H (starting address of the data array).

• Load R0 with 10 (loop counter for 16 iterations).

Loop Through Data Array:

• CLR A: Clear the accumulator A.

• MOVC A, @A+DPTR: Load the byte of data from the address pointed to by DPTR into A.

• ADD A, R2: Add the value in R2 to A.

• DA A: Adjust A for decimal arithmetic (Decimal Adjust for Addition).

• JNC NEXT: If no carry, skip the next instruction.

• INC R3: If carry was generated, increment R3.

• NEXT: Label to continue the program.

• INC DPTR: Increment DPTR to point to the next byte in the data array.

• MOV R2, A: Update R2 with the result in A.

• DJNZ R0, LOOP: Decrement R0 and repeat the loop until it reaches zero.

Data Storage:

• The data array is stored in code space starting at address 300H.


Code:
ORG 000H

MOV DPTR, #300H

MOV R0, #10

LOOP: CLR A

MOVC A,@A+DPTR

ADD A, R2

DA A

JNC NEXT

INC R3

NEXT: INC DPTR

MOV R2, A

DJNZ R0, LOOP

HERE: SJMP HERE

ORG 300H

DB 22H,43H,23H,34H,31H,18H,26H,13H,48H,10H

END
Output:
Verification:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy