Author Topic: .for, .endfor MACROS  (Read 19133 times)

jj2007

  • Member
  • *****
  • Posts: 7756
  • Assembler is fun ;-)
    • MasmBasic
Re: .for, .endfor MACROS
« Reply #30 on: June 12, 2012, 05:52:08 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

  • Member
  • *****
  • Posts: 1116
    • uasm
Re: .for, .endfor MACROS
« Reply #31 on: June 12, 2012, 07:35:50 PM »
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

  • Member
  • ****
  • Posts: 946
Re: .for, .endfor MACROS
« Reply #32 on: June 12, 2012, 11:58:52 PM »
Hi,

Quote
Mars is the only planet with a more than 24 hours day

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

Cheers,

Steve N.

dedndave

  • Member
  • *****
  • Posts: 8751
  • Still using Abacus 2.0
    • DednDave
Re: .for, .endfor MACROS
« Reply #33 on: June 13, 2012, 12:00:12 AM »
i think Maria Shriver is from Pluto   :redface:

jj2007

  • Member
  • *****
  • Posts: 7756
  • Assembler is fun ;-)
    • MasmBasic
Re: .for, .endfor MACROS
« Reply #34 on: June 13, 2012, 12:15:00 AM »
Quote
Mars 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

  • Member
  • ****
  • Posts: 946
Re: .for, .endfor MACROS
« Reply #35 on: June 13, 2012, 12:27:38 AM »
Hi jj,

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

Cheers,

Steve N.

habran

  • Member
  • *****
  • Posts: 1116
    • uasm
Re: .for, .endfor MACROS
« Reply #36 on: June 13, 2012, 01:10:30 AM »
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:
Code: [Select]
: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

  • Guest
Re: .for, .endfor MACROS
« Reply #37 on: July 17, 2012, 01:48:24 PM »
here is how i prefer to write it
Code: [Select]
        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

  • Member
  • *****
  • Posts: 8751
  • Still using Abacus 2.0
    • DednDave
Re: .for, .endfor MACROS
« Reply #38 on: July 17, 2012, 08:55:11 PM »
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

  • Guest
Re: .for, .endfor MACROS
« Reply #39 on: July 18, 2012, 01:59:40 AM »
Dave, any reason why you use inc and shr instead of cmp?

jj2007

  • Member
  • *****
  • Posts: 7756
  • Assembler is fun ;-)
    • MasmBasic
Re: .for, .endfor MACROS
« Reply #40 on: July 18, 2012, 02:02:16 AM »
Dave, any reason why you use inc and shr instead of cmp?

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

dedndave

  • Member
  • *****
  • Posts: 8751
  • Still using Abacus 2.0
    • DednDave
Re: .for, .endfor MACROS
« Reply #41 on: July 18, 2012, 02:14:27 AM »
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
Code: [Select]
        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

  • Guest
Re: .for, .endfor MACROS
« Reply #42 on: July 18, 2012, 02:34:46 AM »
Yeah, I guess
Code: [Select]
.break .if !eax would fail to exit if -1 is returned.

jj2007

  • Member
  • *****
  • Posts: 7756
  • Assembler is fun ;-)
    • MasmBasic
Re: .for, .endfor MACROS
« Reply #43 on: July 18, 2012, 03:10:51 AM »
Good guess :biggrin:

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

Ryan

  • Guest
Re: .for, .endfor MACROS
« Reply #44 on: July 18, 2012, 03:25:22 AM »
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.