Obviously masm isnt a C compiler, obviously it can be used to write asm code perfectly fine.
But after going through icezilions tutorial... alot of "macros" and whatever else masm implements,
seem to make its syntax alot like C. Im not saying this is good or bad, but when i code in asm i like to code in asm. Things like LOCAL (define a local variable), .IF .BREAK .WHILE, invoke - seem to make masm source code look alot like C source code. so wuts the point? why not just use C?
Posted on 2003-12-10 15:07:07 by bnice2137
Who says you have to use the built-in macros? If you'ld rather:

PUSH A
PUSH B
PUSH C
PUSH D
PUSH E
PUSH F
CALL FUNC

go for it. Myself, I'ld rather:

INVOKE FUNC,F,E,D,C,B,A

:grin:
Posted on 2003-12-10 15:11:05 by S/390
Hi. :)

It's been discussed many times, but IMHO the key advantages are:

- Simple and readable code, like C
- Fast and compact executables, like ASM

It's different from C in the sense that this macros are just that, a "mechanical" replacement of opcodes that in no way replaces a full-blown high level language.

But of course, you'll find many different opinions on the subject. ;)

PS: I forgot, just like S/390 sais, you can choose if you're using the macros or not. That's not an option you have in C... :rolleyes:
Posted on 2003-12-10 15:11:11 by QvasiModo
yea i only dont like the high level stuff in the tutorials.
Posted on 2003-12-10 15:35:48 by bnice2137
Nah, you get used to it. Hey, I used to program in A86, that's even more "low level" than NASM... :grin:
Anyway I think the key at using HLL macros is to always know what the assembled output will be.
Posted on 2003-12-10 15:49:44 by QvasiModo
Generally I find it funny with assemblers like NASM that judge themselves superior by what they can't do :)

With local variables there is an advantage to push/call over invoke but besides that there is no opcode level difference. The IF/ELSE/ENDIF macro in MASM will choose the most efficient opcode arrangement for a comparison, something that you might not always do. MASM allows you to write code at a 1 to 1 ratio to opcodes or if you like to use the high level constructs. When writing example code or code others will see, I use the high levels but when I write for my own programs it looks more like this, mostly because I switch between MASM and GoAsm and this syntax is mostly compatible.

mov eax,uMsg

WMINITDIALOG:
cmp eax,WM_INITDIALOG
jnz WMCLOSE ; should trim 4 bytes here for a short
; Load the image and create the back-buffer
xor ecx,ecx
invoke LoadImage, [hInstance], IDR_BITMAP, ecx,\
ecx, ecx, LR_CREATEDIBSECTION
mov [hBkGrnd],eax
invoke GetDC,[hWin]
push eax
invoke CreateCompatibleDC,eax
mov [memdc],eax
pop eax
invoke ReleaseDC,[hWin],eax
invoke SelectObject,[memdc],[hBkGrnd]
mov [oldobj],eax
; Subclass the static control
push ebx
invoke GetDlgItem,[hWin],IDC_STATIC
mov ebx,eax
invoke GetWindowLong,ebx,GWL_WNDPROC
invoke SetWindowLong,ebx,GWL_USERDATA,eax
invoke SetWindowLong,ebx,GWL_WNDPROC,OFFSET StatProc
pop ebx
xor eax,eax
inc eax
ret

WMCLOSE:
cmp eax, WM_CLOSE
jnz short DEFPROC
Posted on 2003-12-10 15:52:58 by donkey

IF .BREAK .WHILE, invoke - seem to make masm source code look alot like C source code. so wuts the point? why not just use C?



Not why not use C but why use C? :grin: I think masm can do the hll features better than C compilers can do inline assembly :)


Generally I find it funny with assemblers like NASM that judge themselves superior by what they can't do


Me too :grin: I don't see the point. The assemblers with more features can do everything the assemblers with less features can and a whole lot more. Its up to the programmer to decide with feature s/he'll use. With assemblers with less features the assembler author decides what features you can use. Some assemblers like fasm have a powerful macro system that allows the language to be extended but others don't.
Posted on 2003-12-10 16:18:19 by Odyssey
fine. but for the purpose of a tutorial, why not teach in what is common to everyone. 80x86 assembly. not macros.
Posted on 2003-12-10 16:28:57 by bnice2137

fine. but for the purpose of a tutorial, why not teach in what is common to everyone. 80x86 assembly. not macros.


I think the tutorial is aimed at beginners to windows assembly programming so Iczelion wrote the tutorial in what he thought was the best way. The tutorials are very popular and most if not all of us learnt a lot from them so I don't see any reason to complain about the way the they were written.
Posted on 2003-12-10 16:33:59 by Odyssey

fine. but for the purpose of a tutorial, why not teach in what is common to everyone. 80x86 assembly. not macros.


