[no subject]
http://www.horseheavenmustang.com/find11.html___ xorg@lists.freedesktop.org: X.Org support Archives: http://lists.freedesktop.org/archives/xorg Info: http://lists.freedesktop.org/mailman/listinfo/xorg Your subscription address: arch...@mail-archive.com
[no subject]
http://suf2004.atwebpages.com/find11.html___ xorg@lists.freedesktop.org: X.Org support Archives: http://lists.freedesktop.org/archives/xorg Info: http://lists.freedesktop.org/mailman/listinfo/xorg Your subscription address: arch...@mail-archive.com
[no subject]
http://studioartax.com/find11.html___ xorg@lists.freedesktop.org: X.Org support Archives: http://lists.freedesktop.org/archives/xorg Info: http://lists.freedesktop.org/mailman/listinfo/xorg Your subscription address: arch...@mail-archive.com
[c-prog] Re: memory access questions
Thank you Jhon, I found a very good description about the inline assembly for PPC from Metrowerk's CodeWarrior. Apple's xcode accepts the syntax. It's a real break-out of the restrictions of c. It allows me to access all memory without alignment problems. I even can access the code, implement dispatch tables, etc. (Platform dependent off course). Teletep --- In c-prog@yahoogroups.com, John Gaughan [EMAIL PROTECTED] wrote: teletep wrote: I know assembly, but i don't know how to embed it in C. Do you know a simple tutorial on inline asm? (preferably PPC). While embedded assembly is part of the C standard, the syntax of actually using it vary from compiler to compiler. In general there is usually a block like this: asm { } that contains the assembler code. Some compilers add underscores to the asm keyword, some do not, some use a different keyword. The syntax of the assembler code is different for each compiler and platform as well. -- John Gaughan
[c-prog] Re: memory access questions
Thank you Paul, answer to Q5: To store the address of a label into cell n of array r: void *labelptr=labelname; r[n]=labelptr; To jump to the label: goto *labelptr; This works with GNU-C compiler 3.3 but not with MetroWorks. I think i need to use inline asm to solve the remaining questions. I know assembly, but i don't know how to embed it in C. Do you know a simple tutorial on inline asm? (preferably PPC). Thank you. Teletep --- In c-prog@yahoogroups.com, Paul Herring [EMAIL PROTECTED] wrote: On Thu, Jul 3, 2008 at 12:13 PM, teletep [EMAIL PROTECTED] wrote: Q5. store the address of a label into cell n : pending. Cannot be done in C or C++. Q6. store the address of a function into cell n : pending. Just use the function name without parens. Using it once it's in the cell is another matter. -- PJH 'Two Dead in Baghdad' not 'product-friendly' - Kent Ertugrul, chief executive of Phorm. http://shabbleland.myminicity.com/env
[c-prog] Re: memory access questions
Hi all, This is a review of my topic: memory access. Given: long int r[100],m,n,o,v; // array and workvariables char b[4];short int w[1];long int l[1]; // dummy arrays b w l int ba=(int)b,wa= (int)w,la= (int)l; // array base addresses RUN-TIME issues: Each 4-byte cell of array r can contain a value or an address. An address can point to any 1,2, or 4-byte word (little endian). m and n are used as cell indexes (0-99). o is used as address offset. v is a work variable used to hold a value or address (whatever). Q1. Store contents of v into cell n. answer: r[n]=v Q2. Store contents of cell n into v. answer: v=r[n] Q3. Store contents of cell m into cell n. answer: r[n]=r[m] Q4. store address of cell m into cell n. answer: r[n]=(int)r[m] Q5. store the address of a label into cell n : pending. Q6. store the address of a function into cell n : pending. Q7. load the 1-byte value addressed by r[n] into variable v. answer: v=b[r[n]-ba] Q8. same as Q7, but for a 2-byte, and a 4-byte word. answer: 2-byte : v=w[(r[n]-wa)/2] answer: 4-byte : v=l[(r[n]-la)/4] Q9. same as Q7, but for a sign-extended 2-byte word. pending Q10. how to apply an offset to the address? answer: for aligned acesses: add/subtract to the real address byte: v=b[r[n]+o-ba] 2-byte: v=w[(r[n]+o-wa)/2] (o must be mod 2) 4-byte: v=l[(r[n]+o-la)/4] (o must be mod 4) for none aligned 2-byte or 4-byte offsets: pending 3 Notes: . the cell indexes are within the bounds. . all addresses point to accesible memory. . dont use functions (unless it is a better or simpler approach) . try to minimize the generated code . if possible dont use C++ . see my previous message for expl Summary of the pending questions: Q5. accessing code via label Q6. accessing code via function Q9. sign-extent (1-2, 1-4, 2-4) Q10. accessing none aligned 2-byte/4-byte words I have ideas, but i lack knowledge of c. Improvements and help appreciated. Thankx Teletep
[c-prog] Re: memory access questions
--- In c-prog@yahoogroups.com, Paul Herring [EMAIL PROTECTED] wrote: On Tue, Jul 1, 2008 at 8:05 PM, teletep [EMAIL PROTECTED] wrote: for 1-byte access: index = memoryaddress - array-base for 2-byte access: index = (memoryaddress - array-base)/2 for 4-byte access: index = (memoryaddress - array-base)/4 For these, you'd be better off using bit masks, the bit operator (and possibly the shift operator) -- Thank you Paul. I presume your hint has to do with the division. A shift is more code efficient than a division. But my compiler generates a shift operation to divide by 2 or 4. Shifting and masking will probably be needed to solve the pending problem on accessing none-aligned 2-byte or 4-byte words. c code must exist to handle none-aligned memory accesses exceptions. Is there a group member with experience on this? Thanx Teletep
[c-prog] memory access questions
Hi, Please help me overcome the type checks in c. Given: long int r[100],m,n,v; Each 4-byte cell of array r can contain a value or an address. An address can point to a 1,2, or 4-byte word (little endian). m and n are used as cell indexes (0-99). v is used to hold a value or address (wathever). I already know the answer to these 3 questions: Q1. Store contents of v into cell n. answer: r[n]=v Q2. Store contents of cell n into v. answer: v=r[n] Q3. Store contents of cell m into cell n. answer: r[n]=r[m] Please answers the next questions. How to store addresses in array cells? Q4. store the address of cell m into cell n. Q5. store the address of a label into cell n. Q6. store the address of a function into cell n. In the assumption that cell r[n] contains a valid address, how do we dereference it? Q7. load the 1-byte value addressed by r[n] into variable v. Q8. same as Q7, but for a 2-byte, and a 4-byte word. Q9. same as Q7, but for a sign-extended 2-byte word. Q10. how to we apply an offset to the address? Notes: . the cell indexes are within the bounds. . all addresses point to accesible memory. . dont use functions (unless it is a better or simpler approach) . try to minimize the generated code . dont use C++ (restrict to ansi C if possible) Thankx Teletep
[c-prog] Re: memory access questions
Thank you Paul. I agree that no solutions can be found using ansi C. I figured out Q4. The answer is: r[n]=(int)r[m]; For Q5, my compiler refuses xxx where xxx is the name of a label. I need some time to figure out Q6. The first problem to solve the other questions concerns pointer assignment. How do i tell my compiler to accept a int value as an address? It must be possible in C. How else can debuggers be written in C? Kind regards, Teletep --- In c-prog@yahoogroups.com, Paul Herring [EMAIL PROTECTED] wrote: On Mon, Jun 30, 2008 at 12:46 PM, teletep [EMAIL PROTECTED] wrote: Hi, Please help me overcome the type checks in c. Given: long int r[100],m,n,v; Each 4-byte cell of array r can contain a value or an address. An address can point to a 1,2, or 4-byte word (little endian). m and n are used as cell indexes (0-99). v is used to hold a value or address (wathever). C doesn't work like that. They must hold either a long value, or the address of a long. You cannot reliably store both in a single variable. I already know the answer to these 3 questions: Q1. Store contents of v into cell n. answer: r[n]=v Q2. Store contents of cell n into v. answer: v=r[n] Q3. Store contents of cell m into cell n. answer: r[n]=r[m] Please answers the next questions. How to store addresses in array cells? Q4. store the address of cell m into cell n. Providing you can address the 'long' vs 'address of long' issue I mentioned earlier, you need to prepend an to a variable to get it's address: long x, y, *z; Value of 'x' = y = x; Address of 'x' = z = x; Q5. store the address of a label into cell n. Q6. store the address of a function into cell n. Functions are slightly different. The 'address of a function' is the unadorned name of the function (without the parentheses.) int (q)(void); int foo(){return 1;) q = foo; In the assumption that cell r[n] contains a valid address, how do we dereference it? Put a * in front of it. From before - z holds the address of x, to get the value: y = *z; Q7. load the 1-byte value addressed by r[n] into variable v. Q8. same as Q7, but for a 2-byte, and a 4-byte word. Q9. same as Q7, but for a sign-extended 2-byte word. These three questions again, assume that r[] is an 'anonymous' variable, in that it will return anything stored in it. In the context of C, they make no sense. Q10. how to we apply an offset to the address? Using addition. int d[10], e, *f; f = d[5]; // address of 6th element e = *(f+1); // value of 7th element Notes: . the cell indexes are within the bounds. . all addresses point to accesible memory. . dont use functions (unless it is a better or simpler approach) . try to minimize the generated code . dont use C++ (restrict to ansi C if possible) The assumptions within the questons are not ANSI/ISO C, so how they can be expected to adhere to ANSI/ISO C? -- PJH
[c-prog] Re: memory access questions
Thank you again Paul, My compiler disregards a cast from int to pointer. int v,f*; f=(int *)v; generates a Type mismatch error. Note: The questions are mine. Your answers will save me time. --- In c-prog@yahoogroups.com, Paul Herring [EMAIL PROTECTED] wrote: On Mon, Jun 30, 2008 at 3:36 PM, teletep [EMAIL PROTECTED] wrote: Thank you Paul. I agree that no solutions can be found using ansi C. I figured out Q4. The answer is: r[n]=(int)r[m]; For Q5, my compiler refuses xxx where xxx is the name of a label. I missed that question when I was reading through it earlier - labels don't have addresses in C. Q5 cannot be answered. I need some time to figure out Q6. My example should help, possibly along with a google for [c function pointer tutorials] The first problem to solve the other questions concerns pointer assignment. How do i tell my compiler to accept a int value as an address? Cast it as you have above (repeated here): r[n]=(int)r[m] Only you need to cast from in to address, instead of from address to int ( (int*) is probably what you're after.) It must be possible in C. How else can debuggers be written in C? Where did you get these questions from by the way? I hope they're not some part of 'official tutorial materials' somewhere... -- PJH 'Two Dead in Baghdad' not 'product-friendly' - Kent Ertugrul, chief executive of Phorm. http://shabbleland.myminicity.com/ind