flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > An example of using "defined" and "used"

Author
Thread Post new topic Reply to topic
hopcode



Joined: 04 Mar 2008
Posts: 563
Location: Germany
hopcode 02 Jan 2009, 19:51
Hallo to All,
and Happy New Year!!!!
Super Forum,Super Programming,Super 2009 Year!!!!
I have been away for a shoert time...Christmas
holidays..fireworks...mädchen...slivovitz...and..
...FAAAAAAAAASM PROOOGRAMMING!!!!
Ok.

Inspired from the "import" macro i have got this idea to
create ids. Currently I apply it to the Biberkopf project.
It is only a part of the complete macro to manage
static-time/runtime definition of ids.
Note that it is not my final version, and maybe it could be
improved a lot.At the moment i cannot explain in details what
it does and why,too much times and verbal complexity for me.
I will post handsketches to explain a bit more
about the design of Fasmlab.

I have posted it,in the hope that it will be useful
for someone who need examples on the semantics of
the keyword "defined" and "used" with Fasm.
Ok.

Code:
;ü------------------------------------------ö
;|         Fasmlab (project Biberkopf)      |
;|     by hopcode aka Marc Rainer Kranz     |
;|     Datum:02.Jan.2009                    |
;|     Macro to define ids                  |
;|     Note:simplified version              |
;#------------------------------------------ä

include "%fasminc%\win32a.inc"
;include "mrk_macro.inc"

macro make_forward the_name {
  @#the_name = $ ;<------ do you understand what i mean ?
}

macro id@slot reg,arg {
 mov reg,@#arg       
; display_hex 16, @#arg
}

macro makeid gname,[idlabel@value]  {
 common
 local val@start
 label header@#gname
 val@start = 0
    
 forward
 local tmp
 define status 0
  match =0 idlabel == value,status idlabel@value
   \{
    idlabel = value
    ;display \`idlabel,13,10
    val@start = value
    if used idlabel
   if ~defined used@labels
      used@labels = 0
     dd 0                           
     db 12 dup (0)
      end if
      label tmp
   make_forward idlabel
        
    dd val@start
        db \`idlabel,0
     db (32-($-tmp)) dup (0) 
    
    used@labels = used@labels +1
     end if
 define status 1
   \}
 
  match =0 idlabel,status idlabel@value
   \{
    idlabel = val@start
    if used idlabel
     if ~defined used@labels
      used@labels = 0
     dd 0                                                                                   
     db 12 dup (0)
      end if
      label tmp
   make_forward idlabel
        
    dd val@start
        db \`idlabel,0
     db (32-($-tmp)) dup (0) 
    used@labels = used@labels +1
    end if
    define status 1
   \}
    val@start = val@start+1
  common
  if defined used@labels
    store dword used@labels at 0
  end if
}

;--------------usage-----------------
 makeid files,\
  FL_TEXTFILES = 100,\
       FL_RCFILE,\    ; = auto increment 101
      FL_FILE,\      ; 102
       FL_TXTFILE,\   ;...
        FL_ASMFILE,\
  FL_BINFILES = 200,\
     FL_HEXFILE,\   ;201
        FL_OUTFILE,\   ;...
        FL_RESFILES
         
 makeid projects,\
   FL_PROJECTS = 100,\
  FL_FILE         ; but here uncontrolled redefinition = 101      !!!
                 ;---------how can i do a check of it ??????????????????         
            
    ;---------- virtual only for a static-time 
 ;-----------in-code "activation". it refers to the line
   ;---------- "if used idlabel"
     
  virtual
       mov eax,FL_PROJECTS             ;activate
   mov eax,FL_RCFILE
   mov eax,FL_HEXFILE
  mov eax,FL_FILE
  end virtual
            
    ;----------virtual to avoid overhead code in the bin file,
  ;----------to avoid assembling f.exmple.: mov eax,header@projects
  virtual
   id@slot eax,FL_HEXFILE  ;at offset 50h
   id@slot eax,FL_PROJECTS ;at offset 70h    
   id@slot eax,FL_RCFILE   ;at offset 10h
   mov eax,header@projects                     
  end virtual               
    
;  display_decimal FL_RCFILE   ;display 101 
;  display 13,10
;  display_decimal FL_FILE     ;ATTENTION!!! redef,it display 101
;
;  display_hex 16, header@projects ;display 70h
;  display_hex 16, header@files    ;display 0h
;  display 13,10
    

output

Code:
; compiled .bin
; 00000000: 05 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................   
; 00000010: 65 00 00 00 46 4C 5F 52 43 46 49 4C 45 00 00 00  e...FL_RCFILE...   
; 00000020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................   
; 00000030: 66 00 00 00 46 4C 5F 46 49 4C 45 00 00 00 00 00  f...FL_FILE.....   
; 00000040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................   
; 00000050: C9 00 00 00 46 4C 5F 48 45 58 46 49 4C 45 00 00  É...FL_HEXFILE..   
; 00000060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................   
; 00000070: 64 00 00 00 46 4C 5F 50 52 4F 4A 45 43 54 53 00  d...FL_PROJECTS.   
; 00000080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................   
; 00000090: 65 00 00 00 46 4C 5F 46 49 4C 45 00 00 00 00 00  e...FL_FILE.....   
; 000000A0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................   
    


Enjoy,
hopcode
Post 02 Jan 2009, 19:51
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.