flat assembler
Message board for the users of flat assembler.

Index > Main > Corresponding MASM operators in FASM

Author
Thread Post new topic Reply to topic
MazeGen



Joined: 06 Oct 2003
Posts: 977
Location: Czechoslovakia
MazeGen 17 Feb 2006, 13:47
Is there something like OPATTR and TYPE operators in FASM? I can't find anything similar in the documentation.

OPATTR (OPerand ATTRibute) returns a single word constant that indicates the type and scope of an expression.
TYPE return the type of an expression.

These operators are very useful in macros.

Here is a 16-bit example how them works (from masm guide):
Quote:

The following macro illustrates some techniques using OPATTR by loading an address into a specified offset register:
Code:
load    MACRO reg:REQ, adr:REQ
    IF (OPATTR (adr)) AND 00010000y    ;; Register
        IFDIFI reg, adr                ;; Don’t load register
            mov     reg, adr           ;;   onto itself
        ENDIF
    ELSEIF (OPATTR (adr)) AND 00000100y
        mov     reg, adr               ;; Constant
    ELSEIF (TYPE (adr) EQ BYTE) OR (TYPE (adr) EQ SBYTE)
        mov    reg, OFFSET adr         ;; Bytes
    ELSEIF (SIZE (TYPE (adr)) EQ 2
        mov    reg, adr                ;; Near pointer
    ELSEIF (SIZE (TYPE (adr)) EQ 4
        mov    reg, WORD PTR adr[0]    ;; Far pointer
        mov    ds,  WORD PTR adr[2]
    ELSE
        .ERR <Illegal argument>
    ENDIF
ENDM
    
Post 17 Feb 2006, 13:47
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 17 Feb 2006, 14:18
There's "eqtype" operator for a bit similar purposes, but there's no true correspondence between those two. It's one of the area where fasm takes substantially different approach.
Post 17 Feb 2006, 14:18
View user's profile Send private message Visit poster's website Reply with quote
MazeGen



Joined: 06 Oct 2003
Posts: 977
Location: Czechoslovakia
MazeGen 06 Mar 2006, 14:04
Really, eqtype seems to be something like opattr, also very powerful Smile. Thanks, I overlooked it at first.
Post 06 Mar 2006, 14:04
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 06 Mar 2006, 15:49
and again, "something eqtype something" seems more understandable than checking some bitfield...

Here's my partial translation
Code:
macro load reg*, adr* 
{
  if adr eqtype eax ;register
    ;.. not sure what this is, maybe this?
    if ~ reg eq adr   ;if "reg" isn't same as "adr"
      mov reg, adr
    end if
  else if adr eqtype 0 ;constant
    mov reg,adr
  ;not sure again, but if it is for string you can even declare string with
  ;usage of idata macro, like this:
  else if adr eqtype ""   ;note: checks only string constants, for string
    local ..string            ;like <"abcd",10,13,"efgh"> you need preprocessor solution
    idata \{ ..string db adr,0\}
    mov reg, ..string
  end if
  ;no idea how to distinguish near and far pointer. if size of offset 
  ;is known, you could check label's size with "virtual" block
}    

could you give examples for each "if" tests? I believe we can find a solution.
Post 06 Mar 2006, 15:49
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
MazeGen



Joined: 06 Oct 2003
Posts: 977
Location: Czechoslovakia
MazeGen 06 Mar 2006, 17:59
Thanks for this translation, we can compare everyone's features this way.

Quote:
Code:
IFDIFI reg, adr    
;.. not sure what this is, maybe this?

IFDIFI reg, adr means "if <reg> different from <adr>, case insensitive" - if you do something like load ax, ax, the macro doesn't assemble anything.

Quote:
Code:
ELSEIF (TYPE (adr) EQ BYTE) OR (TYPE (adr) EQ SBYTE)    

;not sure again, but if it is for string you can even declare string with
;usage of idata macro, like this:

Well, this condition means "else if object at <adr> is unsigned byte BYTE (in fasm, defined using DB) or signed byte SBYTE (don't know how it is in fasm)". Therefore, the object can be string or any BYTE or SBYTE variable:

Code:
.DATA
 some_str BYTE "blabla"
 some_var SBYTE -12

.CODE
 load ax, some_str ; the condition is true
 load bx, some_var ; the condition is true
    


Quote:
and again, "something eqtype something" seems more understandable than checking some bitfield...

Quote:
;no idea how to distinguish near and far pointer. if size of offset
;is known, you could check label's size with "virtual" block

Isn't this a disability of fasm? You have to always define the type somewhere. As for checking some bitfield, you can always code some resource macro, so it may look like "IF IsReg" or "IF IsImm"...
Post 06 Mar 2006, 17:59
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 06 Mar 2006, 18:24
fasm doesn't know about what you are going to use your variables for. That means that there is no difference between these:
Code:
db "abc",10,13,0
db 'a','b',c', 10, 13, 0
db 61h, 62h, 63h, 10, 13, 0    


and when you have something like "a dd ?", how can compiler know whether you are going to use it as pointer? By size?

It is matter of opinion, but i dislike such "guiding" me with my coding. It is job of compiler to define dword and my job to know how am i going to use it.

Tomasz & everyone: This is interesting "problem".. how to get size assigned to label? Is it possible?
Post 06 Mar 2006, 18:24
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
MazeGen



Joined: 06 Oct 2003
Posts: 977
Location: Czechoslovakia
MazeGen 06 Mar 2006, 19:07
vid wrote:
fasm doesn't know about what you are going to use your variables for. That means that there is no difference between these:
Code:
db "abc",10,13,0
db 'a','b',c', 10, 13, 0
db 61h, 62h, 63h, 10, 13, 0    


The same is in MASM, of course.

vid wrote:
and when you have something like "a dd ?", how can compiler know whether you are going to use it as pointer? By size?

You probably forget the context of that macro - it loads an address into a register(s). At the line ELSEIF (TYPE (adr) EQ BYTE... you already know the second argument in not a register nor a constant and therefore it can be only a (data) label.
If it is label used with BYTE or SBYTE (some_str BYTE "blabla"), you have to load the offset of that label (8-bit variable can't contain a pointer),
if it is WORD (ELSEIF (SIZE (TYPE (adr)) EQ 2), it is the pointer itself (we load 16-bit address), so in fasm syntax it assembles MOV reg, [adr],
if it is DWORD, it is FAR pointer, so it loads segment:offset pointer into DS:reg.

vid wrote:
It is matter of opinion, but i dislike such "guiding" me with my coding. It is job of compiler to define dword and my job to know how am i going to use it.

I thing you're wrong, this load macro is intended to be as general as possible, and it is just a silly example of all features of TYPE and OPATTR in one macro. It is also not bullet-proof, it should test if the label is in data section in case it is not BYTE or SBYTE label, and it also should report an error in case of SWORD and SDWORD types, which shouldn't contain a pointer.
Post 06 Mar 2006, 19:07
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 06 Mar 2006, 20:00
MazeGen wrote:
vid wrote:
fasm doesn't know about what you are going to use your variables for. That means that there is no difference between these:
Code:
db "abc",10,13,0
db 'a','b',c', 10, 13, 0
db 61h, 62h, 63h, 10, 13, 0    


The same is in MASM, of course.

i thought some of them are BYTEs and some SBYTEs... Compiler can't know if "_empty_string db 0" is numeric variable or string constant, can it?

vid wrote:
and when you have something like "a dd ?", how can compiler know whether you are going to use it as pointer? By size?

You probably forget the context of that macro - it loads an address into a register(s)...[/quote]
okay, so it's reduced to problem with getting size assigned to label if i am right
Post 06 Mar 2006, 20:00
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 06 Mar 2006, 20:02
vid wrote:
Tomasz & everyone: This is interesting "problem".. how to get size assigned to label? Is it possible?

In general, no. If you need to distinguish between BYTE/WORD/DWORD/QWORD label, you can do it with LOAD tricks like I did in the TEST optimization macro. This also shows that, though I noticed the problem, I didn't feel it really an excuse to add another special feature.
Post 06 Mar 2006, 20:02
View user's profile Send private message Visit poster's website Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend 06 Mar 2006, 21:24
Can't 'label dword ... at' or 'label byte ... at', etc used to define variable size labels at one memory place? Or maybe I misunderstood vid's question.
Post 06 Mar 2006, 21:24
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 06 Mar 2006, 21:30
Reverend: i was asking, how to find out what size is assigned to already defined label. like this:
Code:
macro a arg*
{
  if sizeoflabel(arg) eq byte
    movzx ax, [arg]
  else if sizeoflabel(arg) eq word
    mov ax, [arg]
  ... etc
}    
Post 06 Mar 2006, 21:30
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number 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.