LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-09-2009, 02:36 PM   #1
Alan5
LQ Newbie
 
Registered: Aug 2009
Posts: 12

Rep: Reputation: 0
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.
 
Old 12-09-2009, 03:34 PM   #2
JohnGraham
Member
 
Registered: Oct 2009
Posts: 467

Rep: Reputation: 138Reputation: 138
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
 
Old 12-10-2009, 06:33 AM   #3
Alan5
LQ Newbie
 
Registered: Aug 2009
Posts: 12

Original Poster
Rep: Reputation: 0
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
 
Old 12-11-2009, 04:11 AM   #4
JohnGraham
Member
 
Registered: Oct 2009
Posts: 467

Rep: Reputation: 138Reputation: 138
Quote:
Originally Posted by Alan5 View Post
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
 
1 members found this post helpful.
Old 12-12-2009, 02:11 PM   #5
Alan5
LQ Newbie
 
Registered: Aug 2009
Posts: 12

Original Poster
Rep: Reputation: 0
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.
 
Old 01-14-2010, 03:12 PM   #6
Alan5
LQ Newbie
 
Registered: Aug 2009
Posts: 12

Original Poster
Rep: Reputation: 0
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.
 
Old 03-31-2011, 06:52 AM   #7
Alan5
LQ Newbie
 
Registered: Aug 2009
Posts: 12

Original Poster
Rep: Reputation: 0
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.
 
  


Reply

Tags
asm, gcc


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: C/C++ reference counting with atomic variables and gcc LXer Syndicated Linux News 0 05-27-2009 02:11 PM
Gcc Assembler And Link eichmen Programming 4 04-17-2007 07:14 AM
JAVA: Reference Variables (Pointers) and Constructors wwnexc Programming 14 03-10-2006 03:31 AM
passing variables by reference in javascript djgerbavore Programming 2 06-07-2005 11:34 PM
gcc ld error. Undefined reference redness Linux - Software 4 02-08-2005 02:01 AM


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

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration