flat assembler
Message board for the users of flat assembler.

Index > Main > Trouble with anonymous labels and macros

Author
Thread Post new topic Reply to topic
lemask



Joined: 04 Oct 2010
Posts: 19
lemask 21 Oct 2010, 08:15
Once in a while i wonder why my program won't run as expected. When debugging, i'll find:

Code:
 test    eax,eax
     jz      @f
  call    someting
    CHKERR
      jmp     elsewhere
@@:    ...
    


Where the CHKERR macro resolves to:
Code:
macro CHKERR {
        test    eax,eax
     jnz     @f
  jmp     report_error
@@:
}
    


This mistake really annoys me, and costs me some time. Am i the only one with such problems? How do you use anonymous labels?
Post 21 Oct 2010, 08:15
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20355
Location: In your JS exploiting you and your system
revolution 21 Oct 2010, 08:40
Simple rule: Don't use anonymous labels in macros. Use local labels instead.
Code:
macro CHKERR {
        local   .x
        test    eax,eax
        jnz     .x
        jmp     report_error
.x:
}    
Or even simpler:
Code:
macro CHKERR {
        test    eax,eax
        jz      report_error
}    
Post 21 Oct 2010, 08:40
View user's profile Send private message Visit poster's website Reply with quote
lemask



Joined: 04 Oct 2010
Posts: 19
lemask 27 Oct 2010, 09:52
Thanks for the tip, revolution!
Post 27 Oct 2010, 09:52
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.