0% found this document useful (0 votes)
12 views

Lab Report 05

Uploaded by

Shaheer Ahmed
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 views

Lab Report 05

Uploaded by

Shaheer Ahmed
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/ 4

MICROCONTROLLER & EMBEDDED

SYSTEMS
(MTS - 311)
DE-44 Mechatronics
Syndicate – B

Lab Report # 5

WEEK # 05

Names of Members:
1. NC M. Hamza Idrees Reg. No: 412662

2. GC Daud Ahmed Reg. No: 432008

Submitted to: LD Sir Qasim


Dated: Oct 10, 2024

1
Objectives:
This week's lab aims to:
 To get acquainted with loops in assembly language.
 Learning loops by calling and using instructions.
 Using nested loops.

Introduction:
Looping in the 8051 microcontroller involves repeating a set of instructions a specific number of times.
This is done using loop-control instructions provided by the 8051 architectures:

1. DJNZ (Decrement and Jump if Not Zero):


This instruction is used to decrease the value of a register and jump to a specified address if the
result is not zero.
DJNZ Rn, label; Decrements Rn, jumps to label if Rn is not zero
DJNZ direct, label

2. CJNE (Compare and Jump if Not Equal):


This instruction compares two values and jumps to a specified address if they are not equal.
CJNE dest-byte, src-byte, rel-address.
Compares dest-byte and src-byte, jumps if they are not equal

3. Nested Loops:
Nested loops are created when a loop is placed inside another loop, allowing for hierarchical
repetition of instructions.

2
Lab Tasks:
Task 01: Transfer the block of data from 20h to 30h to location 40h to 50h after adding 2 to each
number using loops:

Figure 1: Task 01 Code and Output

This code transfers data from memory locations 20h to 30h to locations 40h to 50h. It uses register
`R0` to point to the source and `R1` to the destination, moving each value in a loop until all data is
copied, though it currently lacks the addition of 2 to each number as specified.

Task 02: Continuously scan port P0. If data is other, then 0FFh multiply it with 10 and send it to port
P1 and P2

Figure 2: Task 02 Code and Output

This code continuously checks if `P0` is equal to `0FFh`. If not, it multiplies the value of `P0` by 10
and stores the result in registers `P1` and `P2`, then repeats the process.

3
Task 03: Write a program to implement following C code in assembly:

Figure 3: Task 03 Code and Output

This code performs a nested loop where `R0` runs 39 iterations, and in each iteration, `R1` runs 200
iterations. In each inner loop, the accumulator `A` is incremented by 2, repeating the process until both
loops finish.

Conclusion:
In conclusion, loops are essential in the 8051 microcontrollers for repeating instructions and can be
nested for more complex structures. The 'DJNZ' instruction is commonly used for loop control. Look-
up tables, storing predefined values in program memory, allow quick data retrieval using an index or
key. Utilizing loops and look-up tables enhances 8051's efficiency and adaptability, enabling a wide
range of applications.

You might also like