The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: EddieB on October 30, 2006, 10:43:23 AM

Title: Symbols
Post by: EddieB on October 30, 2006, 10:43:23 AM
Hey

I'm still new to assembler, but ive come across code where they have @@ symbols for labels...

Could someone please explain, what they are, and why people use them?

Many thanks.
Title: Re: Symbols
Post by: sinsi on October 30, 2006, 11:30:47 AM
From the MASM reference

Quote@@:
Defines a code label recognizable only between label1 and label2, where label1 is either start of code or the previous @@: label, and label2 is either end of code or the next @@: label. See @B and @F.
@B
The location of the previous @@: label.
@F
The location of the next @@: label.

Useful in loops where you can't be bothered making up unique labels
  mov ecx,3
@@:
  dec ecx
  jz @F      ;translated to "jz to the Forward @@:"
  call DoSomething
  jmp @B     ;translated to "jmp Back to the previous @@:"
@@:
  ret


Be aware, you can get some odd results using more than a couple of @@: labels in one PROC...
Title: Re: Symbols
Post by: sluggy on October 30, 2006, 11:37:38 AM
That is an anonymous label, designed for short jumps.

Somewhere near the @@: will be a jump (either conditional or unconditional). Here is a quick pseudo code example:


shr eax, 1
jnc @F

invoke someFunction

@@:
do so more stuff.....


this tests the lowest bit of eax, if it is set it calls someFunction, if it is not set (determined by the carry flag being clear) then we jump over the function call. The @F tells us to jump foward to the first anonymous label we can find, equally i could have used @B to go backwards. IIRC, the maximum length for a jump to an anonymous label is 127 bytes, which is not much.



Title: Re: Symbols
Post by: EddieB on October 30, 2006, 11:40:38 AM
Thank you for the descriptive posts guys :)

I understand now, the B and F confused me...

Cheers