flat assembler
Message board for the users of flat assembler.

flat assembler > Macroinstructions > who can post a "For" macro? thank!

Author
Thread Post new topic Reply to topic
zjlcc



Joined: 23 Jul 2003
Posts: 32
Location: china
for a:=1 to 10 do begin
........
exit for
........
end;

for a:=10 downto 1 do begin
........
exit for
........
end;

for a:=10 downto 1 step 2 do begin
........
exit for
........
end;

thank you!
Post 01 Sep 2003, 09:01
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6927
Location: Kraków, Poland
Maybe something like:
Code:
macro for var,min,instr,max
 {
   mov [var],min
   local loop,end
   loop:
   _for_var equ var
   _for_limit equ max
   _for_instr equ instr
   _for_origin equ loop
   _for_exit equ end
 }

macro endfor
 {
   cmp [_for_var],_for_limit
   je _for_exit
   _for_instr [_for_var]
   jmp _for_origin
   _for_exit:
   restore _for_exit
   restore _for_origin
   restore _for_limit
   restore _for_instr
   restore _for_var
 }

to fix ,inc,
downto fix ,dec,    

use it like here:
Code:
for a,1 to 10
 for b,10 downto 1
  ; ...
 endfor
endfor    

It should be easy to extend it with more functions.
Post 02 Sep 2003, 17:41
View user's profile Send private message Visit poster's website Reply with quote
zjlcc



Joined: 23 Jul 2003
Posts: 32
Location: china
Very Happy Very Happy Very Happy
thank Privalov
because my bad english, so i study "Macro" syntax very difficulty
anyways, thank Privalov again!!!
Post 03 Sep 2003, 02:00
View user's profile Send private message Reply with quote
wakalabis



Joined: 17 Dec 2004
Posts: 2
Privalov, (or anybody else)

Why does using multiple levels of this macro work ?

Code:
for a,1 to 10
 for b,10 downto 1
   for c, 2 to 5

    endfor
  ; ...
 endfor
endfor
    


when you have something like this:

Code:
macro my_macro var{
    _var equ var

    ...
}

macro my_macro_end {
  
    _restore _var  
}

// code

my_macro 1
my_macro 2

    


when my_macro is called for the second time, what happens to "_var" ?
is it redefined, this time assuming value '2', clearing the old value '1' ?

or is there some kind of context created once for each time 'my_macro' is expanded ? does the new value '2' get "pushed" at each equ and "poped" at each restore ?
Post 17 Dec 2004, 08:24
View user's profile Send private message Reply with quote
Nikolay Petrov



Joined: 22 Apr 2004
Posts: 101
Location: Bulgaria
i use very often next code
Code:
include '%fasminc%\macro\if.inc'
;for a:=1 to 10 do begin
mov [a],1
.repeat
   ;........
   inc [a]
.until [a],e,11
dec [a]

;for a:=10 downto 1 do begin 
mov [a],10
.repeat
   ;......
   dec [a]
.until [a],e,0
inc [a]    


i didn't tested next code, but i think it's going to work.
Code:
;for a,1 to 10 
 ;for b,10 downto 1 
   ;for c, 2 to 5 

    ;endfor 
  ; ... 
 ;endfor 
;endfor
mov [a],1
mov [b],10
mov [c],2
.repeat
    .repeat
        .rapeat
             ;code third cycle
             inc [c]
        .until c,e,6
        mov [c],2
        ;code second cycle 
        dec [b]
     .until b,e,0
     mov [b],10
     ;code first cycle
     inc [a]
.until a,e,11
dec [a]    
Post 17 Dec 2004, 14:58
View user's profile Send private message Reply with quote
beppe85



Joined: 23 Oct 2004
Posts: 181
Yes, you have gotten the idea! Wink

wakalabis wrote:
Privalov, (or anybody else)
or is there some kind of context created once for each time 'my_macro' is expanded ? does the new value '2' get "pushed" at each equ and "poped" at each restore ?


See this example:

Code:
macro teste var
{
        _myvar equ var
}

macro endt
{
        restore _myvar
}

teste 'a'
  display _myvar
  teste 'b'
    display _myvar
  endt
  display _myvar
endt
display _myvar    


The last display causes an error, because _myvar gets restored to its very first meaning, that is, _myvar per se.
Post 18 Dec 2004, 22:08
View user's profile Send private message Reply with quote
wakalabis



Joined: 17 Dec 2004
Posts: 2
beppe85, você é brasileiro ?

Valeu pela resposta !

Translation:

beppe85, are you Brazilian ?

Thanks for replying !
Post 19 Dec 2004, 02:04
View user's profile Send private message Reply with quote
beppe85



Joined: 23 Oct 2004
Posts: 181
wakalabis, com certeza, sou sim. Very Happy

Translation:

Sure I am.
Post 19 Dec 2004, 06:19
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-2018, Tomasz Grysztar.

Powered by rwasa.