Search code examples
assembly8051

JL equivalent in 8051 assembly


I'm looking for JL (jump if less) equivalent in 8051 assembly. The closest solution I figured out was

CJNE A,#42,DUMMY
DUMMY: JC IS_LESS ; jump to IS_LESS if A<42

Is there any more elegant way? I mean without that DUMMY label. I'd like to perform something like CMP instruction. I could simply SUB, but I'd like just non-destructive test of the value.


Solution

  • After reading the manual properly, CJNE's syntax in this case is CJNE A,#data,rel, where rel is referenced as

    Signed (two’s complement) 8-bit offset byte. Used by SJMP and all conditional jumps. Range is -128 to +127 bytes relative to first byte of the following instruction.

    Therefore, "JL" instruction could be coded as

    CJNE A, #42, 0 ; 0 = do not jump
    JC IS_LESS     ; jump to IS_LESS if A<42