flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Macro instruction parameter size

Author
Thread Post new topic Reply to topic
rydemstorm



Joined: 31 Oct 2012
Posts: 15
rydemstorm 07 Nov 2012, 22:09
I build this macro to determ the size of operand:
Code:
macro Size argi,argo
{
        virtual
                origin = $
                if argi eqtype word 0 | argi eqtype 0
                          push argi
                else
                          inc argi
                end if
                load opcode byte from origin
                if opcode = 66h                           ;66 3
                          argo=4
                else if (opcode or 7) = 47h               ;4X:0-7
                          argo=2
                else if opcode = 0FFh | opcode = 068h     ;ff | 68
                          argo=2
                else if opcode = 0FEh                     ;fe
                          argo=1
                else
                          err ;"not implemented 64bit or invalid argument"
                end if
        end virtual
}
macro TestSize [sou]
{
        forward
                Size sou,siz
                if sou eqtype 0 | sou eqtype word 0
                        if (siz = 1)
                                push 1
                        else if (siz = 2)
                                push 2
                        else if (siz = 4)
                                push 4
                        else
                                err ;"not implemented 64bit or invalid argument"
                        end if
                else
                        if (siz = 1)
                                add sou,1
                        else if (siz = 2)
                                add sou,2
                        else if (siz = 4)
                                add sou,4
                        else
                                err ;"not implemented 64bit or invalid argument"
                        end if
                end if
}
    

I call with this parameters:
TestSize al,cl,dl,bl,ah,ch,dh,bh,byte [b2],[b1];,byte 0xaa
TestSize ax,cx,dx,bx,sp,bp,si,di,word 0xbbcc,word [w2],[w1],0xbbcc
TestSize eax,ecx,edx,ebx,esp,ebp,esi,edi,dword [d2],[d1],dword 0xddeeff00
Work fine, except when I call with a byte constant "TestSize byte 0xaa" because try to push a byte in the stack, I try to filter this case to avoid the error but I can not found the way.
Could helpme anyone???
In the picture you can see the code generated, for every register o variable add operand,size, for every const push size
One idea is catch de exception and put a correct code to make the macro work fine, but I dont know it is possible
Try to filter if operand begin with "byte" and avoid the exception, but I can not resolve yet:
if (argi eqtype byte 0) not cathch, it is a bug this???


Description: Sample running
Filesize: 30.46 KB
Viewed: 1973 Time(s)

Size.png


Post 07 Nov 2012, 22:09
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.