Sie sind auf Seite 1von 16

EXPERIMENT NO.

JUMP, LOOP, AND CALL INSTRUCTION


PUSH/POP OPERATION

OBJECTIVES
 To be able to compare the jump, loop, and call instructions use in 8051 (or in any
microcontroller).
 To determine the use of jump, loop, and call instructions.

PROCEDURE A: LOOP AND JUMP INSTRUCTION


A. LOOP INSTRUCTION
1. Make a new Project and .a51 file with a name expt2 and expt2aA.a51 respectively. (Just repeat
procedure A of experiment No.1 in creating a New Project and .a51 file).

2. The following program will clear the Accumulator (ACC) and add 3 to the accumulator ten times.
Encode the following commands:
MOV A, #0
MOV R2, #10
AGAIN: ADD A, #03
DJNZ R2, AGAIN
MOV R5, A
END

3. Rebuild (i.e. Rebuild All Target Files) and debug the program. Observe the value of r5 in the
registers.
4. Run the program and note the value of r5. Is the value evident in the program?

- The program looped 10 times showing that the value of r2 decreases until zero, and the value of
R5 is 1EH or 30H, making the results evident in this picture.

5. Return to the “main program proper.” And then change the value of #03 to #94 then rebuild (i.e.,
Rebuild All Target Files) and debug the program. Observe the value of r5 in the registers and
then run the program and note the value of r5. Is the value evident in the program?
- The process is almost the same in the previous step, but because of the changed value in the
syntax, making the program’s output evident, showing the loop repeated 10 times until r2
becomes zero, and portraying the value of R5 as ACH.

B: JUMP INSTRUCTION
Create another text file with the name expt2aB.a51 under the same project. The following
program compute the sum of 79H, F5H, and E2H and then store it in registers R0 (for the lower order
byte) and R5 (for the higher order byte), and finally, display to port P1 and P2 respectively.

1. Encode the following commands:


MOV A, #0
MOV R5, A
ADD A, #79H
JNC N_1
INC R5
N_1: ADD A, #0F5H
JNC N_2
INC R5
N_2: ADD A, #0E2H
JNC OVER
INC R5
MOV P1, R5
OVER: MOV R0, A
MOV P2, R0
END
2. Rebuild (i.e., Rebuild All Target Files), and debug the program. Observe the value of registers
r0 and r5. Display port1 and port2 and run the program. Note the value of r0, r5, port1, and
port2. Is the value evident in the program?

- The program is evident in this one, showing that the output of port 1 portraying the value of r5,
which is 2 due to the increment of the value twice. And the value of Port 2, which is 50H
obtained by adding the three values.

3. Return to the “main program proper” and then change the values to #94, #0FFH, and #0CAH
respectively then rebuild (i.e., Rebuild All Target Files) and debug the program. Observe the
value of the mentioned registers and port above. Write your observations.
- In this part, we have observed that the previous procedure and this one have the same output,
portraying both the lower and upper order byte in the two ports respectively

PROCEDURE B: CALL INSTRUCTION AND PUSH/POP OPERATION


A. CALL INSTRUCTION
Create another text file with the name expt2bA.a51 under the same project.
1. Encode the following commands:
ORG 0H
SJMP START
ORG 40H
START:
BACK: MOV A, #55H
MOV P1, A
LCALL DELAY
POP 0
POP 1
MOV A, #0AAH
MOV P1, A
LCALL DELAY
SJMP BACK
ORG 300H
DELAY:
MOV R5, #0FFH
AGAIN:
DJNZ R5, AGAIN
RET
END
2. Rebuild (i.e., Rebuild All Target Files) and debug the program. Analyze the content of stack
pointer before and after the execution. Run the program.

3. Stop the program and note the value of registers r0 and r1. The value of r0 and r1 refers to
the address pointed-out by “program counter (PC)” that was stored in the stack register.
Register r0 holds the higher-order byte and register r1 holds the lower-order byte of the
address. Select the disassembly and locate the address of POP 0. Note that the address
that will be saved (which is pointed out by the PC) is the address after the call operation. Is
this evident in the program? Why.
4. Replace ORG 40H by ORG 200 and then rebuild the program. What happen?

- In this method, the program failed to run, because of the error done by the ORG 200 syntax,
because the declared syntax is SJMP, which has a limited amount of bits required to run the
program, which is approximately 126 bits only.

