flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Macro parameters for constant literals and variable

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
fasmnewbie



Joined: 01 Mar 2011
Posts: 553
fasmnewbie
l_inc wrote:
fasmnewbie
Quote:
I can't display two different values for the same run.

First of all, why not? Look:
Code:
macro test a
{
        pusha
        local ..b, .go
        xor si, si

        ;push dword [..b] ;works for label
        ;push dword ..b   ;works for constant

        define address +
        define address -
        match *val,a \{
            restore address
            jmp @f
                ..b dd val
            @@:
            push dword [..b]
        \}
        match -,address \{
            restore address
            jmp @f
                ..b dd a
            @@:
            push dword ..b
        \}
        restore address

        pop si
        .go:
        xor ax, ax
        mov ax, word[si]
        xor bx, bx
        mov bx, word[si+2]
        prtr bx, -n
        prtr ax, -n
        popa
}

test 500d ;1F4h 
line 
test *mydata 

pquit 
mydata dd 500d ;1F4H    

That's what you could do.

But your approach is from the beginning is veeery wrong. Firstly, you should start using functions/procedures instead of (or at least together with) macros. Otherwise your code will be bloated with replicated code parts. That's not what macros are intended for. Secondly, your code is full of meaningless and wrong things. Why do you push dword and pop a word (with pop si)? Why do you put the a value into memory at all, if you just need to put it into the ax and bx registers? Why do you sometimes use a single dot prefix and sometimes double dot (your differentiation of those is wrong)? And many more.


Beside that (*) additive, my codes now work as you suggested. I already discarded my faulty codes (using your approach) so I can't show you where I used it wrong.

Your macro skill is high my friend and now you are giving me homework to study those advance features Rolling Eyes

By the way, thank you for that beautiful piece of codes . Now I can use that for the integral type as well. Hope other newbies can learn from all these codes/routines. Owe you one Very Happy

Code:
macro test a
{ 
        pusha 
        local ..b, .go 
        xor si, si 

        define address + 
        define address - 
        match *val,a \{ 
            restore address 
            jmp @f 
                ..b dd val 
            @@: 
            push word [..b]
        \} 
        match -,address \{ 
            restore address 
            jmp @f 
                ..b dd a 
            @@: 
            push word ..b
        \} 
        restore address 

        pop si 
        .go: 
        mov ax, word[si]
        mov bx, word[si+2]
        prtr bx, -n 
        prtr ax, -n 
        popa 
} 
test *mydata
line
test 500d
pquit
mydata dd 500d    
Post 10 Aug 2013, 17:57
View user's profile Send private message Visit poster's website Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc
fasmnewbie
Speaking about homeworks... Don't learn on that. Better take this one:
Code:
macro put val*,[reg*]
{
    common local counter
        counter = 0
        define address +
        define address -
        match [x],val \{
            restore address
    forward
            mov reg,word[x+counter]
            counter = counter+2
    common
        \}
        match -,address \{
            restore address
    forward
            mov reg,(val shr (counter*8))and $FFFF
            counter = counter+2
    common
        \}
        restore address
}
put 500h,ax,bx
put [mydata],ax,bx

mydata dd 500d    

Firstly, this macro does not generate those suboptimal jumps over data and indirections via si.
Secondly, it's more generic and would allow you to put a value into any set of registers (like put $FEDCBA9876543210,ax,bx,cx,dx).
And thirdly, it uses brackets instead of an asterisk. Smile

Your test macro would then look like this:
Code:
macro test a 
{ 
    pusha
    put a,ax,bx
    prtr bx, -n
    prtr ax, -n
    popa
}
test 500d ;1F4h
line
test [mydata]

pquit
mydata dd 500d ;1F4H    

_________________
Faith is a superposition of knowledge and fallacy
Post 10 Aug 2013, 18:25
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2

< 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-2020, Tomasz Grysztar.

Powered by rwasa.