Вы находитесь на странице: 1из 11

8-bit microcontrollers

Jump & Call instructions


A jump instruction can replace the contents of the program
counter with a new program address that causes program
execution to begin at code located at new address.
The difference in bytes of this new address from the
address in the program where jump or call is located is
called Range of jump or call.
They may have one of the three ranges
Relative range
05/03/16

+127d,-128d bytes from the


instructions following the jump/call
8 bit microcontrollers

CALL Instructions
ACALL: Absolute Call
It calls subroutines with a target address
within 2K bytes from the current program
counter (PC). 2 byte instruction.
LCALL: Long Call
To reach the target address in the 64K bytes
maximum ROM space of 8051, we must
use LCALL. 3 byte instruction
05/03/16

8 bit microcontrollers

Format of CALL instructions


ACALL abs addressACALL label
LCALL 16 bit address

05/03/16

LCALL 2050h

8 bit microcontrollers

JUMP Instructions
AJMP: Absolute Jump
It transfers program execution to the target
address unconditionally, within 2k bytes of
program memory. 2 byte instruction
LJMP: Long jump
It is used to jump unconditionally to any
address location within 64K bytes of
program memory. 3 byte instruction.
05/03/16

8 bit microcontrollers

SJMP: Short Jump


Used to jump unconditionally within -128 to
+127 bytes of the current program counter
(PC) value. 2 byte instruction.

05/03/16

8 bit microcontrollers

An absolute range

2K byte page

A long range

Any address

A short range

relative to PC
(-128 to +127)
(0000- FFFF) anywhere in the program
memory

Jumps.
Bit jumps:
All bit jumps either operate according to the status
of carry flag of PSW or status of any bit addressable
location..
All bit jumps are relative to the PC(-128 to +127)
05/03/16
8 bit microcontrollers

JC radd

2 Byte Instr.

JNC radd
JZ radd
JNZ radd

2 Byte Instr.
2 Byte Instr
2 Byte Instr

JB b, radd

3 Byte Instr.

JNB b, radd

3 Byte Instr.

JBC b, radd

3 Byte Instr.

jump relative if add bit is set and clear


the bit to 0.
radd: Relative Address within Program Code
05/03/16

8 bit microcontrollers

Byte jumps
CJNE dest. byte, source byte, addrs.

3 Byte Instr

Compare the contents of A with direct address if not equal


then jump to relative address
CJNE A, #n, radd

3 Byte Instr

CJNE Rn, #n, radd

3 Byte Instr

CJNE @Rp, #n, radd

3 Byte Instr

DJNZ Rn, radd

3 Byte Instr

The CJNE instruction affects the CY flag only.


Dest. < Source; CY=1
Dest. > Source; CY=0
05/03/16
8 bit microcontrollers

Unconditional jumps
JMP @A+DPTR

1 Byte Instr

AJMP sadd

2 Byte Instr

LJMP ladd

3 Byte Instr

SJMP radd

2 Byte Instr

05/03/16

8 bit microcontrollers

10

Calculation of short jump address


Again:
Next:

Over:

05/03/16

Org 0000h
Jz next
Inc r0
inc a
inc a
mov a,#34h
jnc over
clr a
mov r0,a
mov r1,a
mov r2,a
mov r3,a
mov r4,#45h
jnc again
end

8 bit microcontrollers

11

Вам также может понравиться