We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I have a assembly function declared in C as extern void *func(int *); and it is called from the C program as pstack=func(stack); where int *pstack; int *stack; //pointer to array In my assembly function, I understand that the argument is stored in R1-R3. What I need is to have the assembly function add in contents to the array passed into the function which is initially empty. The function will also return the address of the array which is filled. My doubt is: How do I have access to a location in the array and subsequently add in a value? I am new to assembly so please pardon my ignorance. Any assistance will be greatly appreciated. Thank you.
for ANY c and assebly case do the following: make a skeleton function in C and use the generated asembler (which is beatutifully commented) as a base for your assembler subroutine. Erik
How do I have access to a location in the array and subsequently add in a value? I am new to assembly Well, since you're doing this on an 8051, you're about to get a baptism by fire. Grab your 8051 architecture book, and study the programming model. The 8051 has a number of different address spaces (code, data, xdata, idata, pdata, to name them with the Keil C keywords) and you use different instructions as well as addressing modes to address some of them. Keil's "generic" pointers, the three-byte sort passed in R1-R3, contain a tag byte that tells you which memory space the address is for, and thus lets you know what to do with the other two bytes. If you happen to know that this function is only needed for xdata (for instance), it might make your task easier to specify the function as taking an xdata pointer, so that there is only one type of address to deal with. So, if R1 tells you that its an xdata reference, you'd put R2/R3 into the DPTR register and use MOVX to read or write the bytes. If R1 tells you that its a data reference, you might move R3 to R0 and use a MOV A,@R0 instruction. If you look in the XBANKING.A51 files, you can see Keil's code for loading/storing various locations, which will give you some idea of how to go about it. You can look at the assembly output from C code, but it will call these library routines to do the actual transfers. Out of curiousity, why not just write this function in C in the first place?