That would be a good idea but what syntax would you use ? Different assemblers have widely varying syntax for example some require that a % is prefixed on constants, on most others that would generate an error. Some require that memory operands be enclosed in [] some don't. MASM is the defacto standard as greater than 90% of the assembly language users write in that assembler, there are tutorials that have been translated to other syntaxes but saying that the tutorials should be in a common language is like asking to write C tutorials so that they have a common base with Pascal. The high level contructs the examples use are generally limited to .IF/.ELSE/.ENDIF and INVOKE, these are available in at least 3 assemblers I know of maybe more.
Posted on 2003-12-10 16:35:54 by donkey
maybe im just complaining because i use nasm. and icezilion didnt write a nasm version lol. im not aiming this at the writer, those are great tutorials. im just putting it out there for discussion so i can see what people think about using all this high level type stuff in asm programs. Also, for alot of real beginner programers, the macros may make them have a flalse sense of security with asm programming. Dont take what im saying as a letter to the masm creaters intending to discontinue their macros.. nor is it a letter to Icezilion saying that i dont appreciate his tuts. :cool:
Posted on 2003-12-10 16:53:20 by bnice2137
I can't speak for Iczelion but one of the main goals has been to make assembler more available to a wider audience and less of a 1337 language that only a few virri writers used. As a programming platform, to be considered for general use it has to be robust and also have RAD tools like the high level constructs. Without those it is little more than a curiousity that people program in to have blazing graphics or to show off to their friends. The IF/ELSE/ENDIF and other high level constructs help by making a program both faster to write and generally easier to debug, the great thing is that if you find them slowing you down you can always elect to ignore them. As I had said above, I judge the power of an assembler by what it does, not what it can't do, sometimes low level can just be a pain in the a*s when you just want to churn out a quick routine. If you want a compromise between the two types, high level MASM and low level NASM you should look at GoAsm, it is my preference and it handles locals much better than most ;)

http://www.godevtool.com/

Right now you're lucky, you have not yet invested 1000's of hours learning one way. All roads are still open to you so pick the one that is most comfortable and not the one that everyone tells you is the right one because of this stupid reason or that. They are all good in their own way.
Posted on 2003-12-10 17:01:45 by donkey
well i have spent quite a while using nasm.. just not with windows. anyway, i think ill switch to masm due to the fact that its easy to get tutorials and such with it for win32 programming. and ill leave nasm behind with my linux and osdev days...uve made a believer out of me!!! MASM. but im still not using the high level constructs. thats what C is for!!! just kidding. :alright:
Posted on 2003-12-10 17:09:03 by bnice2137

maybe im just complaining because i use nasm. and icezilion didnt write a nasm version lol


Oh I think I might understand what you've been saying all this time. The tutorials use High level control structures which some assemblers like nasm doesn't have so beginners to assembly language using an assembler like nasm might have problems converting the tutorials to nasm syntax.
Posted on 2003-12-10 17:09:22 by Odyssey

well i have spent quite a while using nasm.. just not with windows. anyway, i think ill switch to masm due to the fact that its easy to get tutorials and such with it for win32 programming. and ill leave nasm behind with my linux and osdev days...uve made a believer out of me!!! MASM. but im still not using the high level constructs. thats what C is for!!! just kidding.


Not going to try to convince you to not use masm because with the masm32 package and RadAsm its the best tool for win32asm programming in my opinion but I think you should also have a look at fasm. It's popular among ex-nasm users :grin: and is under active development. It's fast and has a powerful macro system. You can check it out at
http://www.flatassembler.net/
Posted on 2003-12-10 17:16:16 by Odyssey
PUSH A
PUSH B
PUSH C
PUSH D
PUSH E
PUSH F
CALL FUNC

go for it. Myself, I'ld rather:

INVOKE FUNC,F,E,D,C,B,A



well that is not true ! masm does not always translate

INVOKE FUNC,F,E,D,C,B,A


us that ....


some times is very limitative to use it becouse makes in locals

lea eax, ; invoke place here this .....
PUSH eax ; if we use here the local
PUSH B
PUSH C
PUSH D
PUSH E
PUSH F
CALL FUNC
Posted on 2003-12-10 17:32:46 by Nguga
Hi Nuguga,

I had said :
With local variables there is an advantage to push/call over invoke but besides that there is no opcode level difference.

And as bad as that is you had used the same system until I pointed out the alternate way to do it. In general you will not notice the difference and MASM will warn you if you attempt to use eax in this case. But I do agree that it can be done better than the way masm handles it but you can always rewrite the invoke macro if you like.
Posted on 2003-12-10 17:47:56 by donkey
One reason I prefer MASM over C, which i dont think was mentioned (could be wrong), is the fact that MASM32 is not typed like C is. I personally hate having to learn how to write a program that conforms to a program, to make a program :rolleyes: . Pointers are the worst in this case! Im masm every handle/pointer can simply be proto typed as ":DWORD". End of story! No casting, no convincing the C compiler to do what i want... Its amazing sometimes how much casting goes on for something that can be done in MASM with only a couple lines of code!

Regards,
:NaN:
Posted on 2003-12-10 19:03:37 by NaN
If you do not like using the high level construct in masm, then do not use it. Simple as it.
Posted on 2003-12-10 20:47:19 by roticv
yikes, this is not the first time I heard someone say this about MASM. It's a good assembler makes coding a lot easier.

After using MASM I never want to go back to the time when I started ASM programming on the x86 in DOS using TASM 3.0 :( or the time when I did Z80 assembly earlier :S (Well Z80 ASM isn't as complicated as x86)
Posted on 2003-12-10 20:59:05 by x86asm