I was googling the net to find something about the C macro offsetof and as usual MSDN is stingy to give some acceptable info and example
I was curious if someone ever translated it to ASM and I found nothing
so I decided to shad lights on it
In masm there is no need for that macro because it has it built in,
however I wrote one for those who were not clear what is it about
especially for C programmers who want to learn assembly language
;defined in stddef.h
;#define offsetof(s,m) (size_t)( (ptrdiff_t)&(((s *)0)->m) )
;s = struct
;m = member
;returns offset of a member in struct
;E.G.
; mov edx, offsetof(MYFRAME,EditWindow)
;it is a same as
; mov edx, MYFRAME.EditWindow
;struct MYFRAME
; rcFrame RECT <>
; FrameWindow HWND
; EditWindow HWND
; rcEdit RECT <>
;ends
offsetof MACRO s,m
sm EQU <>
sm CATSTR sm,<s>,<.>,<m>
EXITM<sm>
ENDM
offsetof MACRO s,m
EXITM <s.&m>
ENDM
:t
Cool 8)
You said more with less words :t
My intention was to show the steps what is actually happening :biggrin:
Habran,
Quote from: habran on June 30, 2014, 10:15:49 PM
Cool 8)
You said more with less words :t
My intention was to show the steps what is actually happening :biggrin:
You should know that qWord is a really macro magician. Some of his tricks border on witchcraft.
Gunther
qWord understands the syntax - a few other members do too, of course
that's the whole trick to macros
it's not clearly explained in the masm manual
maybe we can get qWord to write a macro tutorial :biggrin:
Quote from: dedndave on July 01, 2014, 02:12:44 AM
it's not clearly explained in the masm manual
maybe we can get qWord to write a macro tutorial :biggrin:
That's an excellent idea. It would help a lot of members.
Gunther
C'mon Gunther, witchcraft!? that reminds me on witch-hunt in medieval history :icon_eek:
It is not flattering ;)
Sorcery maybe or Shamanism or Magic :biggrin:
Hey qWord maybe you should change your avatar to this:
(http://upload.wikimedia.org/wikipedia/en/1/1f/MerlinDisney.gif)
what do you say dedndave 8)
include \masm32\include\masm32rt.inc
offsetof MACRO s,m
EXITM <s.&m>
ENDM
.code
start:
print str$(offsetof(RECT, top)), " = "
print str$(RECT.top)
exit
end start ;)
The trick with macros is to get around MASM's bugs :biggrin:
(http://www.un.org.kh/images/stories/demining%20undp.jpg)
maybe this can help :P
(http://upload.wikimedia.org/wikipedia/commons/thumb/8/87/FLIT_Spray_Can_1.jpg/440px-FLIT_Spray_Can_1.jpg)
qWord is a macro wizard
however, that icon is already in use by Tom Bleeker :P
http://www.madwizard.org/ (http://www.madwizard.org/)
Damn!
What about this one:
(http://upload.wikimedia.org/wikipedia/commons/thumb/b/b0/Nuremberg_chronicles_-_Merlin_%28CXXXVIIIr%29.jpg/440px-Nuremberg_chronicles_-_Merlin_%28CXXXVIIIr%29.jpg)
"Nothin' up my sleeve!"
(http://www.sellsbrothers.com/posts/Image/144)
dedndave you are a real wizard :bgrin:
hey jj2007 :t
I have a suggestion for hutch:
why not devote a topic for macros where people can contribute they own macros
> The trick with macros is to get around MASM's bugs
We generally call them undocumented features. :icon_mrgreen:
Quote from: hutch-- on July 01, 2014, 04:08:48 PM
> The trick with macros is to get around MASM's bugs
We generally call them undocumented features. :icon_mrgreen:
Hutch, these features are all documented now (http://www.japheth.de/JWasm/Manual.html#CHAPMASMBUGS).
:biggrin:
> Hutch, these features are all documented now.
Nah, this is just propaganda from the competition.
What makes me laugh is MASM was always a bad mannered old pig, that's part of its charm. Its task is to screw mnemonics together, not to hold the hand of the timid. You learn its "features" the hard way like normal and manipulate them to do the task you want. Now the ancient macro engine is an even bigger old pig with notation that was out of date in 1988 but interestingly enough if you massage it hard enough, you get results.
Quote from: hutch-- on July 01, 2014, 11:16:31 PMNow the ancient macro engine is an even bigger old pig with notation that was out of date in 1988 but interestingly enough if you massage it hard enough, you get results.
:P
Still one of my favorites:
foo macro
echo did you see me?
EXITM <0>
endm
% ; foo()
Undocumented feature "expand macro function and discard return value" :biggrin:
Quote from: qWord on July 01, 2014, 11:32:35 PM
% ; foo()
Undocumented feature "expand macro function and discard return value" :biggrin:
Similar (but quite useful):
include \masm32\include\masm32rt.inc
void MACRO args
@CatStr(<;>, <args>)
ENDM
.code
start:
void rv(MessageBox, 0, "Hello World", "It's all void:", MB_OK)
exit
end start