5. Now replace SJMP by LJMP and then rebuild the program. What happen?
- The program has resumed to its normal state and it has been functional again due to the
changing of SJMP code into LJMP, which has the ability to access the latter part of the
disassembly area, making it store the data in the latter part.

6. Debug and run the program. After that, stop the program and select disassembly. Locate
again the address of POP 0. Is this evident in the program? Why.

- After replacing the SJMP into LJMP, the address location of POP 0 is now at 0CFH, which
shows that the higher order byte is the value of the r0 and the lower order byte is the value
obtained in r1, making the output evident in the program.
7. Return to the “main program proper” and move the instructions POP 0 and POP 1 after the
second LCALL DELAY before SJMP BACK and then rebuild, debug and run again the
program. Again, stop the program and select disassembly. Locate again the address of POP
0. Observe what happen.

- The POP operation had undergo LCALL DELAY twice in the program, making the location of
POP 0 at 00D6 where the r0 value is 00 making it the higher order byte, and the lower order
byte, r1, is D6.
8. Change all LCALL DELAY to LCALL REPEAT and then rebuild the program. What happen?

- The program failed to run, because LCALL REPEAT is undefined in the syntax.

9. Now change the label DELAY to REPEAT and then rebuild, debug and run again the
program. Record your result.
- The program output didn’t show the right output after the syntax was replaced.

B. CALL INSTRUCTION
Create another text file with the name expt2bB.a51 under the same project.
1. Encode the following commands:
ORG 0
BACK: MOV A, #55H
MOV P1, A
MOV R4, #99H
MOV R5, #67H
LCALL DELAY
MOV A, #0AAH
MOV P1, A
LCALL DELAY
SJMP BACK
ORG 300H
DELAY:
PUSH 4
PUSH 5
MOV R4, #0FFH
NEXT: MOV R5, #0FFH
AGAIN: DJNZ R5, AGAIN
DJNZ R4, NEXT
POP 0
POP 1
RET
END
2. Rebuild (i.e., Rebuild All Target Files) and debug the program. Analyze the content of
register r0, r1, r4, and r5 before and after the execution. Run and stop the program for
about three times and record your observation. What is the value of the designated
registers?

3. Change the value of #99H and #67H to #06H and #0C8H then rebuild, debug and run
again the program. Again, what is the value of the designated registers.
4. Is the POP and PUSH instruction evident in the program? Explain/show the operation of
POP and PUSH in the program by using stack frame.

- In the said operation, it is shown in the following procedure that the PUSH and POP operations
are visible in the disassembly, by means of pushing the values of R4 and R5, and portraying the
output in the r0 and r1, making the Last-In-First-Out principle a fact.
QUESTIONS

1. What is the use of MOV R2, #10 in the program of procedure A?

- Immediate value 10 was moved to Register R2.

2. What is the effect of changing #10 to #0F3H in the program of procedure A?

- It changed the number of times the R2 will decrement and the times the subroutine AGAIN
will be repeated.

3. What is the effect of changing the code address of CALL function in procedure B-a without
changing the label pointed out by CALL function?

- An error was encountered because the subroutine REPEAT was not yet defined in the
program.

4. What is the effect of replacing SJMP and LJMP when the origination of the main program was
changed to 200?

- The error encountered in the previous step was solved. The origin was already within range.

5. Is the POP and PUSH instruction evident in procedure B-b? Explain why.

- Yes, because the subroutine is expected to repeat 55 025 times and the program gave
us R0=67H and R1=99H since we used PUSH 4 and PUSH 5, then POP 0 and POP 1,
meaning we pushed the 99H of R4 and 67H of R5 to the stack register then popped 67H
to R0 and 99H to R1.
CONCLUSION:

- After doing the said experiment, we have observed the Jump, Loop, and Call principle,
which was taught in the lecture was evident in the said program. The Jump instruction here
in the program was used to either switch instructions from one to another before proceeding
in another instruction that needs to be done. Loop instruction is redirecting one process
back to the previous instruction, if the needed process is not obtained. Call instruction is like
literally calling an instruction that can be seen in the syntax before proceeding to the next
instruction in line with the syntax.

Das könnte Ihnen auch gefallen