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

habran

Mea culpa, huch :icon_mrgreen:
I was in hurry and still my mind was in the .for macro
however, it looks much better when in brackets, you have to admit that
So, what is actually that you are concerned with in that example?
Cod-Father

habran

dedndave,
>i prefer to write code "old style"
I appreciate your opinion
however, sometimes readability of program is more important then speed
ml64 is out of game because of the "old style"

best regards
 
Cod-Father

jj2007

Quote from: habran on June 11, 2012, 09:10:47 PM
however, it looks much better when in brackets, you have to admit that

There is room for improvement then:
.if eax
nop
.endif


can become
.if (eax!=NULL);
;{
nop;
;}
.endif

;)

habran

 :eusa_clap: jj2007, I like your cinizam
I take it as a great sense of humor
that is a masterpiece jock,  I see it first time in my life
you should publish it somewhere

BTW
I used to write in BSIC while using commodore 64 but just to transfer machine code to assembler or opposite
I like C more than BASIC but my favorite is ASM, nothing can compensate for it
Cod-Father

qWord

For-loops are fine and I've also had the idea to create such a macro, but finial I end up that the resulting syntax doesn't look as nice as in C. Currently I can only see a change if it is directly implemented in the assembler:  jWasm.
For your macros, I see the problem of the used none-ASCII-characters (<<,>>), which are only visible, if the editor use the correct code page.
MREAL macros - when you need floating point arithmetic while assembling!

habran

qWord, in this case you can use LT, GT, EQ, LE, NE, GE

>directly implemented in the assembler:  jWasm.

I have worked on it and already build the skeleton of it
but I did not have enough time to study the code necessary to translate operators into code

now I am planing to look at it
Cod-Father

jj2007

Quote from: habran on June 11, 2012, 10:28:04 PM
I used to write in BASIC while using commodore 64 but just to transfer machine code to assembler or opposite
I like C more than BASIC but my favorite is ASM, nothing can compensate for it

I see we are on the same wavelength :biggrin:
My "coding career" was always a mix of Basic (i.e. Gfa on the Atari ST - almost a Pascal dialect) and assembler (68k, later x86). So I am probably just too old for C - and anyway, in Olly they look remarkably similar ;-)

Excuse my ignorance: What is the syntax for an extra simple loop as shown below?
include \masm32\MasmBasic\MasmBasic.inc   ; download
   Init
   PrintLine "MasmBasic For...Next loop:"
   mov eax, 5
   For_ ecx=0 To eax-1
      Print Str$("ecx=%i ", ecx)
   Next

   PrintLine CrLf$, "Now Habran's macro:"
   ; .FOR (
   Inkey "ok"
   Exit
end start

Output:
MasmBasic For...Next loop:
ecx=0 ecx=1 ecx=2 ecx=3 ecx=4
Now Habran's macro:
ok


P.S.: Any news from JWasm? 2.07 pre is fine for most purposes but there are minor quirks to fix...

habran

#22
jj2007
wavelength? you mean we remember things happened deep in the last millennium?
no mobile, no internet, no computer no nothing except having sex 28 hour a day!!! 8)

try this because I did not try it:
Init
   PrintLine "MasmBasic For...Next loop:"
   .for (eax=5,ecx=0:SDWORD PTR eax GE 0:eax--)
      Print Str$("ecx=%i ", ecx)
      PrintLine CrLf$, "Now Habran's macro:"
      ; .FOR (
      Inkey "ok"
   .endfor
   Exit
end start


best regards neighbor

P.S.: "0" (JWasm news)
Cod-Father

hutch--

There is nothing wrong with the analog world, it keeps running when the digital world's batteries go flat.  :biggrin:

dedndave

shouldn't ".endfor" be ".next"   :lol:

jj2007

Quote from: habran on June 12, 2012, 07:18:24 AM
wavelength? you mean we remember things happened deep in the last millennium?
no mobile, no internet, no computer no nothing except having sex 28 hour a day!!! 8)

Hutch, alarm!! We have a Martian on board - earthlings had only 24 hours available for this ;-)

Tried your code but no luck, it throws lots of error messages, see attachment...

include \masm32\MasmBasic\MasmBasic.inc   ; download
include FOR_M.inc   ; slightly modified
   Init

   PrintLine "MasmBasic For...Next loop:"
   mov eax, 5
   For_ ecx=0 To eax-1
      Print Str$("ecx=%i ", ecx)
   Next

   PrintLine CrLf$, "Now Habran's macro:"
   .for (eax=5:ecx=0:SDWORD PTR eax GE 0:eax--)
      nop
   .endfor   

   Inkey "ok"
   Exit
end start

habran

jj2007
sorry it was supposed to be with comma not with column

like this: .for (eax=5,ecx=0:SDWORD PTR eax GE 0:eax--)

and I am not from Mars, I am your neighbor fro former Yugoslavia
but I am already 20 years in South Australia
Cod-Father

habran

 :biggrin: Yeah hutch: analog sex 8)
Cod-Father

jj2007

Quote from: habran on June 12, 2012, 02:58:14 PM
jj2007
sorry it was supposed to be with comma not with column

like this: .for (eax=5,ecx=0:SDWORD PTR eax GE 0:eax--)

assembles fine now but doesn't do anything ::)
But I got it working in the end:

include \masm32\MasmBasic\MasmBasic.inc   ; download
include FOR_M.inc   ; slightly modified
   Init

   PrintLine "MasmBasic For...Next loop:"
   mov eax, 5
   For_ ecx=0 To eax-1
      Print Str$("ecx=%i ", ecx)
   Next

   PrintLine CrLf$, CrLf$, "Now Habran's macro: "
;   mov eax, 4
   .for (ecx=0 :SDWORD PTR ecx GE 4 : ecx++)
      Print Str$("ecx=%i ", ecx)
   .endfor   
   Inkey CrLf$, "ok"
   Exit
end start

Output:
MasmBasic For...Next loop:
ecx=0 ecx=1 ecx=2 ecx=3 ecx=4

Now Habran's macro:
ecx=0 ecx=1 ecx=2 ecx=3 ecx=4


Two minor issues:
   mov eax, 4
   .for (ecx=0 : SDWORD PTR ecx GE eax : ecx++)   ; reg32 instead of immediate: endless loop, eax gets trashed somewhere

   .for (ecx=0 : SDWORD PTR ecx GE 4 : ecx++)   ; blank before SDWORD: assembly hangs


Quoteand I am not from Mars, I am your neighbor fro former Yugoslavia
but I am already 20 years in South Australia

cosmically speaking, Mars is a close neighbour, too :biggrin:
by the way, if I remember well, even a century back that 24-hour activity was already digital ;)

habran

jj2007

I will look at it tonigh :eusa_clap:

are you sure that we are from the same century? :lol:
Cod-Father