Lab Report 05
Lab Report 05
SYSTEMS
(MTS - 311)
DE-44 Mechatronics
Syndicate – B
Lab Report # 5
WEEK # 05
Names of Members:
1. NC M. Hamza Idrees Reg. No: 412662
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:
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:
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
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:
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.