Hi, I want to translate a C code into 8051 assembly language, I have some few questions :
what is the equivalenet for a = b in assembly, if a and b are integers
also for y = f(x), f() is a fucntion that returns an integer
Thank you !
There are several possible ways to code a = b, depending on where a and b are located within the data memory space of the processor. In the best case, where both a and b reside in the first 128 bytes of internal memory it would be:
MOV al,bl ; where al and bl are the symbolic address of the respective locations in internal data memory where the low bytes are located
MOV ah,bh ; where ah and bh are the symbolic addresses of the respective bytes in internal data memory where the high bytes are located.
This avoids the question of how multibyte quantities are stored in 8051 memory. It could be big-endian or little-endian
In the more complicated case we have to get the DPTR register involved and move the bytes, one at a time using the MOVX instruction along with the ACC or Accumulator register.
How to pass arguments and return values from a function can be done in a variety of ways. The most efficient way IMHO is to use the registers R2, R3, R4, and R5 for arguments. R6 and R7 are for return values. That avoids using the nearly useless stack pointer.
I'm just wondering if you are aware that there are programs called "C compilers" that will automatically translate I proper C code into assembly language code.