This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

What is this asm code doing??

Hi all

Can anyone tell what is this asm code doing?? what is the _?ix1000 doing??

MOV R3,#0FFH
MOV R2,#HIGH _?ix1000
MOV R1,#LOW _?ix1000
PUSH AR3
PUSH AR2
PUSH AR1
MOV R3,#00H
MOV R2,#HIGH count
MOV R1,#LOW count
MOV R0,AR1
MOV R4,AR2
MOV R5,AR3
POP AR1
POP AR2
POP AR3
MOV R6,#00H
MOV R7,#04H
LCALL ?C?COPY

Thanks a lot

  • What is this asm code doing??

    Did you write code you do not know what is doing?

    Trying to decipher uncommented code usually imples theft

    Erik

  • It is a call to memcpy().

    There are two 3-byte variables, one in R1,R2,R3 which is the address of _?ix1000 and one in R0,R4,R5 which is the address of count. The number of bytes to copy is in R6,R7 - just 4 bytes in this case.

    Whay all the pushing and popping? It looks totaly unnecessary and is presumably the way C51 chooses to do it.

    What is _?ix1000? Only Keil can help you although the preceeding underscore hints that this is a compiler generated label.

    You should be able to look at the opcodes and determine the actual values of the pointers. Refer to the manual for a detailed description of the 3-byte pointers - one byte indicates which type of memory and the other two bytes indicate a 16-bit address.

    You can use your map file to determine what it is that is being copied.

  • Thanks all

    Sorry, I just found this code in my liker map after I complier my source code ,I just to be inquisitive about why kiel c will add
    these code into my code ,I see the source code just like this

    unsigned char count[4]={0};

    I think it is inefficiency code !! So I just study and ask ,I am not a thief,ok!!

    Thanks a lot

  • unsigned char count[4]={0};
    
    Yes, that would account for it. This is one of the ways that memcpy() can get into a project even when you don't use it explicitly. This can be a bit of a problem because memcpy() is designed for speed and is actually quite large.

    It would be helpful for many projects if there was a compiler option for slow but compact versions of the string.h functions.

    Also, calls to memcpy() can be very inefficient - as you have noted above. It would be nice if C51 could generate in-line code to copy small amounts of memory to and from fixed addresses. This really ought to be easy as, for example, an assignment of a long does not invoke memcpy().

    memcpy() can get called to copy a very small structures. If you are using bitfields, a structure can be as small as a single byte!

    Keil: how about some improvement?

    (It is possible I am out-of-date on this, it has been a while since I last looked.)