Jumps in inline code

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

I am using a bit of line code:

	asm("breq PC+0x01\n");	

but I get an undefined reference to the program counter. How do I get it to skip the next instruction ?

<º))))><

I am only one lab accident away from becoming a super villain.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

PC is "." in a real assembler ;-)

But why not use local labels?

asm("breq 1f\n");
asm("ldi r16,12\n");
asm("1: or r14,r16\n");

which generates:

asm("breq 1f\n");
  9a:	09 f0       	breq	.+2      	; 0x9e 
asm("ldi r16,12\n");
  9c:	0c e0       	ldi	r16, 0x0C	; 12
asm("1: or r14,r16\n");
  9e:	e0 2a       	or	r14, r16

The page in the manual about local labels:

http://sourceware.org/binutils/d...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

PC is "." in a real assembler

Just a note: It is, and it isn't. Remember that in one assembler, that "program counter" shorthand may refer to the beginning of 'this' instruction, and in another it may refer to the beginning of the 'next' instruction.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

in one assembler

There only is one true assembler - it's called "gas". Beware of pale imitations. ;)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do you have gas ?

<º))))><

I am only one lab accident away from becoming a super villain.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
But why not use local labels?
because I didn't know that I could. That's much easier, cheers. I've put that in and bingo, it's working fine. Excellent - thank you for help (once again) :)

<º))))><

I am only one lab accident away from becoming a super villain.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Do you have gas ?

Nope, but most people think I'm a windbag! :lol:

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
PC is "." in a real assembler ;-)

But why not use local labels?

asm("breq 1f\n");
asm("ldi r16,12\n");
asm("1: or r14,r16\n");

You aren't allowed to jump to another asm as it introduces a control flow unknown to the compiler. Nor are you allowed to trample over registers without informing the compiler.

Whilst your program may work with current versions of GCC, with future version it may not.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Whilst your program may work with current versions of GCC, with future version it may not.

OK, you lost me on that one. Couldn't you say that about nearly everything in the compiler, especially those things AVR-specific?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
You aren't allowed to jump to another asm as it introduces a control flow unknown to the compiler.

What do you mean by "another asm"? If you mean that you can't jump to another assembly block, of course not, that's why they call it a local label.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Maybe Timothy meant that the optimiser might re-order the Asm statements? I have to be honest that I've never seen this happen, but if it can this would seem to be yet another argument for using .S