converting from C to 8051 Assembly Question

Discussion in 'Programmer's Corner' started by, Mar 27, 2013.


    Thread Starter New Member

    Dec 10, 2012
    Dear all;
    I tried to convert C code of an encryption algorithm called TEA to 8051 assembly code using Keil assembler.
    I found some string code line like the one bellow .
    Code ( (Unknown Language)):
    1. LCALL    ?C?LLDOPTR
    the assembler called external function form C language.
    Is this instruction correct or should I look what is this function do then convert the C function idea to 8051 assembly?

    here is another example
    the C code is
    Code ( (Unknown Language)):
    1. for (i=0; i < 32; i++)
    the assembly is
    Code ( (Unknown Language)):
    1. CLR      A
    2.     MOV      i?045+03H,A
    3.     MOV      i?045+02H,A
    4.     MOV      i?045+01H,A
    5.     MOV      i?045,A
    7. tea_encryption_32round:
    8.     CLR      A
    9.     MOV      R7,#020H    ; 020h = 32 d
    10.     MOV      R6,A
    11.     MOV      R5,A
    12.     MOV      R4,A
    13.     MOV      R3,i?045+03H
    14.     MOV      R2,i?045+02H
    15.     MOV      R1,i?045+01H
    16.     MOV      R0,i?045
    17.     CLR      C
    18.     LCALL    ?C?ULCMP
    19.     JC       $ + 5H
    20.     LJMP     ?C0002
  2. Ian Rogers


    Dec 12, 2012
    Its difficult to do what you want because external functions are not always easy to see

    ?C?ULCMP is Unsigned Long compare i < 32.

    ?C?LLOPTR seems to be a data pointer...

    ?ixxx is initialised data variable address.
    ?C seems to be code address.

    Thread Starter New Member

    Dec 10, 2012
    Thank you Ian Rogers for your response.
    What if I use this C external function in my 8051 assembly code as I got it from the assembler. Does this Function will work correctly?

    By the way the code below has a meaning
    Code ( (Unknown Language)):
    1. ?C?LLDOPTR
    the meaning is
    L : indicates a long that is passed in R4/R5/R6/R7.
    LD : indicates a read (load) operation.
    OPTR : represents a 3-byte pointer plus an offset in R1/R2/R3 + DPTR.