News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Macro to test if arg is a direct value or memorry address/register ?

Started by gelatine1, October 22, 2015, 02:24:26 AM

Previous topic - Next topic

gelatine1

Hello, I don't know if this is possible but I would like to create a macro that can tell whether or not the argument is an immediate operand or not.

so for example


.data
value dd 5

.code
Tst MACRO arg:REQ
     .IF arg=immediate ... ;obviously should be something different that does work
         EXITM %1
    .ELSE
        EXITM %0
    .ENDIF
ENDM

start:
    mov eax,Tst(5) ;should put value of 1 in eax
    mov eax,Tst(value) ;should put value of 0 in eax
end start


Is this impossible to achieve ? or isn't it ?

Thanks in advance

GoneFishing

sure you can :
Quote
Tst MACRO arg:REQ
     IF OPATTR(arg) EQ 24h
         %echo arg is immediate operand
    ELSE
         %echo arg is  not immediate operand
    ENDIF
ENDM

jj2007

Excerpt from MasmBasic.inc (there were differences between Masm and JWasm, but not sure if they still exist):

;     OPATTR guide
;     Bit    Set If...
;     0      References a code label
;     1      Is a memory expression or has a relocatable data label
;     2      Is an immediate expression
;     3      Uses direct memory addressing, i.e. is an absolute memory reference
;     4      Is a register expression
;     5      References no undefined symbols and is without error
;     6      References a stack location (usually a LOCAL variable or parameter)
;     7      References an external label
;     8-10   Language type (0=no type)
                        ; 76543210      ; use and 127 to mask external label and language bits
atMemory      = 34      ;
00100010      ; [edx+20], [ebx+20], [eax+edx+20], JWasm: [eax+4*eax+20], [eax+20]
atImmediate   = 36      ;
00100100
atLabel       = 37      ;
10100101
atOffset      = 38      ;
10100110      ; offset CrLf$ (immediate and mem expression)
atGlobal      = 42      ;
10101010      ; CrLf$, Masm: [eax+4*eax+20], [eax+20]
atRegLabel    = 43      ;
10101011      ; Masm: [eax+start] (Jwasm yields 37)
atRegister    = 48      ;
00110000      ; also xmm
atXmm         = 77      ; xxxxxxxx      ; reg starting with x
atLocal       = 98      ; 01100010      ; [esp+20], [ebp+20]

gelatine1


gelatine1

Well.. I just figured out that OPATTR(1.0) is 0. Is this supposed to be happening or is that just because floating point constants are not supported ?

qWord

Quote from: gelatine1 on October 23, 2015, 05:45:22 AMIs this supposed to be happening or is that just because floating point constants are not supported ?
yes, FP constants are not supported.
Some days ago, there was a similar question: http://masm32.com/board/index.php?topic=4709.0
MREAL macros - when you need floating point arithmetic while assembling!

jj2007

Quote from: gelatine1 on October 23, 2015, 05:45:22 AM
Well.. I just figured out that OPATTR(1.0) is 0.

See qWord's answer. Don't rely on opattr(...) eq 0, sometimes the assembler throws an error instead, especially earlier ML versions.

gelatine1

Quote from: jj2007 on October 23, 2015, 06:45:30 AM
Quote from: gelatine1 on October 23, 2015, 05:45:22 AM
Well.. I just figured out that OPATTR(1.0) is 0.

See qWord's answer. Don't rely on opattr(...) eq 0, sometimes the assembler throws an error instead, especially earlier ML versions.

yep I had just tried that :p

Quote from: qWord on October 23, 2015, 06:15:38 AM
Quote from: gelatine1 on October 23, 2015, 05:45:22 AMIs this supposed to be happening or is that just because floating point constants are not supported ?
yes, FP constants are not supported.
Some days ago, there was a similar question: http://masm32.com/board/index.php?topic=4709.0

:icon_eek: :shock: Well...... Why didn't I see this topic before ???  :dazzled: Thanks alot anyway!! And I never actually realised that I could treat the 1.0 as a string too (or any other xxx.yyyyy number) :redface: