The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: zemtex on September 03, 2010, 10:08:53 PM

Title: The nature of masm jumps
Post by: zemtex on September 03, 2010, 10:08:53 PM
Since this is the forum to ask silly questions, here is my version of it: I find myself using @@: labels often because I often create labels with duplicate names and that is a problem in the long run. Any recommendations for how I can use labels in local functions?

Is there a way to jump 2 or more steps back by using Jmp @B and Jmp @F. These two instructions jump only one step back or forward, what if I want to jump two or more steps back, is there a way to do that?

Regards,
....Zemtex!
Title: Re: The nature of masm jumps
Post by: Twister on September 03, 2010, 10:29:42 PM
No, you can not jump two anonymous labels back or two anonymous labels foward. You can only jump to the previous or next anonymous label.
Title: Re: The nature of masm jumps
Post by: Rockoon on September 03, 2010, 10:32:47 PM
Using @@ in front of any label name makes it local scope.

@@foo:
...do work...
jmp @@foo
Title: Re: The nature of masm jumps
Post by: jj2007 on September 03, 2010, 10:42:45 PM
Take it easy - all labels inside procs are local by default. Use a double colon (Skip::) if you want global labels.

include \masm32\include\masm32rt.inc

MyTest1 PROTO: DWORD, :DWORD
MyTest2 PROTO: DWORD, :DWORD

.code
AppName db "Masm32 is great!", 0
Hello db "A message:", 0

start:
invoke MyTest1, offset AppName, addr Hello
invoke MyTest2, offset AppName, addr Hello
MsgBox 0, "Done", "Hi", MB_OK
exit

MyTest1 proc arg1:DWORD, arg2:DWORD
  jmp Skip
  MsgBox 0, arg1, arg2, MB_OK
Skip:
  ret
MyTest1 endp

MyTest2 proc arg1:DWORD, arg2:DWORD
  jmp Skip
  MsgBox 0, arg1, arg2, MB_OK
Skip:
  ret
MyTest2 endp

end start
Title: Re: The nature of masm jumps
Post by: hutch-- on September 03, 2010, 11:42:16 PM
My own preference when mixing @@: labels and labels where you ned to jump over @@: labels is to simply number them.

lbl0:
lbl1: etc ...

You can do it inside any proc as labels inside a proc are local unless you have the double colon after it.  gLabel::
Title: Re: The nature of masm jumps
Post by: bomz on September 04, 2010, 07:07:45 AM
This problem is common, to decide it particularly @@ exist.  make your own zemasm. try DEBUG and you understand what is real problem

MASM32 v11 expected???? (http://smiles.kolobok.us/light_skin/blush.gif)

may be the best decision is basic structure when each string may (for turbo) or must (for Hewlett-Packard) have number - it's not so crazy because each string really have number
Title: Re: The nature of masm jumps
Post by: hutch-- on September 04, 2010, 07:59:30 AM
Its an internal part of ML.EXE so its not like it can be changed any time soon. Anonymous labels work fine, you just need to understand what they do and use them properly.
Title: Re: The nature of masm jumps
Post by: bomz on September 04, 2010, 08:50:38 AM
I like it (anonymous labels) (http://smiles.kolobok.us/light_skin/give_heart2.gif)
Title: Re: The nature of masm jumps
Post by: Vortex on September 04, 2010, 09:00:21 AM
Poasm and Jwasm are also supporting the anonymous labels.
Title: Re: The nature of masm jumps
Post by: zemtex on September 04, 2010, 09:45:37 AM
Quote from: hutch-- on September 03, 2010, 11:42:16 PM
My own preference when mixing @@: labels and labels where you ned to jump over @@: labels is to simply number them.

lbl0:
lbl1: etc ...

You can do it inside any proc as labels inside a proc are local unless you have the double colon after it.  gLabel::

Yes thats the way to go. To keep things short and lucid throughout the local code its better to just number things. I sometimes use a letter before a number so I can group different sections of code. One function may use h another use n etc. But after I read this thread and "discovered" that local labels are really local anyway, I will just forget about using letters and stick to numbers only.  :U
Title: Re: The nature of masm jumps
Post by: BogdanOntanu on September 04, 2010, 11:35:39 AM
I dislike anonymous labels.

They make the code harder to read and understand. For example When you see a jmp @F in code you do not really know what it is... is it an exit point? is it an .IF .ELSE location or what? By comparison JMP @finish  or JMP @skip_pixel have clear meanings.

If you do not want to have a meaningful label name invented then by all means do use the HLL directives like .IF .ELSE or .WHILE or .REPEAT but -- from my experience with large ASM projects -- anonymous labels should be avoided at all costs ;)
Title: Re: The nature of masm jumps
Post by: drizz on September 04, 2010, 12:47:13 PM
Never use anonymous labels inside a macro!
Title: Re: The nature of masm jumps
Post by: jj2007 on September 04, 2010, 04:45:35 PM
Quote from: drizz on September 04, 2010, 12:47:13 PM
Never use anonymous labels inside a macro!

Why, because of the 16-bit limit?
Title: Re: The nature of masm jumps
Post by: oex on September 04, 2010, 04:56:02 PM
Quote from: jj2007 on September 04, 2010, 04:45:35 PM
Quote from: drizz on September 04, 2010, 12:47:13 PM
Never use anonymous labels inside a macro!

Why, because of the 16-bit limit?

because if you call the macro inside the following you mess up your app?

xmacro MACRO
jmp @F

@@:
ENDM

PROC
@@:
print "Hello" ; (Constantly)
xmacro

jmp @b
ENDP

The jump jumps back into the macro not to the proc anon
Title: Re: The nature of masm jumps
Post by: jj2007 on September 04, 2010, 05:14:06 PM
Quote from: oex on September 04, 2010, 04:56:02 PM
Quote from: jj2007 on September 04, 2010, 04:45:35 PM
Quote from: drizz on September 04, 2010, 12:47:13 PM
Never use anonymous labels inside a macro!

Why, because of the 16-bit limit?

because if you call the macro inside the following you mess up your app?


Right, good example :U

Here is a workaround:
include \masm32\include\masm32rt.inc
include MacLabel.inc

Mac1 MACRO
  jmp @MF
  nop
@@M:
  xor eax, eax
  jne @MB
  inc eax
  je @MB
ENDM

Mac2 MACRO
  jmp @MF
  nop
@@M:
  xor eax, eax
  jne @MB
  dec eax
  je @MB
ENDM

.code
AppName db "Masm32 is great:", 0

start:
Mac1
Mac2
MsgBox 0, "That works!", addr AppName, MB_OK
exit

end start