The MASM Forum

General => The Campus => Topic started by: Kalx on June 13, 2015, 08:27:53 AM

Title: Missing operator in expression
Post by: Kalx on June 13, 2015, 08:27:53 AM
Hi,
I was writing my n00b level code to output the address of the PEB,but an error "missing operator in expression" where there's MOV eax,[fs:0x30] keep popping up.
.386

.model flat,stdcall
option casemap:none

include \masm32\include\masm32rt.inc

.data


.code


start:

    XOR eax,eax
    MOV eax,[fs:0x30]
    print "eax = "
    print str$(eax),10,13
    inkey "pause"
    invoke ExitProcess,NULL
               
end start

Thanks to those who'll help :)
Title: Re: Missing operator in expression
Post by: habran on June 13, 2015, 08:59:37 AM
Try MOV eax,[fs:30h]  instead of MOV eax,[fs:0x30]
Title: Re: Missing operator in expression
Post by: Kalx on June 13, 2015, 09:03:04 AM
The error changed,now on the same line " error A2108: use of register assumed to ERROR"
Title: Re: Missing operator in expression
Post by: nidud on June 13, 2015, 09:12:17 AM
deleted
Title: Re: Missing operator in expression
Post by: Kalx on June 13, 2015, 09:38:56 AM
Well,now masm go fine but the exe doesn't output anything. I'm sure that this is another kind of problem.
Title: Re: Missing operator in expression
Post by: rrr314159 on June 13, 2015, 10:00:38 AM
Hi Kalx,

All I can figure is you are using only the 3 lines nidud gave; he didn't mean u should take out the other lines which do the printing! Here's everything needed:

include \masm32\include\masm32rt.inc
.code

start:

    assume fs:nothing
   
    MOV eax,fs:[30h]
    print "eax = "
    print str$(eax),10,13
    inkey "pause"
    invoke ExitProcess,NULL
               
end start
Title: Re: Missing operator in expression
Post by: dedndave on June 13, 2015, 10:08:42 AM
the contents of EAX are destroyed when you print "eax="   :P

        print   "eax = "

        ASSUME  FS:Nothing

        mov     eax,fs:[30h]

        ASSUME  FS:ERROR

        print   str$(eax),13,10
        inkey
        exit

Title: Re: Missing operator in expression
Post by: rrr314159 on June 13, 2015, 11:35:37 AM
woops, you're right ::)

I got an answer printed ("6") and ass-umed it was the right one
Title: Re: Missing operator in expression
Post by: dedndave on June 13, 2015, 08:37:41 PM
length of the string "eax = " = 6
the StdOut routine returns the length, and is used in the print macro
Title: Re: Missing operator in expression
Post by: nidud on June 13, 2015, 11:09:10 PM
deleted
Title: Re: Missing operator in expression
Post by: rrr314159 on June 14, 2015, 01:36:48 AM
True, but still doesn't explain why Kalx didn't see anything print out. Presumably I'm right, he removed all the print statements? Can't see any other explanation. Perhaps we'll never find out.

First thing I did (when I figured out what a macro was, and discovered macros.asm) was rewrite all the macros I use. My "prnt" macro preserves registers because there's absolutely no reason to return the count in eax; and no reason for speed since "print"ing takes so long. That's my excuse for forgetting this weird behavior.

Note that my "sprnt" macro does return the character count, like sprintf. Makes perfect sense when you're printing to a buffer. Admittedly it also made sense long ago when printf returned the character count, dealing with physical printers ... but no longer does today.

BTW I've posted all my macro-replacements for macros.asm here and there, latest versions work with both 32 and 64 bit, and have come up with dozens of new ones. I notice many of them jj2007 has done also, in MasmBasic, years ago ... I got a couple of the ideas from him, but mostly it's a case of convergent evolution

nidud: All these macros may be a bit confusing ...

the problem with them is very simple: they're non-standard. If everyone used the same there'd be no problem. ... no doubt it's time for a thorough upgrade to macros.asm, so newbies wouldn't feel the need to improve them
Title: Re: Missing operator in expression
Post by: Kalx on June 14, 2015, 01:45:40 AM
Ok,neither the code of nidud nor my code output something.
The code of nidud is in his own post,mine is this:

.386

.model flat,stdcall
option casemap:none

include \masm32\include\masm32rt.inc

.data


.code


start:

    ASSUME fs:NOTHING
    MOV eax, fs:[30h]
    ASSUME fs:ERROR
    print str$(eax),13,10
    inkey
    exit     

end start

