News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

32bit/64bit Macros

Started by ecube, August 18, 2010, 08:44:39 PM

Previous topic - Next topic

ecube

I posted this in another thread but its on like the 5th page so i'll post here

%MOV(%DESTN,%SOURCE) MACRO
#IFNDEF WIN64
mov D[%DESTN],%SOURCE
#ELSE
mov Q[%DESTN],%SOURCE
#ENDIF
ENDM

%CMP(%DESTN,%SOURCE) MACRO
#IFNDEF WIN64
cmp D[%DESTN],%SOURCE
#ELSE
cmp Q[%DESTN],%SOURCE
#ENDIF
ENDM

%ADD(%DESTN,%SOURCE) MACRO
#IFNDEF WIN64
ADD D[%DESTN],%SOURCE
#ELSE
ADD Q[%DESTN],%SOURCE
#ENDIF
ENDM

%SUB(%DESTN,%SOURCE) MACRO
#IFNDEF WIN64
SUB D[%DESTN],%SOURCE
#ELSE
SUB Q[%DESTN],%SOURCE
#ENDIF
ENDM

%INC(%DESTN) MACRO
#IFNDEF WIN64
INC D[%DESTN]
#ELSE
INC Q[%DESTN]
#ENDIF

%DEC(%DESTN) MACRO
#IFNDEF WIN64
DEC D[%DESTN]
#ELSE
DEC Q[%DESTN]
#ENDIF
ENDM



%MOV(myvar,53)
%CMP(myvar,54)
jne >


some simple macros you can use instead of add,cmp,mov,sub,inc,dec to work for both 32bit and 64bit. And donkey has the %INT_PTRĀ  in the the headers thats defined as dd/dq depending.

thanks donkey, updated here too, heh

donkey

Hi E^cube,

Useful macros. You can also use the S type indicator:

#IFDEF WIN64
#DEFINE S 8
#ELSE
#DEFINE S 4
#ENDIF


mov S[dest], 1234

Even so I have included your macros in the header macros.h file so that they can be used consistently across different projects and users.

Edgar
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

ecube

ahh nice donkey, forgot about that, well the only benefit my macros have is I guess it leaves S open for something else? I don't know what, but is there any restrictions on it that you know of?

donkey

Well, it is limited to 1,2,4,8 and 10 bytes as far as I know but no other restrictions (however DS is not available for the DATA SECTION (see below)). Jeremy has said that he will add one for pointers (P) but it has yet to be implemented at least as far as 0.56.8, not sure about any of the beta versions.

For some reason when you use DS in the data section the size is taken from the next label declared for example:

#DEFINE S 4

DATA SECTION
somelabel DS 0
someotherlabel DT 0


In the case above SIZEOF somelabel will result in 10, in the following example it results in 8

#DEFINE S 4

DATA SECTION
somelabel DS 0
someotherlabel DQ 0


in the following example it is completely off and results in 16

DATA SECTION
somelabel DS 0
someotherlabel DD 4 DUP (0)


In no case did changing the value assigned to S make any difference in the results. This appears to be because it no longer treats somelabel as a unique label, its address is the same as someotherlabel so you would assume that GoAsm sets the actual width of DS to be zero, creating in effect a union between the two.

Edgar
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

donkey

Just noticed in your macros, INC and DEC have 2 operands when there should only be 1, I've made the changes to the macros.h file.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable