Move the data indirectly into pointed-at C variable, as per the assembler 'MOV ability to access data either directly, x = y, or indirectly, x = *y_ptr, is extremely useful.In English this C statement means: "take the 'address of' c_variable and put it into the reserved RAM, i.e, the pointer" In this case the pointer's RAM corresponds to R0 and the '&' equates loosely to the assembler '#'. Load reserved RAM with address to be accessed, equivalent to 'MOV R0,#40'.In practice the compiler attaches a symbolic name to a RAM location, just as with a normal variable. /* 3 - Put data '0xff' indirectly into c variable via*/./* 2 - Load pointer variable with address to be accessed*/./* 1 - Define a variable which will hold an address */.Use the appropriate indirect addressing instruction to access data held at chosen address.įortunately in C the same procedure is necessary, although the indirect register must be explicitly defined, whereas in assembler the register exists in hardware. Place address to be indirectly addressed in a register.Ģ. In all cases in the assembler example two distinct operations are required:ġ. Note the asterisk prefix, indicating that the data held in this variable is an address rather than a piece of data that might be used in a calculation etc. The register holding the address to be indirectly accessed in the assembler examples is a normal C type, except that its purpose is to hold an address rather than a variable or constant data value. The C equivalent of the indirect instruction is the pointer. In each case the data is held in a memory location indicated by the value in registers to the right of the Pointers In C MOV DPTR,#0040 Put off-chip address to be indirectly.
MOVX Put off-chip address to be indirectly.MOV R0,#40 Put off-chip address to be indirectly.MOV R0,#40 Put on-chip address to be indirectly.In the 8051 this is achieved by the following instructions The use and, more appropriately, the abuse of this language feature is largely why C is condemned by some as dangerous! Pointers In Assemblerįor an assembler programmer the C pointer equates closely to indirect addressing. One of C's greatest strengths can also be its greatest weakness - the pointer. Using Pointers, Arrays, Structures and Unions in 8051 C Compilersīy Olaf Pfieffer, based on the C51 Primer by Mike Beach, Hitex UKĪlthough both the Keil and Raisonance 8051 C compiler systems allow you to use pointers, arrays, structures and unions as in any PC-based C dialect, there are several important extensions allowing to generate more efficient code.