News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

The nature of masm jumps

Started by zemtex, September 03, 2010, 10:08:53 PM

Previous topic - Next topic

zemtex

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!
I have been puzzling with lego bricks all my life. I know how to do this. When Peter, at age 6 is competing with me, I find it extremely neccessary to show him that I can puzzle bricks better than him, because he is so damn talented that all that is called rational has gone haywire.

Twister

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.

Rockoon

Using @@ in front of any label name makes it local scope.

@@foo:
...do work...
jmp @@foo
When C++ compilers can be coerced to emit rcl and rcr, I *might* consider using one.

jj2007

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

hutch--

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::
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

bomz

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????

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

hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

bomz


Vortex

Poasm and Jwasm are also supporting the anonymous labels.

zemtex

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
I have been puzzling with lego bricks all my life. I know how to do this. When Peter, at age 6 is competing with me, I find it extremely neccessary to show him that I can puzzle bricks better than him, because he is so damn talented that all that is called rational has gone haywire.

BogdanOntanu

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 ;)
Ambition is a lame excuse for the ones not brave enough to be lazy.
http://www.oby.ro

drizz

Never use anonymous labels inside a macro!
The truth cannot be learned ... it can only be recognized.

jj2007

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?

oex

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
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

jj2007

#14
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