flat assembler
Message board for the users of flat assembler.

flat assembler > Macroinstructions > First Macro - Code Review

Author
Thread Post new topic Reply to topic
moveax41h



Joined: 18 Feb 2018
Posts: 47
Hey everyone, this is my first time writing a macro. In addition, I was away from fasm for about 3 months so it would be a good time to get some feedback. I'm wondering if you could think of a better way of doing this or critique mine... Thanks:

Code:


format ELF

section '.text' executable

 public main
 extrn printf
 extrn scanf

 macro check_flag msg, bit, subsequent
     {
            pushf

                push msg
                call printf
                add esp, 4

                pop eax ; get flags into eax
                test ax, bit
                jz subsequent

                push set_m
                call printf
                add esp, 4
     }

 main:
        pushf
        push the_flags_m
        call printf
        add esp, 8

.cf_check:
        check_flag carry_flag_m, 1h, .pf_check

.pf_check:
        check_flag parity_flag_m, 4h, .af_check


.af_check:
        check_flag aux_flag_m, 10h, .zf_check ; DEBYG: This check may be wrong

.zf_check:
        check_flag zero_flag_m, 40h, .sf_check


.sf_check:
        check_flag sign_flag_m, 80h, .df_check

.df_check:
        check_flag direction_flag_m, 400h, .of_check

.of_check:
        check_flag overflow_flag_m, 800h, .done

.done:
        ret

section '.data' writeable

section '.rodata'

 set_m db "SET",0xA, 0
 notset_m db "not set", 0 ; NOT USED IN CURR VERSION
 the_flags_m db "The flags are: %#08x", 0xA, 0
 carry_flag_m db "The carry flag is: ", 0xA, 0
 parity_flag_m db "The parity flag is: ", 0xA, 0
 aux_flag_m db "The aux flag is: ", 0xA, 0
 zero_flag_m db "The zero flag is: ", 0xA, 0
 sign_flag_m db "Thaux flag is: ", 0xA, 0
 overflow_flag_m db "The overflow flag is: ", 0xA, 0
 direction_flag_m db "The direction flag is: ", 0xA, 0
    

_________________
-moveax41h
Post 22 Jul 2018, 20:08
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16096
Location: Transylbonia
You can use local labels in macros:
Code:
macro check_flag msg, bit
     {
     local .skip
            pushf

                push msg
                call printf
                add esp, 4

                pop eax ; get flags into eax
                test ax, bit
                jz .skip

                push set_m
                call printf
                add esp, 4
      .skip:
     }    
Post 22 Jul 2018, 22:52
View user's profile Send private message Visit poster's website 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-2018, Tomasz Grysztar.

Powered by rwasa.