You are on page 1of 5

EXPERIMENT NO.

2
JUMP, LOOP AND CALL INSTRUCTION
PUSH/POP OPERATION

OBJECTIVE:
 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., Rebuil 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?

5. Return to “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?

6. Again, return to “main program proper” and then change the value of #10 to #0F3H 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?
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, 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?

3. Return to “main program proper” and then change the value of #94 to #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 you observations.

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
SJMO 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 happened?

5. Now replace SJMP by LJMP and then rebuild the program. What happened?

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?

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 happened.

8. Change all LCALL DELAY to LCALL REPEAT and then rebuild the program. What happened?

9. Now change the label DELAY to REPEAT and then rebuild, debug and run again the program.
Record you result.
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.

QUESTIONS:
1. What is the use of MOV R2, #10 in the program of procedure A?
2. What is the effect of changing #10 to #0F3H in the program of procedure A?
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?
4. What is the effect of replacing SJMP by LJMP when the origination of the main program is
changed to 200?
5. Is the POP and PUSH instruction evident in procedure B-b? Explain why.

GROUP NO.________________________ DATE:_____________________

INSTRUCTOR INITIAL:_______________________

You might also like