News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

.for, .endfor MACROS

Started by habran, June 11, 2012, 09:30:45 AM

Previous topic - Next topic

jj2007

Quote from: habran on June 12, 2012, 05:10:39 PM
are you sure that we are from the same century? :lol:

Pretty sure. I am uncertain about the location though - Mars is the only planet with a more than 24 hours day ::)

habran

OK, when I said 28 hours a day I meant more than I needed
that means that we exaggerated in a pleasure
And for your information, Mars is not inhabited!!! (Except Arnold Schwarzenegger :badgrin:)
Not any more, they died of boredom because they did not have internet
If you don't believe me ask other members on this board

best regards
Cod-Father

FORTRANS

Hi,

QuoteMars is the only planet with a more than 24 hours day

   Only if you ignore Mercury, Venus, and optionally Pluto.

Cheers,

Steve N.

dedndave

i think Maria Shriver is from Pluto   :redface:

jj2007

Quote from: FORTRANS on June 12, 2012, 11:58:52 PM
QuoteMars is the only planet with a more than 24 hours day

   Only if you ignore Mercury, Venus, and optionally Pluto.


Steve,
We only considered those which are appropriate for digital activity (hey, did anybody notice we are in the Lab here? we'll soon be banned :bgrin:)

FORTRANS

Hi jj,

   Well, okay.  I'll quiet up after mentioning that Messenger
is now in orbit around Mercury.

Cheers,

Steve N.

habran

thank you jj2007 for finding the bug in the macro :t
it was a proof that I am just a human (and not a Martian) :eusa_boohoo:
the bug was there because I was lazy to type so I copied and pasted the same routine but missed
to change 1 number
it was here:
:Lop3
  cspace TEXTEQU @SubStr(<params>,temp,1)
   IFIDN cspace,< >
   temp = temp+1
   space1 = space1+1
   goto Lop2               ;bug was here, it supposed to be goto Lop3
   ENDIF                           

I have fixed it an upload it in the beginning of this tread
and now it works like a charm :eusa_clap:

thanks again
Cod-Father

mywan

Quote from: dedndave on June 11, 2012, 11:31:41 AM
here is how i prefer to write it
        jmp short MLoop1

MLoop0: INVOKE  Translate Message,ebp
        INVOKE  DispatchMessage,ebp

MLoop1: INVOKE  GetMessage,ebp,edi,edi,edi
        inc     eax
        shr     eax,1
        jnz     MLoop0

it might not be pretty, but it is efficient

Not sure what's not pretty about it. One of the things that worried me when deciding to take on learning asm was loops and switches. To me the quoted snippet was the easiest to comprehend with the least effort of the 3 you provided. I have no issues at all with higher level syntax styles when it adds clarity, ease of use, or comprehensibility. Even paying some mild overhead cost for it is not out of the question in most circumstances. I'm just not personally seeing any of that in the examples given.

I hope if you contribute to my questions in the future you can offer your "old style" perspective as well. It's valuable even when alternative approaches are chosen in a given instance.

dedndave

i feel better, now

some of the guys in here can't read code unless it is surrounded by ".IF/.ENDIF"   :lol:
i hate that stuff, but i want to use it so that the newbies are accustomed to it

Ryan

Dave, any reason why you use inc and shr instead of cmp?

jj2007

Quote from: Ryan on July 18, 2012, 01:59:40 AM
Dave, any reason why you use inc and shr instead of cmp?

Loop exits for msg=0 and msg=-1 ;-)

dedndave

to expand on what Jochen said...

by using INC and SHR, we get to use only 1 branch instruction

INC reg32 is a single-byte instruction
SHR reg32,1 is a two-byte instruction
JNZ by a reverse distance of 128 bytes or less is 2 bytes
        inc     eax
        shr     eax,1
        jnz     MLoop0

5 bytes total

we want to exit the program if the returned value is either 0 or -1
for all other values, we want to loop

Ryan

Yeah, I guess .break .if !eax would fail to exit if -1 is returned.

jj2007

Good guess :biggrin:

Dave's code is one cycle faster and 4 bytes shorter.

Ryan

The irony is the template that Microsoft uses for new C++ programs doesn't account for -1.  I wish they would elaborate on what exactly would cause it to fail.  They mention as examples an invalid hWnd or an invalid message pointer.  Passing hWnd would overlook WM_QUIT, so that's definitely not recommended in a primary message loop.  If someone passes an invalid message pointer, it would certainly be caught on the first run.