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

PBL Code Expl

Uploaded by

rzambre7
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

PBL Code Expl

Uploaded by

rzambre7
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Line 1: DELAY:

● This line doesn't contain an instruction but serves as a label. A label acts as a symbolic
reference point in your code. In this context, it marks the starting point of the delay
routine. When another part of your code needs to introduce a delay, it can "jump" or "call"
this label (DELAY) to execute the instructions within.

Line 2:

● MOV: This is a fundamental assembly instruction that performs a "move" operation. It's
used to transfer data between registers or between a register and a constant value.
● R5: This refers to register 5 within the processor's register file. Registers are like small,
fast memory locations within the CPU itself, used for holding data that the CPU is actively
working on.
● #255: The # symbol usually signifies an immediate value. This means we are directly
loading the decimal value 255 into register R5. This value essentially controls the duration
of the delay.

Line 3:

● Another label! This one marks the beginning of the outer loop in our delay routine.

Line 4:

● Similar to line 2, we're loading the immediate value 255 into register R6. This sets up the
counter for the inner loop.

Line 5:

● Yet another label marking the start of the innermost loop.

Line 6:

● DJNZ: This stands for "Decrement and Jump if Not Zero." It's a powerful instruction for
loop control.
● R6: We're operating on the value stored in register R6 (which was initialized to 255).
● Here's how it works:
1. Decrement: The DJNZ instruction first decreases the value in R6 by 1.
2. Check for Zero: It then checks if the value in R6 has become zero after the
decrement.
3. Jump (or not):
■ If R6 is not zero, the code jumps back to the label DELAY_LOOP2,
effectively repeating the loop.
■ If R6 has reached zero, the jump is skipped, and the execution continues
to the next line.
4.

Line 7:

● This line functions almost identically to line 6, but with these key differences:
○ It operates on R5 (the outer loop counter).
○ If R5 is not zero after decrementing, it jumps back to DELAY_LOOP1.

Line 8:

● The RET instruction stands for "return." In assembly, routines are often called using
instructions like CALL. The RET instruction signals the end of the DELAY routine and
returns execution to the instruction immediately following the original CALL instruction that
invoked this delay routine

You might also like