public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Address of label which is defined within an asm statement?
@ 2006-06-27 18:37 Ioannis E. Venetis
  2006-06-28  6:08 ` Ian Lance Taylor
  0 siblings, 1 reply; 5+ messages in thread
From: Ioannis E. Venetis @ 2006-06-27 18:37 UTC (permalink / raw)
  To: gcc-help

Dear all,

I have the following code:

__asm__ __volatile__ (
				...
				"MyLabel:	..."
				...
				: <output regs>
				: <input regs>
				: <clobber list>);

Within the asm statement, I have to find somehow the address of label 
"MyLabel", in order to use it in one instruction. I looked through the 
archives but only found a solution if the label is defined outside the 
asm statement, where the '&&' operator and the "X" constraint can be 
used to pass that label into the asm statement. However, I can't figure 
out how to do it in my case. Any ideas?

Thank you,

Ioannis

P.S: Unfortunately, the architecture that I use is unconventional and 
not yet available. This is why I don't mention it. I hope that there is 
a generic solution, that does not require architecture specific details.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Address of label which is defined within an asm statement?
  2006-06-27 18:37 Address of label which is defined within an asm statement? Ioannis E. Venetis
@ 2006-06-28  6:08 ` Ian Lance Taylor
  2006-06-28 14:41   ` Ioannis E. Venetis
  0 siblings, 1 reply; 5+ messages in thread
From: Ian Lance Taylor @ 2006-06-28  6:08 UTC (permalink / raw)
  To: Ioannis E. Venetis; +Cc: gcc-help

"Ioannis E. Venetis" <venetis@capsl.udel.edu> writes:

> I have the following code:
> 
> __asm__ __volatile__ (
> 				...
> 				"MyLabel:	..."
> 				...
> 				: <output regs>
> 				: <input regs>
> 				: <clobber list>);
> 
> Within the asm statement, I have to find somehow the address of label
> "MyLabel", in order to use it in one instruction. I looked through the
> archives but only found a solution if the label is defined outside the
> asm statement, where the '&&' operator and the "X" constraint can be
> used to pass that label into the asm statement. However, I can't
> figure out how to do it in my case. Any ideas?

If you have a label in assembly code, and you want to use it in
assembly code, then you need to write whatever is appropriate for your
assembly language (e.g., "mov #MyLabel,r0").  That is not really a
compiler issue.

If you have a label in assembly code, and you want to use it in C code
(e.g., by doing "goto MyLabel;"), then, sorry, you can't do that.

Ian

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Address of label which is defined within an asm statement?
  2006-06-28  6:08 ` Ian Lance Taylor
@ 2006-06-28 14:41   ` Ioannis E. Venetis
  2006-06-28 16:00     ` David Fernandez
  0 siblings, 1 reply; 5+ messages in thread
From: Ioannis E. Venetis @ 2006-06-28 14:41 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc-help

Hello Ian,

Thanks for answering this. I need to access the address of the label 
within the assembly code that I write. This means that I will have to 
check again the documentation of this architecture. I hope that I will 
find something.

Best regards,

Ioannis

> 
> If you have a label in assembly code, and you want to use it in
> assembly code, then you need to write whatever is appropriate for your
> assembly language (e.g., "mov #MyLabel,r0").  That is not really a
> compiler issue.
> 
> If you have a label in assembly code, and you want to use it in C code
> (e.g., by doing "goto MyLabel;"), then, sorry, you can't do that.
> 
> Ian

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Address of label which is defined within an asm statement?
  2006-06-28 14:41   ` Ioannis E. Venetis
@ 2006-06-28 16:00     ` David Fernandez
  2006-06-28 22:28       ` Ioannis E. Venetis
  0 siblings, 1 reply; 5+ messages in thread
From: David Fernandez @ 2006-06-28 16:00 UTC (permalink / raw)
  To: Ioannis E. Venetis; +Cc: Ian Lance Taylor, gcc-help

On Wed, 2006-06-28 at 10:45 -0400, Ioannis E. Venetis wrote:
> Hello Ian,
> 
> Thanks for answering this. I need to access the address of the label 
> within the assembly code that I write. This means that I will have to 
> check again the documentation of this architecture. I hope that I will 
> find something.
> 
> Best regards,
> 
> Ioannis
> 
> > 
> > If you have a label in assembly code, and you want to use it in
> > assembly code, then you need to write whatever is appropriate for your
> > assembly language (e.g., "mov #MyLabel,r0").  That is not really a
> > compiler issue.
> > 
> > If you have a label in assembly code, and you want to use it in C code
> > (e.g., by doing "goto MyLabel;"), then, sorry, you can't do that.
> > 
> > Ian

To obtain the label address could be somthing like "mov #MyLabel, %<n>"
or "mov $MyLabel, %<n>" with <n> the output parameter number where you
get the result like : "=g" (MyLabelAddressVar).

To call a label from C code can be done using
	goto *MyLabelAddressVar
I think that is a C Extension feature of gcc... You cold also pass the
value to another assembler block to do the trick, but that would be
architectural dependent some way...
	"jmp *%0"
	:
	: "r" (MyLabelAddressVar)

David.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Address of label which is defined within an asm statement?
  2006-06-28 16:00     ` David Fernandez
@ 2006-06-28 22:28       ` Ioannis E. Venetis
  0 siblings, 0 replies; 5+ messages in thread
From: Ioannis E. Venetis @ 2006-06-28 22:28 UTC (permalink / raw)
  To: David Fernandez; +Cc: Ian Lance Taylor, gcc-help

Thank you David and Ian,

Based on your responses I finally figured out what I had to do. It works 
now!

Best regards,

Ioannis


David Fernandez wrote:
> On Wed, 2006-06-28 at 10:45 -0400, Ioannis E. Venetis wrote:
>> Hello Ian,
>>
>> Thanks for answering this. I need to access the address of the label 
>> within the assembly code that I write. This means that I will have to 
>> check again the documentation of this architecture. I hope that I will 
>> find something.
>>
>> Best regards,
>>
>> Ioannis
>>
>>> If you have a label in assembly code, and you want to use it in
>>> assembly code, then you need to write whatever is appropriate for your
>>> assembly language (e.g., "mov #MyLabel,r0").  That is not really a
>>> compiler issue.
>>>
>>> If you have a label in assembly code, and you want to use it in C code
>>> (e.g., by doing "goto MyLabel;"), then, sorry, you can't do that.
>>>
>>> Ian
> 
> To obtain the label address could be somthing like "mov #MyLabel, %<n>"
> or "mov $MyLabel, %<n>" with <n> the output parameter number where you
> get the result like : "=g" (MyLabelAddressVar).
> 
> To call a label from C code can be done using
> 	goto *MyLabelAddressVar
> I think that is a C Extension feature of gcc... You cold also pass the
> value to another assembler block to do the trick, but that would be
> architectural dependent some way...
> 	"jmp *%0"
> 	:
> 	: "r" (MyLabelAddressVar)
> 
> David.
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-06-28 22:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-06-27 18:37 Address of label which is defined within an asm statement? Ioannis E. Venetis
2006-06-28  6:08 ` Ian Lance Taylor
2006-06-28 14:41   ` Ioannis E. Venetis
2006-06-28 16:00     ` David Fernandez
2006-06-28 22:28       ` Ioannis E. Venetis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).