11
8-bit 8-bit microcontrollers microcontrollers

05 Branching Instructions

  • Upload
    neeraj

  • View
    216

  • Download
    0

Embed Size (px)

DESCRIPTION

microcontroller

Citation preview

Page 1: 05 Branching Instructions

8-bit microcontrollers8-bit microcontrollers

Page 2: 05 Branching Instructions

04/21/23 8 bit microcontrollers 2

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 +127d,-128d bytes from the instructions following the jump/call

Page 3: 05 Branching Instructions

04/21/23 8 bit microcontrollers 3

CALL Instructions

ACALL: Absolute CallIt calls subroutines with a target address

within 2K bytes from the current program counter (PC). 2 byte instruction.

LCALL: Long CallTo reach the target address in the 64K bytes

maximum ROM space of 8051, we must use LCALL. 3 byte instruction

Page 4: 05 Branching Instructions

04/21/23 8 bit microcontrollers 4

Format of CALL instructions

ACALL abs address ACALL label

LCALL 16 bit address LCALL 2050h

Page 5: 05 Branching Instructions

04/21/23 8 bit microcontrollers 5

JUMP Instructions

AJMP: Absolute JumpIt transfers program execution to the target

address unconditionally, within 2k bytes of program memory. 2 byte instruction

LJMP: Long jumpIt is used to jump unconditionally to any

address location within 64K bytes of program memory. 3 byte instruction.

Page 6: 05 Branching Instructions

04/21/23 8 bit microcontrollers 6

SJMP: Short Jump

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

Page 7: 05 Branching Instructions

04/21/23 8 bit microcontrollers 7

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)

Page 8: 05 Branching Instructions

04/21/23 8 bit microcontrollers 8

JC radd 2 Byte Instr.

JNC radd 2 Byte Instr.JZ radd 2 Byte InstrJNZ radd 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

Page 9: 05 Branching Instructions

04/21/23 8 bit microcontrollers 9

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

Page 10: 05 Branching Instructions

04/21/23 8 bit microcontrollers 10

Unconditional jumps…

JMP @A+DPTR 1 Byte Instr

AJMP sadd 2 Byte Instr

LJMP ladd 3 Byte Instr

SJMP radd 2 Byte Instr

Page 11: 05 Branching Instructions

04/21/23 8 bit microcontrollers 11

Calculation of short jump addressOrg 0000hJz nextInc r0

Again: inc a inc a

Next: mov a,#34hjnc overclr amov r0,amov r1,amov r2,amov r3,a

Over: mov r4,#45hjnc againend