hey guys,
i love programming. i have know C/C++ for a long while and went into ASM this past year. and you know what, learning ASM made me love programming even more. it helped put a lot of things into perspective.
anyway, i have gotten used to using MASM directives after doing a lot of programming and experimentation. a lot of MASM's directives made doing things so much easier. so im wondering if there are equivalents of some of these directives for C/C++ compilers.
some equivalents consist of the IF/ELSE/ENDIF directives, macros (to an extent), operators.
but there are some directives (which i find VERY useful) but cant imagine an equivalent for. (mostly preprocessor)
REPEAT
FOR/FORC
OPATTR
i was wondering if any of the more experienced programmers out there might know of some equivalents or at least the code to produce the same effect?
RTFM :bdg
There are some, you just have to swim through the help files :wink
Off the top of my head, there is:
.WHILE/.ENDW -- which repeat the endlosed code while the argument (while ____ ) is true
.REPEAT/.UNTIL -- which repeats the enclosed code until the argument (until ____) is true
I don't think there's a FOR, but you can get the same effect by using a variable as a counter, checking for the end-value at the end of the loop, and then jumping appropriately. Similarly with while and repeat.
I'm sure there's somerthing similar to OPATTR, but I can't think what right now.
Anyway, try searching through the masm help file, and also there is some stuff hidden on msdn :wink
well of course i know about the high level directives but that's not what im asking for. ;)
the idea that the assembler can duplicate lines of code while being able to use different parameters for each iteration without overhead sounds very attractive for me (even at the cost of potentially more lines of code in the end).
for example, in masm:
FOR name,<item1, object1, item2, item3, object2, ...>
; lots of stuff here
;
;
;
ENDM
would be easier than C/C++:
// lots of stuff for item1 here
//
//
//
// lots of stuff for object1 here
//
//
//
// lots of stuff for item2 here
//
//
//
// lots of stuff for item3 here
//
//
//
// lots of stuff for object2 here
//
//
//
//... and so on
or even:
.DATA
FOR name,<1,2,3,4,...>
Item&name SDWORD ?
ENDM
.CODE
vs
int Item1,Item2,Item3,Item4,...;
i also find the OPATTR very useful when using conditional assembly. i want to knw if its possible to do something similar for C/C++. and so far, i cannot find a way to simulate the same.
There are those too :wink
(Stolen directly from Masm32.hlp :bdg)
FOR parameter[:REQ|:=default], <argument [,argument]...>
statements
ENDM
FORC parameter, <string>
statements
ENDM
OPATTR expression
(see masm32.hlp for meaning of returned values)
There's also things like IF (not .IF) for conditional assembly..
Quote from: Jeff on May 31, 2005, 06:11:27 AM
the idea that the assembler can duplicate lines of code while being able to use different parameters for each iteration without overhead sounds very attractive for me (even at the cost of potentially more lines of code in the end).
Yes, MASM preprocessor is *much* more powerful than C's can ever be. :toothy
An enhanced preprocessor for high level languages would be really cool, but I don't know of any with so many features...