If this two code work in every computer but mine,maybe the cause is the compile time option?
I use thse (I've a folder called workspace inside the masm32's folder and i call ml and link from there) :
..\bin\ml /c /coff proj1.asm
..\bin\link /SUBSYSTEM:WINDOWS /LIBPATH:..\lib proj1.obj
P.s:I'm very glad to see that this is an active community
Title: Re: Missing operator in expression
Post by: hutch-- on June 14, 2015, 02:14:57 AM
> the problem with them is very simple: they're non-standard. If everyone used the same there'd be no problem. ... no doubt it's time for a thorough upgrade to macros.asm, so newbies wouldn't feel the need to improve them

There IS a reason why a single file is used in MASM32, so it IS standard. Everyone is free to write their own but the supplied versions have worked correctly for a long time and they are documented properly.
Title: Re: Missing operator in expression
Post by: jj2007 on June 14, 2015, 02:30:34 AM
Quote from: rrr314159 on June 14, 2015, 01:36:48 AMthe problem with them is very simple: they're non-standard. If everyone used the same there'd be no problem. ... no doubt it's time for a thorough upgrade to macros.asm, so newbies wouldn't feel the need to improve them
There are a two or three macros that could be polished a little bit, but 99% work surprisingly well. And compared to any other assembler package I've seen, Masm32 is a very high standard.


Quote from: Kalx on June 14, 2015, 01:45:40 AM
..\bin\link /SUBSYSTEM:WINDOWS /LIBPATH:..\lib proj1.obj

To see console output, you need /SUBSYSTEM:CONSOLE
Title: Re: Missing operator in expression
Post by: rrr314159 on June 14, 2015, 04:26:38 AM
@Kalx, sure, subsystem:console

@hutch, you're right, why "fix something that ain't broke"?

Quote from: jj2007There are a two or three macros that could be polished a little bit, but 99% work surprisingly well.

