LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Using assembler in GCC , how do how do I reference volatile variables ? (http://www.linuxquestions.org/questions/programming-9/using-assembler-in-gcc-how-do-how-do-i-reference-volatile-variables-774542/)

Alan5 12-09-2009 02:36 PM

Using assembler in GCC , how do how do I reference volatile variables ?
 
Please help with assembler in GCC.
Writing asm within a function how do how do I reference the volatile variables ?
There has to be a stack frame and offsets, I have searched the web finding no answer.
I will attempt to solve this by correlating printf ( "%p" , & variable ) ; with segment and general registers, but if this exploration works the result will be second best as it may be flawed. And I won't know.

JohnGraham 12-09-2009 03:34 PM

It looks like you want to read a good GCC inline assembler tutorial - this one's got a good section for what you want:

http://www.ibiblio.org/gferg/ldp/GCC...-HOWTO.html#s5

John G

Alan5 12-10-2009 06:33 AM

Thanks
 
Many thanks John.
The problem arose because of my pig headed attachment to registers.
I had earlier seen the link that you kindly gave, I been working forwards with :
http://www.delorie.com/djgpp/doc/bre...ine_djgpp.html
So I have to engrave on the inside of my head :
Because GCC optimises, it is impossible to work with the 386 registers and volatile variables

JohnGraham 12-11-2009 04:11 AM

Quote:

Originally Posted by Alan5 (Post 3786571)
So I have to engrave on the inside of my head :
Because GCC optimises, it is impossible to work with the 386 registers and volatile variables

What do you mean? Why do you think this is? Surely you simply have your inline assembler load the variable from memory and then replace it when it's done... or is this not what you mean?

(By the way if you're thinking that GCC is erroneously optimizing your assembler, you can stop it with __volatile__, i.e. use "__asm__ __volatile__ (...);")

John G

Alan5 12-12-2009 02:11 PM

Yeah but
 
My thanks to you John for your continuing interest and help.
I understand GCC optimises everything. So the stack frame pointer is not in a known place. With or without optimization of my code I will not be able to reference the volatile variables.
If this is wrong I hope it can be corrected for all readers.
I have been otherwise committed for a day, I will get down to your first suggestion. Give me a couple of days and there should be a cry of triumph here.

Alan5 01-14-2010 03:12 PM

Success with gratitude
 
I think that I am there, my thanks.

My first task was a multi element shift. I am sorry that when posted here as a quote it is unreadable. I will post a link when this with other routines are on the web.

Alan5 03-31-2011 06:52 AM

My thanks
 
I have not expressed my thanks properly, I irritated kind and helpful JohnGraham.

My problem was that I did not understand my problem.

I knuckled down did what I wanted. Long after it was done I realized what my personal problem was. I explain.

I have worked with a number of assemblers. I acquired an understanding that they are designed to make the writing and translation of code as easy as possible for the human author. The GCC assembler with five different references for each register contradicted this. But GCC asm is defined for the benefit of the C compiler, humans have to adapt.

I am happy. If anyone with the same problem arrives here my proof is at :

http://www.linuxquestions.org/questi...te=1&p=3826717

If you wish to read just see within the asm folder and get bignGCC.lib . bignGCC.txt explains how to use it. If you wish to compile and run then you will need the bign.tar for explanation and bigcalc.c , which has to be modified by changing the #include "bign.lib" to #include "bignGCC.lib" .

Thanks John.


All times are GMT -5. The time now is 09:04 AM.