Search code examples
assemblyembeddedmicrocontroller8051

8051: JMP instruction works in an unexpected way


I'm working with 89C51 in Keil uVision.

I've somehow acquired the habit of using

JMP label   ; goto label

According to the datasheet, JMP should be written as JMP @A+DPTR, and for what I'm using it, the SJMP, LJMP and AJMP should be used.

Nonetheless, the way I use it works just fine.

The question is, why? Is that some uVision's addition to the language?


Solution

  • It's an optimization that inserts the appropriate jump instruction so you don't have to determine which is required.

    From the Ax51 User's Guide:

    Generic jumps and calls are two instruction mnemonics that do not represent a specific opcode. JMP may assemble to SJMP, AJMP, LJMP or EJMP. CALL may assemble to ACALL, LCALL or ECALL. These generic mnemonics always evaluate to an instruction, not necessarily the shortest, that will reach the specified program address operand.

    If you desire a specific type of jump, you can always use the corresponding mnemonic.