- AFAIK they work fine (ignoring for now 64-bit), do exactly what they're supposed to do. One might want to "polish" them. For instance, as mentioned, I think print shld preserve registers, don't need the byte count. (In situations where you do, u'd print to buffer, using sprintf macro.) Also some macros seem redundant to me ... but this is all definitely a matter of opinion. Others will disagree. Up to hutch of course, but I agree attempting to "improve" macros.asm was not a good idea - fixing something that ain't broke.

- Instead people wind up augmenting them as they like, which causes the nonstandard situation. Just like Linux, it would be more "commercial" with only one version; but that's not really possible.

- MasmBasic includes an augmented set of macros which could be considered an enhanced macros.asm - the most successful I know of. (BTW notice that "deb" doesn't return byte count in eax! I assume) This is the best/only way to do it: produce your own candidate "better" macros package and hope everyone uses it (roughly speaking). But as with Linux, probably no "standard package" can get more than, say, 20 or 30% of users.

- Talking about standardizing I'd say it's more important to standardize on an assembler, like H/JWasm, which is the most popular around here (and my fave). But there are other worthy candidates, all with happy users, so that's not gonna happen any big hurry either. MASM is stuck with "too many versions", so, look on bright side: diversity, freedom of choice, Open Source Software, etc.

Quote from: jj2007And compared to any other assembler package I've seen, Masm32 is a very high standard.

- Sure, we're all very happy with it. VisualMASM? Randall Hyde HLA? ;) Note even HLA (and other, more useful, "environments") are built on Masm32 package. Fasm is great, but the "package" is minimal: dreams of being like Masm32 if and when it grows up. GoAsm, others can be mentioned, with happy users. Actually I don't know much about those, but I'm pretty sure no one even claims to exceed Masm32's high standard re completeness of package (samples, tutorials, qEditor etc), reliability, documentation, basic functionality. But they do have one advantage: under active development. So they can include new more modern features (like, 64-bit macro library I hope).

- Personally, I just write my own macros, borrowing anything from macros.asm or anywhere, and don't worry much about it. I only mentioned it as an excuse (superfluous of course) for forgetting that "print" trashes eax.
Title: Re: Missing operator in expression
Post by: jj2007 on June 14, 2015, 09:00:02 AM
Quote from: rrr314159 on June 14, 2015, 04:26:38 AMI think print shld preserve registers, don't need the byte count. ... "deb" doesn't return byte count in eax!
deb (http://www.webalice.it/jj2006/MasmBasicQuickReference.htm#Mb1019) is a special debugging macro: it doesn't alter flags or registers, but it does indeed insert a lot of extra code (about 500 bytes at least, but you can switch it off with usedeb=0). Whether an ordinary print should trash eax is arguable; where do you stop? print str$(eax) would require preserving eax (and edx, ecx) in print and in str$(). Same for hex$ and bin$, of course; and numerous other commands. In MasmBasic, I decided to preserve ecx everywhere, and I never regretted that - it is a very useful register. But eax and edx??

QuoteThis is the best/only way to do it: produce your own candidate "better" macros package and hope everyone uses it (roughly speaking). But as with Linux, probably no "standard package" can get more than, say, 20 or 30% of users.

I guess the Masm32 community is neatly split in three parts:
- too noob or too lazy to write own macros
- macro fans who write their own stuff (you, me, qWord, ...)
- macro haters who want to feel the bare metal.
And of course there is Hutch, who wrote most of the 400+ macros in macros.asm 8)

I have actually no idea how many people use MasmBasic, and I assume qWord also doesn't know how many use SmplMath. Download figures say nothing, it could even be robots. What is certain is that I do use my own macros quite a lot.

QuoteTalking about standardizing I'd say it's more important to standardize on an assembler, like H/JWasm, which is the most popular around here (and my fave). But there are other worthy candidates, all with happy users, so that's not gonna happen any big hurry either. MASM is stuck with "too many versions", so, look on bright side: diversity, freedom of choice, Open Source Software, etc.

I can't see a "too many versions" problem. Code that was written for ML 6.14 will work for ML 10.0 and for JWasm, including Habran's version. Sometimes JWasm is a bit tricky, but all my macros work with all versions of the MASM family. The same is probably true for all code in \Masm32\examples.

QuoteBut they do have one advantage: under active development

Hutch made a huge and radical change to Masm32 about three years ago: Unicode builds (http://www.masmforum.com/board/index.php?topic=17481.0). Since then, improvements have been more incremental, of course. Do I understand correctly that you volunteer to handle the switch to 64 bits?

(I won't, because there is that deep conviction in me that while the switch from 16 to 32 was a huge improvement, the switch to 64 is just a marketing thing with zero gain in terms of speed...)
Title: Re: Missing operator in expression
Post by: hutch-- on June 14, 2015, 11:23:26 AM
Back when the MASM32 project was first started, the existing situation was a never ending supply of incompatible prototypes, macros and code that no-one else could build along with the propaganda that assembler code was unwritable. I worked with a number of other people, Iczelion being probably the most consistent and creative, to put some reasonable order into the then emerging 32 bit assembler community. Iczelion was more up to date with 32 bit mnemonics than I was at the time, I wrote working 32 bit code but was still thinking in 16 bit mode but I had far more mileage in Windows API code than the other guys and deliberately bulldozed a modern architecture that could use a lot of the then current reference material.

As quick as possible the lack of a built in runtime library was addressed and a number of people contributed to the original MASM32 library and anything that looked useful was added to the macro file so that a person interested in trying to write assembler had something to start with instead of the cold turkey/high failure rate that plagued assembler programming before that. The general result allowed for a wider range of programming styles from low level mnemonic grinders to pseudo BASIC simplicity and this kept more people happy more often and produced a far higher number of competent assembler programmers than the nonsense that has been around for years before.

The idea was to produce a core system that worked but did not act as a straight jacket for new ideas. Wide ranging API prototypes, constants and structures that were reliable made this possible and also made people exchanging and sharing code viable. The idea of keeping the core architecture reliable and predictable meant that people who wrote something some years ago did not end up with broken code that would no longer build. Assembler as a discipline has never been about soft options, at its best it is a terse uncompromising endeavour that will jump up and bite you if you part your hair the wrong way yet if you learn the discipline, it allows you amazing architectural freedom and almost unlimited power and this is because essentially an assembler (MASM in this case) is an industrial tool for screwing mnemonics together, not a kiddie level (hold your hot little hand) pile of junk.

Most of the older fellas know how to write code like an assembler dump and being able to write this type of code if often virtuous for specific tasks but dumping a beginner with a pile of this stuff is a surefire way to scare them back to JAVA or DOT.WOT.
Title: Re: Missing operator in expression
Post by: rrr314159 on June 14, 2015, 11:24:59 AM
Quote from: rrr314159 on June 14, 2015, 04:26:38 AMI think print shld preserve registers, don't need the byte count. ... "deb" doesn't return byte count in eax!

Quote from: jj2007 on June 14, 2015, 09:00:02 AMdeb is a special debugging macro: it doesn't alter flags or registers, but it does indeed insert a lot of extra code (about 500 bytes at least, but you can switch it off with usedeb=0). Whether an ordinary print should trash eax is arguable; where do you stop? print str$(eax) would require preserving eax (and edx, ecx) in print and in str$().

- As I said, opinions differ, that's why would be fruitless to want to "improve" macros.asm. Rather, I'm glad we have flexible customizable platform lets everyone do as they wish. But, re. "drawing the line" I would say,

1) debug macros: preserve regs and flags, as u say
2) printing and anything involving human output/input: preserve all regs, except for useful return vals. My reasoning, if humans are involved (out to or in from) speed is completely negligible, and preserving only takes couple extra bytes
3) macros where speed (or bytes) important, preserve almost nothing. If I want to, on a particular use I can push/pop across it myself.

- In your example print str$(eax) ... I don't use str$, rather do it the C way with format string, like, 'prnt "eax = %i", eax'. But if doing it the Basic way wouldn't hesitate to preserve reg's twice: it's only printing! And if u examine the algos involved u'll probably find only one or two (eax, edx) need push / pop. OTOH using sprnt (print to a buffer) it's optimized more for speed, in such I don't preserve even ecx always. It's only for my own use, so I can remember the idiosyncracies of particular macros.

- Hey, u pays yer money u takes yer choice

Quote from: jj2007I guess the Masm32 community is neatly split in three parts:
- too noob or too lazy to write own macros
- macro fans who write their own stuff (you, me, qWord, ...)
- macro haters who want to feel the bare metal.

- from my perspective leaving out the most important category (which includes myself): "macro lovers who want to feel the bare metal". By writing my own, I still feel I'm riding right on the silicon. But that's what u are calling a "macro fan" .. matter of opinion how u look at it

Quote from: jj2007And of course there is Hutch, who wrote most of the 400+ macros in macros.asm

- I'd say he's another "macro fan" like u, me, and qWord. Although let me say I feel a bit out of my league, with u guys, who are still ahead of me in sheer output also knowledge. But I'm getting closer ... !

Quote from: jj2007I have actually no idea how many people use MasmBasic

- interesting to know, bet u could come up with decent guess if u put your mind to it

Quote from: rrrTalking about standardizing I'd say it's more important to standardize on an assembler like H/JWasm, ... But there are other worthy candidates ... MASM is stuck with "too many versions"

Quote from: jj2007I can't see a "too many versions" problem. Code that was written for ML 6.14 will work for ML 10.0 and for JWasm, including Habran's version.

- Hmmm, think I'm using the acronym "MASM" incorrectly. I meant to include Fasm, Yasm, GoAsm and other dialects of Intel assembler. With those, I'm sure u'll agree there are "too many versions"

Quote from: jj2007Do I understand correctly that you volunteer to handle the switch to 64 bits?

- I have come to a momentous decision (!) - forget about "switching" to 64 bit! For one thing 32 is hanging around for at least another decade. The advantage of 64 bit (xtra registers) is just not enough for most people (tho it is for me), plus there's the disadvantage of larger builds. And even for me I can't afford to become incompatible with all u 32-bitters, even tho I work mostly by myself. But the good news is it's extremely easy to write macros / code compatible with both, so that's what I do. I would volunteer to "handle the switch" to 32 / 64 bit "hybrid" u might call it ... depending on just what's involved! Hate to have to "guarantee" some macro works - what's the punishment if it screws up? And how do i know it works on your computer, or dedndave's, or the fellow behind the tree's? Put it this way, if anyone wants to see how I do 32 / 64 happy to explain it and post more macros than u can shake a stick at. And I'd like to learn about, and fix, problems that might arise with other computers / operator systems. Would require cooperation (testing) from community

Quote from: jj2007I won't, because there is that deep conviction in me that while the switch from 16 to 32 was a huge improvement, the switch to 64 is just a marketing thing with zero gain in terms of speed...

- As said I no longer recommend "Switching" (forget if I ever did, actually). But 32 / 64 is like "less filling and tastes great": u can have both!

@hutch: "Most of the older fellas ..."

- what other type of fellas are on this board? :biggrin:
Title: Re: Missing operator in expression
Post by: hutch-- on June 14, 2015, 11:42:35 AM
>  what other type of fellas are there on this board?

When you could read a CodeView debug as fast as your own code, you know you got it right.  :P
Title: Re: Missing operator in expression
Post by: rrr314159 on June 14, 2015, 11:45:55 AM
CodeView my butt ... in my heyday I read octal as fast as my own code; in fact that was my own code! That was later 1970's. I looked exactly as I do today but less distinguished
Title: Re: Missing operator in expression
Post by: hutch-- on June 14, 2015, 01:16:15 PM
Yes, I confess this was after punch cards.  :shock:
Title: Re: Missing operator in expression
Post by: rrr314159 on June 14, 2015, 01:31:45 PM
Hollerith was a great man, but I preferred paper tape - had plenty of uses, e.g. you could tie packages with it. I may have told u this story b4 ...?

Showed up at math class w/o a tie, was sent back to the dorm to get one (strict high school). So tied some paper tape printout around my neck (it actually encoded a printout of very primitive character-graphics Playboy centerfold) and went back to class. The professor went berserk - I got 3 demerits and the admiration of my fellow students. those were the days. I looked exactly like I do today, but less distinguished